Copyright | (c) Edward Kmett 2013-2015 |
---|---|
License | BSD3 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell98 |
This module contains two main classes, each providing methods to
serialize and deserialize types. Serial
is the primary class,
to be used for the canonical way to serialize a specific
type. SerialEndian
is used to provide endian-specific methods
for serializing a type.
- class Serial a where
- serialize :: MonadPut m => a -> m ()
- deserialize :: MonadGet m => m a
- class SerialEndian a where
- serializeBE :: MonadPut m => a -> m ()
- deserializeBE :: MonadGet m => m a
- serializeLE :: MonadPut m => a -> m ()
- deserializeLE :: MonadGet m => m a
- serializeHost :: MonadPut m => a -> m ()
- deserializeHost :: MonadGet m => m a
- class Serial1 f where
- serializeWith :: MonadPut m => (a -> m ()) -> f a -> m ()
- deserializeWith :: MonadGet m => m a -> m (f a)
- serialize1 :: (MonadPut m, Serial1 f, Serial a) => f a -> m ()
- deserialize1 :: (MonadGet m, Serial1 f, Serial a) => m (f a)
- class Serial2 f where
- serializeWith2 :: MonadPut m => (a -> m ()) -> (b -> m ()) -> f a b -> m ()
- deserializeWith2 :: MonadGet m => m a -> m b -> m (f a b)
- serialize2 :: (MonadPut m, Serial2 f, Serial a, Serial b) => f a b -> m ()
- deserialize2 :: (MonadGet m, Serial2 f, Serial a, Serial b) => m (f a b)
- store :: (MonadPut m, Storable a) => a -> m ()
- restore :: forall m a. (MonadGet m, Storable a) => m a
- class GSerial f where
- gserialize :: MonadPut m => f a -> m ()
- gdeserialize :: MonadGet m => m (f a)
- class GSerialEndian f where
- gserializeBE :: MonadPut m => f a -> m ()
- gdeserializeBE :: MonadGet m => m (f a)
- gserializeLE :: MonadPut m => f a -> m ()
- gdeserializeLE :: MonadGet m => m (f a)
- class GSerial1 f where
- gserializeWith :: MonadPut m => (a -> m ()) -> f a -> m ()
- gdeserializeWith :: MonadGet m => m a -> m (f a)
Serialization
Methods to serialize and deserialize type a
to a binary representation
Instances provided here for fixed-with Integers and Words are big endian. Instances for strict and lazy bytestrings store also the length of bytestring big endian. Instances for Word and Int are host endian as they are machine-specific types.
Nothing
Serial Bool Source | |
Serial Char Source | |
Serial Double Source | |
Serial Float Source | |
Serial Int Source | |
Serial Int8 Source | |
Serial Int16 Source | |
Serial Int32 Source | |
Serial Int64 Source | |
Serial Integer Source |
|
Serial Ordering Source |
|
Serial Word Source | |
Serial Word8 Source | |
Serial Word16 Source | |
Serial Word32 Source | |
Serial Word64 Source | |
Serial () Source | |
Serial Void Source | |
Serial Natural Source |
|
Serial Version Source | |
Serial All Source | |
Serial Any Source | |
Serial ByteString Source | |
Serial ByteString Source | |
Serial IntSet Source | |
Serial Scientific Source | |
Serial Text Source | |
Serial Text Source | |
Serial AbsoluteTime Source |
|
Serial LocalTime Source | |
Serial ZonedTime Source | |
Serial TimeOfDay Source | |
Serial TimeZone Source | |
Serial UTCTime Source |
|
Serial NominalDiffTime Source |
|
Serial Day Source |
|
Serial UniversalTime Source |
|
Serial DiffTime Source |
|
Serial a => Serial [a] Source | |
(Serial a, Integral a) => Serial (Ratio a) Source |
|
Serial a => Serial (Identity a) Source | |
HasResolution a => Serial (Fixed a) Source |
|
Serial a => Serial (ZipList a) Source | |
Serial a => Serial (Dual a) Source | |
Serial a => Serial (Sum a) Source | |
Serial a => Serial (Product a) Source | |
Serial a => Serial (First a) Source | |
Serial a => Serial (Last a) Source | |
Serial a => Serial (Down a) Source | |
Serial a => Serial (Maybe a) Source | |
Serial v => Serial (IntMap v) Source | |
(Serial a, Ord a) => Serial (Set a) Source | |
Serial a => Serial (Seq a) Source | |
(Serial v, Hashable v, Eq v) => Serial (HashSet v) Source | |
(Bits n, Integral n, Bits (Unsigned n), Integral (Unsigned n)) => Serial (VarInt n) Source | $setup >>> import Data.Word >>> import Data.Fixed >>> import Data.Bytes.Serial Integer/Word types serialized to base-128 variable-width ints.
|
(Serial a, Serial b) => Serial (Either a b) Source | |
(Serial a, Serial b) => Serial (a, b) Source | |
(Serial k, Serial v, Ord k) => Serial (Map k v) Source | |
Serial (f a) => Serial (Reverse f a) Source | |
Serial a => Serial (Constant a b) Source | |
(Serial k, Serial v, Hashable k, Eq k) => Serial (HashMap k v) Source | |
(Serial a, Serial b, Serial c) => Serial (a, b, c) Source | |
(Serial (f a), Serial (g a)) => Serial (Product f g a) Source | |
(Serial a, Serial b, Serial c, Serial d) => Serial (a, b, c, d) Source | |
(Serial a, Serial b, Serial c, Serial d, Serial e) => Serial (a, b, c, d, e) Source |
Specifying endianness
class SerialEndian a where Source
Methods to serialize and deserialize type a
to a big and little endian
binary representations. Methods suffixed with "host" are automatically defined
to use equal the methods corresponding to the current machine's native
endianness, but they can be overridden.
Nothing
serializeBE :: MonadPut m => a -> m () Source
deserializeBE :: MonadGet m => m a Source
serializeLE :: MonadPut m => a -> m () Source
deserializeLE :: MonadGet m => m a Source
serializeHost :: MonadPut m => a -> m () Source
deserializeHost :: MonadGet m => m a Source
Higher-order
These classes provide us with the ability to serialize containers that need polymorphic recursion.
Nothing
serializeWith :: MonadPut m => (a -> m ()) -> f a -> m () Source
deserializeWith :: MonadGet m => m a -> m (f a) Source
Serial1 [] Source | |
Serial1 Maybe Source | |
Serial1 IntMap Source | |
Serial1 Seq Source | |
Serial a => Serial1 (Either a) Source | |
Serial a => Serial1 ((,) a) Source | |
(Ord k, Serial k) => Serial1 (Map k) Source | |
(Hashable k, Eq k, Serial k) => Serial1 (HashMap k) Source | |
(Serial a, Serial b) => Serial1 ((,,) a b) Source | |
(Serial a, Serial b, Serial c) => Serial1 ((,,,) a b c) Source | |
(Serial a, Serial b, Serial c, Serial d) => Serial1 ((,,,,) a b c d) Source |
serialize1 :: (MonadPut m, Serial1 f, Serial a) => f a -> m () Source
deserialize1 :: (MonadGet m, Serial1 f, Serial a) => m (f a) Source
serializeWith2 :: MonadPut m => (a -> m ()) -> (b -> m ()) -> f a b -> m () Source
deserializeWith2 :: MonadGet m => m a -> m b -> m (f a b) Source
Storable
store :: (MonadPut m, Storable a) => a -> m () Source
serialize any Storable
in a host-specific format.
restore :: forall m a. (MonadGet m, Storable a) => m a Source
deserialize any Storable
in a host-specific format.
Generics
You probably will never need to care that these exist except they
provide us with default definitions for Serial
and SerialEndian
Used internally to provide generic serialization
gserialize :: MonadPut m => f a -> m () Source
gdeserialize :: MonadGet m => m (f a) Source
class GSerialEndian f where Source
Used internally to provide generic big-endian serialization
Nothing
gserializeBE :: MonadPut m => f a -> m () Source
gdeserializeBE :: MonadGet m => m (f a) Source
gserializeLE :: MonadPut m => f a -> m () Source
gdeserializeLE :: MonadGet m => m (f a) Source
SerialEndian a => GSerialEndian (K1 i a) Source |
Used internally to provide generic serialization
gserializeWith :: MonadPut m => (a -> m ()) -> f a -> m () Source
gdeserializeWith :: MonadGet m => m a -> m (f a) Source
GSerial1 V1 Source | |
GSerial1 U1 Source | |
GSerial1 Par1 Source | |
Serial1 f => GSerial1 (Rec1 f) Source | |
Serial a => GSerial1 (K1 i a) Source | |
(GSerial1 f, GSerial1 g) => GSerial1 ((:+:) f g) Source | |
(GSerial1 f, GSerial1 g) => GSerial1 ((:*:) f g) Source | |
(Serial1 f, GSerial1 g) => GSerial1 ((:.:) f g) Source | |
GSerial1 f => GSerial1 (M1 i c f) Source |