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.
Synopsis
- 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 #
Instances
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 Natural Source # |
|
Serial Ordering Source # |
|
Serial Word Source # | |
Serial Word8 Source # | |
Serial Word16 Source # | |
Serial Word32 Source # | |
Serial Word64 Source # | |
Serial () Source # | |
Defined in Data.Bytes.Serial | |
Serial Void Source # | |
Serial Version Source # | |
Serial All Source # | |
Serial Any 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 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 ZonedTime Source # | |
Serial LocalTime Source # | |
Serial TimeOfDay Source # | |
Serial TimeZone Source # | |
Serial UniversalTime Source # |
|
Defined in Data.Bytes.Serial serialize :: MonadPut m => UniversalTime -> m () Source # deserialize :: MonadGet m => m UniversalTime Source # | |
Serial UTCTime Source # |
|
Serial NominalDiffTime Source # |
|
Defined in Data.Bytes.Serial serialize :: MonadPut m => NominalDiffTime -> m () Source # deserialize :: MonadGet m => m NominalDiffTime 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 Day Source # |
|
Serial a => Serial [a] Source # | |
Defined in Data.Bytes.Serial | |
Serial a => Serial (Maybe a) Source # | |
(Serial a, Integral a) => Serial (Ratio a) Source # |
|
HasResolution a => Serial (Fixed a) 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 (Dual a) Source # | |
Serial a => Serial (Sum a) Source # | |
Serial a => Serial (Product a) Source # | |
Serial a => Serial (Down a) Source # | |
Serial a => Serial (NonEmpty 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 # | |
Defined in Data.Bytes.Serial | |
(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 # | |
Defined in Data.Bytes.Serial | |
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 # | |
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 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.
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 #
Instances
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 #
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
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 #
Instances
SerialEndian a => GSerialEndian (K1 i a :: * -> *) 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 #