The 'store' package provides efficient binary serialization. There are a couple features that particularly distinguish it from most prior Haskell serialization libraries:
Its primary goal is speed. By default, direct machine representations are used for things like numeric values (
Word32, etc) and buffers (
Vector, etc). This means that much of serialization uses the equivalent of
- Another way that the serialization behavior can vary is if
integer-simple is used instead of GHC's default of using
Integerserialized with the
integer-simpleflag enabled are not compatible with those serialized without the flag enabled.
- Another way that the serialization behavior can vary is if integer-simple is used instead of GHC's default of using GMP.
Instead of implementing lazy serialization / deserialization involving multiple input / output buffers,
pokealways work with a single buffer. This buffer is allocated by asking the value for its size before encoding. This simplifies the encoding logic, and allows for highly optimized tight loops.
storecan optimize size computations by knowing when some types always use the same number of bytes. This allows us to compute the byte size of a
Vector Int32by just doing
length v * 4.
It also features:
Optimized serialization instances for many types from base, vector, bytestring, text, containers, time, template-haskell, and more.
TH and GHC Generics based generation of Store instances for datatypes.
TH generation of testcases.
Utilities for streaming encoding / decoding of Store encoded messages, via the
Store is best used for communication between trusted processes and local caches. It can certainly be used for other purposes, but the builtin set of instances have some gotchas to be aware of:
Store's builtin instances serialize in a format which depends on machine endianness.
Store's builtin instances trust the data when deserializing. For example, the deserialization of
Vectorwill read the vector's length from the first 8 bytes. It will then allocate enough memory to store all the elements. Malicious or malformed input could cause allocation of large amounts of memory. See issue #122.