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
- class SerialEndian a where
- class Serial1 f where
- serialize1 :: (MonadPut m, Serial1 f, Serial a) => f a -> m ()
- deserialize1 :: (MonadGet m, Serial1 f, Serial a) => m (f a)
- class Serial2 f where
- 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
- class GSerialEndian f where
- class GSerial1 f where
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.
serialize :: MonadPut m => a -> m () Source #
serialize :: (MonadPut m, GSerial (Rep a), Generic a) => a -> m () Source #
deserialize :: MonadGet m => m a Source #
deserialize :: (MonadGet m, GSerial (Rep a), Generic a) => m a Source #
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 Natural Source # |
|
Serial Void 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 => Serial (Maybe 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 v => Serial (IntMap v) Source # | |
Serial a => Serial (Seq a) Source # | |
(Serial a, Ord a) => Serial (Set 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 # | 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 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 (Reverse * f a) Source # | |
Serial a => Serial (Constant * a b) Source # | |
(Serial a, Serial b, Serial c, Serial d) => Serial (a, b, c, d) Source # | |
(Serial (f a), Serial (g a)) => Serial (Product * f g a) 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.
serializeBE :: MonadPut m => a -> m () Source #
serializeBE :: (MonadPut m, GSerialEndian (Rep a), Generic a) => a -> m () Source #
deserializeBE :: MonadGet m => m a Source #
deserializeBE :: (MonadGet m, GSerialEndian (Rep a), Generic a) => m a Source #
serializeLE :: MonadPut m => a -> m () Source #
serializeLE :: (MonadPut m, GSerialEndian (Rep a), Generic a) => a -> m () Source #
deserializeLE :: MonadGet m => m a Source #
deserializeLE :: (MonadGet m, GSerialEndian (Rep a), Generic a) => 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.
class Serial1 f where Source #
serializeWith :: MonadPut m => (a -> m ()) -> f a -> m () Source #
serializeWith :: (MonadPut m, GSerial1 (Rep1 f), Generic1 f) => (a -> m ()) -> f a -> m () Source #
deserializeWith :: MonadGet m => m a -> m (f a) Source #
deserializeWith :: (MonadGet m, GSerial1 (Rep1 f), Generic1 f) => 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 # | |
class Serial2 f where 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
class GSerial f where Source #
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
gserializeBE :: MonadPut m => f a -> m () Source #
gserializeBE :: (MonadPut m, GSerial f) => f a -> m () Source #
gdeserializeBE :: MonadGet m => m (f a) Source #
gdeserializeBE :: (MonadGet m, GSerial f) => m (f a) Source #
gserializeLE :: MonadPut m => f a -> m () Source #
gserializeLE :: (MonadPut m, GSerial f) => f a -> m () Source #
gdeserializeLE :: MonadGet m => m (f a) Source #
gdeserializeLE :: (MonadGet m, GSerial f) => m (f a) Source #
SerialEndian a => GSerialEndian (K1 i a) Source # | |
class GSerial1 f where 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 # | |