bytes-0.12: Sharing code for serialization between binary and cereal

Portabilitynon-portable
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellTrustworthy

Data.Bytes.Serial

Contents

Description

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

Serialization

class Serial a whereSource

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.

Methods

serialize :: MonadPut m => a -> m ()Source

deserialize :: MonadGet m => m aSource

Specifying endianness

class SerialEndian a whereSource

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.

Higher-order

These classes provide us with the ability to serialize containers that need polymorphic recursion.

class Serial1 f whereSource

Methods

serializeWith :: MonadPut m => (a -> m ()) -> f a -> m ()Source

deserializeWith :: MonadGet m => m a -> m (f a)Source

Instances

Serial1 [] 
Serial1 Maybe 
Serial1 Seq 
Serial1 IntMap 
Serial1 Set 
Serial a => Serial1 (Either a) 
Serial a => Serial1 ((,) a) 
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

class Serial2 f whereSource

Methods

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 
Serial2 (,) 
Serial2 Map 
Serial a => Serial2 ((,,) a) 
(Serial a, Serial b) => Serial2 ((,,,) a b) 
(Serial a, Serial b, Serial c) => Serial2 ((,,,,) a b c) 

serialize2 :: (MonadPut m, Serial2 f, Serial a, Serial b) => f a b -> m ()Source

deserialize2 :: (MonadGet m, Serial2 f, Serial a, Serial 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 aSource

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 whereSource

Used internally to provide generic serialization

Methods

gserialize :: MonadPut m => f a -> m ()Source

gdeserialize :: MonadGet m => m (f a)Source

Instances

GSerial V1 
GSerial U1 
Serial a => GSerial (K1 i a) 
(GSerial f, GSerial g) => GSerial (:+: f g) 
(GSerial f, GSerial g) => GSerial (:*: f g) 
GSerial f => GSerial (M1 i c f) 

class GSerialEndian f whereSource

Used internally to provide generic big-endian serialization

Methods

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

Instances

class GSerial1 f whereSource

Used internally to provide generic serialization

Methods

gserializeWith :: MonadPut m => (a -> m ()) -> f a -> m ()Source

gdeserializeWith :: MonadGet m => m a -> m (f a)Source

Instances

GSerial1 V1 
GSerial1 U1 
GSerial1 Par1 
GSerial1 f => GSerial1 (Rec1 f) 
Serial a => GSerial1 (K1 i a) 
(GSerial1 f, GSerial1 g) => GSerial1 (:+: f g) 
(GSerial1 f, GSerial1 g) => GSerial1 (:*: f g) 
GSerial1 f => GSerial1 (M1 i c f)