Copyright | (c) Edward Kmett 2013-2015 |
---|---|
License | BSD3 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
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.
Synopsis
- 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
Instances
Serial All Source # | |
Serial Any Source # | |
Serial Version Source # | |
Serial Void Source # | |
Serial Int16 Source # | |
Serial Int32 Source # | |
Serial Int64 Source # | |
Serial Int8 Source # | |
Serial Word16 Source # | |
Serial Word32 Source # | |
Serial Word64 Source # | |
Serial Word8 Source # | |
Serial ByteString Source # | |
Defined in Data.Bytes.Serial serialize :: MonadPut m => ByteString -> m () Source # deserialize :: MonadGet m => m ByteString Source # | |
Serial ByteString Source # | |
Defined in Data.Bytes.Serial serialize :: MonadPut m => ByteString -> m () Source # deserialize :: MonadGet m => m ByteString Source # | |
Serial IntSet Source # | |
Serial Ordering Source # |
|
Serial Scientific Source # | |
Defined in Data.Bytes.Serial serialize :: MonadPut m => Scientific -> m () Source # deserialize :: MonadGet m => m Scientific Source # | |
Serial Text Source # | |
Serial Text Source # | |
Serial Day Source # |
|
Serial AbsoluteTime Source # |
|
Defined in Data.Bytes.Serial serialize :: MonadPut m => AbsoluteTime -> m () Source # deserialize :: MonadGet m => m AbsoluteTime Source # | |
Serial DiffTime Source # |
|
Serial NominalDiffTime Source # |
|
Defined in Data.Bytes.Serial serialize :: MonadPut m => NominalDiffTime -> m () Source # deserialize :: MonadGet m => m NominalDiffTime Source # | |
Serial UTCTime Source # |
|
Serial UniversalTime Source # |
|
Defined in Data.Bytes.Serial serialize :: MonadPut m => UniversalTime -> m () Source # deserialize :: MonadGet m => m UniversalTime Source # | |
Serial LocalTime Source # | |
Serial TimeOfDay Source # | |
Serial TimeZone Source # | |
Serial ZonedTime Source # | |
Serial Integer Source # |
|
Serial Natural Source # |
|
Serial () Source # | |
Defined in Data.Bytes.Serial | |
Serial Bool Source # | |
Serial Char Source # | |
Serial Double Source # | |
Serial Float Source # | |
Serial Int Source # | |
Serial Word Source # | |
Serial a => Serial (ZipList a) Source # | |
Serial a => Serial (Identity a) Source # | |
Serial a => Serial (First a) Source # | |
Serial a => Serial (Last a) Source # | |
Serial a => Serial (Down a) Source # | |
Serial a => Serial (Dual a) Source # | |
Serial a => Serial (Product a) Source # | |
Serial a => Serial (Sum a) Source # | |
(Serial a, Integral a) => Serial (Ratio a) 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 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 # | |
Serial a => Serial (NonEmpty a) Source # | |
Serial a => Serial (Maybe a) Source # | |
Serial a => Serial [a] Source # | |
Defined in Data.Bytes.Serial | |
(Serial a, Serial b) => Serial (Either a b) Source # | |
HasResolution a => Serial (Fixed a) 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 (a, b) Source # | |
Defined in Data.Bytes.Serial | |
Serial a => Serial (Constant a b) Source # | |
Serial (f a) => Serial (Reverse f a) Source # | |
(Serial a, Serial b, Serial c) => Serial (a, b, c) Source # | |
Defined in Data.Bytes.Serial | |
(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 # | |
Defined in Data.Bytes.Serial | |
(Serial a, Serial b, Serial c, Serial d, Serial e) => Serial (a, b, c, d, e) Source # | |
Defined in Data.Bytes.Serial |
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 #
default serializeBE :: (MonadPut m, GSerialEndian (Rep a), Generic a) => a -> m () Source #
deserializeBE :: MonadGet m => m a Source #
default deserializeBE :: (MonadGet m, GSerialEndian (Rep a), Generic a) => m a Source #
serializeLE :: MonadPut m => a -> m () Source #
default serializeLE :: (MonadPut m, GSerialEndian (Rep a), Generic a) => a -> m () Source #
deserializeLE :: MonadGet m => m a Source #
default deserializeLE :: (MonadGet m, GSerialEndian (Rep a), Generic a) => m a Source #
serializeHost :: MonadPut m => a -> m () Source #
deserializeHost :: MonadGet m => m a Source #
Instances
Higher-order
These classes provide us with the ability to serialize containers that need polymorphic recursion.
class Serial1 f where Source #
Nothing
serializeWith :: MonadPut m => (a -> m ()) -> f a -> m () Source #
default serializeWith :: (MonadPut m, GSerial1 (Rep1 f), Generic1 f) => (a -> m ()) -> f a -> m () Source #
deserializeWith :: MonadGet m => m a -> m (f a) Source #
Instances
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 #
Instances
Serial2 Either Source # | |
Defined in Data.Bytes.Serial serializeWith2 :: MonadPut m => (a -> m ()) -> (b -> m ()) -> Either a b -> m () Source # deserializeWith2 :: MonadGet m => m a -> m b -> m (Either a b) Source # | |
Serial2 (,) Source # | |
Defined in Data.Bytes.Serial serializeWith2 :: MonadPut m => (a -> m ()) -> (b -> m ()) -> (a, b) -> m () Source # deserializeWith2 :: MonadGet m => m a -> m b -> m (a, b) Source # | |
Serial a => Serial2 ((,,) a) Source # | |
Defined in Data.Bytes.Serial serializeWith2 :: MonadPut m => (a0 -> m ()) -> (b -> m ()) -> (a, a0, b) -> m () Source # deserializeWith2 :: MonadGet m => m a0 -> m b -> m (a, a0, b) Source # | |
(Serial a, Serial b) => Serial2 ((,,,) a b) Source # | |
Defined in Data.Bytes.Serial serializeWith2 :: MonadPut m => (a0 -> m ()) -> (b0 -> m ()) -> (a, b, a0, b0) -> m () Source # deserializeWith2 :: MonadGet m => m a0 -> m b0 -> m (a, b, a0, b0) Source # | |
(Serial a, Serial b, Serial c) => Serial2 ((,,,,) a b c) Source # | |
Defined in Data.Bytes.Serial serializeWith2 :: MonadPut m => (a0 -> m ()) -> (b0 -> m ()) -> (a, b, c, a0, b0) -> m () Source # deserializeWith2 :: MonadGet m => m a0 -> m b0 -> m (a, b, c, a0, b0) 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 #
Instances
class GSerialEndian f where Source #
Used internally to provide generic big-endian serialization
Nothing
gserializeBE :: MonadPut m => f a -> m () Source #
default gserializeBE :: (MonadPut m, GSerial f) => f a -> m () Source #
gdeserializeBE :: MonadGet m => m (f a) Source #
default gdeserializeBE :: (MonadGet m, GSerial f) => m (f a) Source #
gserializeLE :: MonadPut m => f a -> m () Source #
default gserializeLE :: (MonadPut m, GSerial f) => f a -> m () Source #
gdeserializeLE :: MonadGet m => m (f a) Source #
default gdeserializeLE :: (MonadGet m, GSerial f) => m (f a) Source #
Instances
SerialEndian a => GSerialEndian (K1 i a :: Type -> Type) Source # | |
Defined in Data.Bytes.Serial gserializeBE :: MonadPut m => K1 i a a0 -> m () Source # gdeserializeBE :: MonadGet m => m (K1 i a a0) Source # gserializeLE :: MonadPut m => K1 i a a0 -> m () Source # gdeserializeLE :: MonadGet m => m (K1 i a a0) 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 #