2-- Module : Streamly.Data.MutByteArray
3-- Copyright : (c) 2023 Composewell Technologies
4-- License : BSD3-3-Clause
5-- Maintainer : streamly@composewell.com
8-- A low level byte Array type 'MutByteArray', along with type classes 'Unbox'
9-- and 'Serialize' for fast binary serialization and deserialization of Haskell
10-- values. Serialization, deserialization performance is similar to, and in
11-- some cases many times better than the store package. Conceptually, the
12-- 'Serialize' type class works in the same way as store.
14-- Serialize instances are configurable to use constructor names (see
15-- 'Streamly.Internal.Data.MutByteArray.encodeConstrNames'), record field names (see
16-- 'Streamly.Internal.Data.MutByteArray.encodeRecordFields') instead of binary
17-- encoded values. This is an experimental feature which allows JSON like
18-- properties with faster speed. For example, you can change the order of
19-- constructors or record fields without affecting serialized value.
21-- Higher level unboxed array modules "Streamly.Data.Array" and
22-- "Streamly.Data.MutArray" are built on top of this module. Unboxed arrays are
23-- essentially serialized Haskell values. Array modules provide higher level
24-- serialization routines like 'Streamly.Internal.Data.Array.pinnedSerialize'
25-- and 'Streamly.Internal.Data.Array.deserialize' from the
26-- "Streamly.Internal.Data.Array" module.
28-- == Mutable Byte Array
30-- 'MutByteArray' is a primitive mutable array in the IO monad. 'Unbox' and
31-- 'Serialize' type classes use this primitive array to serialize data to and
32-- deserialize it from. This array is used to build higher level unboxed
33-- array types 'Streamly.Data.MutArray.MutArray' and 'Streamly.Data.Array.Array'.
37-- The 'Unbox' type class is simple and used to serialize non-recursive fixed
38-- size data types. This type class is primarily used to implement unboxed
39-- arrays. Unboxed arrays are just a sequence of serialized fixed length
40-- Haskell data types. Instances of this type class can be derived using
41-- 'Generic' or template haskell based deriving functions provided in this
44-- Writing a data type to an array using the array creation routines in
45-- "Streamly.Data.Array" or "Streamly.Data.MutArray" (e.g. @writeN@ or
46-- @fromListN@), serializes the type to the array. Similarly, reading the data
47-- type from the array deserializes it. You can also serialize and deserialize
48-- directly to and from a 'MutByteArray', using the type class methods.
52-- The 'Serialize' type class is a superset of the 'Unbox' type class, it can
53-- serialize variable length data types as well e.g. Haskell lists. Use
54-- 'deriveSerialize' to derive the instances of the type class automatically
55-- and then use the type class methods to serialize and deserialize to and from
58-- See 'Streamly.Internal.Data.Array.pinnedSerialize' and
59-- 'Streamly.Internal.Data.Array.deserialize' for 'Array' type based
62-- == Comparing serialized values
64-- When using the `Unbox` type class the same value may result in differing
65-- serialized bytes because of unused uninitialized data in case of sum types.
66-- Therefore, byte comparison of serialized values is not reliable.
68-- However, the 'Serialize' type class guarantees that the serialized values
69-- are always exactly the same and byte comparison of serialized is reliable.
71module Streamly.Data.MutByteArray
74 -- * Mutable Byte Array
75 -- | The standard way to read from or write to a 'MutByteArray' is by using
76 -- the 'Unbox' or 'Serialize' type class methods.
97 -- ** Instance Deriving
102--------------------------------------------------------------------------------
104--------------------------------------------------------------------------------
106import Streamly.Internal.Data.MutByteArray
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list