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 | |
Serial Char | |
Serial Double | |
Serial Float | |
Serial Int | |
Serial Int8 | |
Serial Int16 | |
Serial Int32 | |
Serial Int64 | |
Serial Integer |
|
Serial Ordering |
|
Serial Word | |
Serial Word8 | |
Serial Word16 | |
Serial Word32 | |
Serial Word64 | |
Serial () | |
Serial Version | |
Serial All | |
Serial Any | |
Serial ByteString | |
Serial ByteString | |
Serial IntSet | |
Serial Text | |
Serial Text | |
Serial AbsoluteTime |
|
Serial LocalTime | |
Serial ZonedTime | |
Serial TimeOfDay | |
Serial TimeZone | |
Serial UTCTime |
|
Serial NominalDiffTime |
|
Serial Day |
|
Serial UniversalTime |
|
Serial DiffTime |
|
Serial Void | |
Serial a => Serial [a] | |
(Serial a, Integral a) => Serial (Ratio a) |
|
HasResolution a => Serial (Fixed a) |
|
Serial a => Serial (ZipList a) | |
Serial a => Serial (Dual a) | |
Serial a => Serial (Sum a) | |
Serial a => Serial (Product a) | |
Serial a => Serial (First a) | |
Serial a => Serial (Last a) | |
Serial a => Serial (Down a) | |
Serial a => Serial (Maybe a) | |
Serial v => Serial (IntMap v) | |
(Serial a, Ord a) => Serial (Set a) | |
Serial a => Serial (Seq a) | |
Serial a => Serial (Identity a) | |
(Bits n, Integral n, Bits (Unsigned n), Integral (Unsigned n)) => Serial (VarInt n) | $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) | |
(Serial a, Serial b) => Serial (a, b) | |
(Serial k, Serial v, Ord k) => Serial (Map k v) | |
Serial (f a) => Serial (Reverse f a) | |
Serial a => Serial (Constant a b) | |
(Serial a, Serial b, Serial c) => Serial (a, b, c) | |
(Serial (f a), Serial (g a)) => Serial (Product f g a) | |
(Serial a, Serial b, Serial c, Serial d) => Serial (a, b, c, d) | |
(Serial a, Serial b, Serial c, Serial d, Serial e) => Serial (a, b, c, d, e) |
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 [] | |
Serial1 Maybe | |
Serial1 IntMap | |
Serial1 Seq | |
Serial a => Serial1 (Either a) | |
Serial a => Serial1 ((,) a) | |
(Ord k, Serial k) => Serial1 (Map k) | |
(Serial a, Serial b) => Serial1 ((,,) a b) | |
(Serial a, Serial b, Serial c) => Serial1 ((,,,) a b c) | |
(Serial a, Serial b, Serial c, Serial d) => Serial1 ((,,,,) a b c d) |
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) |
Used internally to provide generic serialization
gserializeWith :: MonadPut m => (a -> m ()) -> f a -> m () Source
gdeserializeWith :: MonadGet m => m a -> m (f a) Source