data-serializer-0.3: Common API for serialization libraries

Safe HaskellNone
LanguageHaskell2010

Data.Serializer

Contents

Description

Serialization monoid and serializable types.

Synopsis

Serialization monoid

class (Semigroup s, Monoid s) => Serializer s where Source #

Serialization monoid.

Minimal complete definition

word8

Methods

endian :: Proxy s -> Endian Source #

Default byte order of the serializer.

word8 :: Word8 -> s Source #

Serialize a byte. word8 x = byteString (singleton x)

word16 :: Word16 -> s Source #

Serialize an unsigned 16-bit integer in the default byte order.

word32 :: Word32 -> s Source #

Serialize an unsigned 32-bit integer in the default byte order.

word64 :: Word64 -> s Source #

Serialize an unsigned 64-bit integer in the default byte order.

word16L :: Word16 -> s Source #

Serialize an unsigned 16-bit integer in little endian.

word16B :: Word16 -> s Source #

Serialize an unsigned 16-bit integer in big endian.

word32L :: Word32 -> s Source #

Serialize an unsigned 32-bit integer in little endian.

word32B :: Word32 -> s Source #

Serialize an unsigned 32-bit integer in big endian.

word64L :: Word64 -> s Source #

Serialize an unsigned 64-bit integer in little endian.

word64B :: Word64 -> s Source #

Serialize an unsigned 64-bit integer in big endian.

byteString :: ByteString -> s Source #

Serialize a ByteString. Must be a monoid homomorphism.

shortByteString :: ShortByteString -> s Source #

Serialize a ShortByteString. Must be a monoid homomorphism.

lazyByteString :: ByteString -> s Source #

Serialize a lazy ByteString. Must be a monoid homomorphism.

builder :: Builder -> s Source #

Serialize a Builder. Must be a monoid homomorphism.

Instances

Serializer Put Source # 
Serializer Builder Source # 
Serializer CerealSerializer Source # 
Serializer BinarySerializer Source # 
Serializer [Word8] Source # 
Serializer s => Serializer (BigEndianSerializer s) Source # 
Serializer s => Serializer (LittleEndianSerializer s) Source # 

newtype BinarySerializer Source #

A wrapper around the Put monoid (to avoid orphan instances).

Constructors

BinarySerializer 

Instances

Generic BinarySerializer Source # 
Semigroup BinarySerializer Source # 
Monoid BinarySerializer Source # 
Serializer BinarySerializer Source # 
type Rep BinarySerializer Source # 
type Rep BinarySerializer = D1 (MetaData "BinarySerializer" "Data.Serializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "BinarySerializer" PrefixI True) (S1 (MetaSel (Just Symbol "binarySerializer") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Put)))

newtype CerealSerializer Source #

A wrapper around the Put monoid (to avoid orphan instances).

Constructors

CerealSerializer 

Instances

Generic CerealSerializer Source # 
Semigroup CerealSerializer Source # 
Monoid CerealSerializer Source # 
Serializer CerealSerializer Source # 
type Rep CerealSerializer Source # 
type Rep CerealSerializer = D1 (MetaData "CerealSerializer" "Data.Serializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "CerealSerializer" PrefixI True) (S1 (MetaSel (Just Symbol "cerealSerializer") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Put)))

Binary words serialization

word16H :: Serializer s => Word16 -> s Source #

Serialize an usigned 16-bit integer in host byte order.

word32H :: Serializer s => Word32 -> s Source #

Serialize an unsigned 32-bit integer in host byte order.

word64H :: Serializer s => Word64 -> s Source #

Serialize an unsigned 64-bit integer in host byte order.

word :: Serializer s => Word -> s Source #

Serialize an unsigned native-sized integer in serializer default byte order.

wordL :: Serializer s => Word -> s Source #

Serialize an unsigned native-sized integer in little endian.

wordB :: Serializer s => Word -> s Source #

Serialize an unsigned native-sized integer in big endian.

wordH :: Serializer s => Word -> s Source #

Serialize an unsigned native-sized integer in host byte order.

int8 :: Serializer s => Int8 -> s Source #

Serialize a signed 8-bit integer.

int16 :: Serializer s => Int16 -> s Source #

Serialize a signed 16-bit integer in serializer default byte order.

int16L :: Serializer s => Int16 -> s Source #

Serialize a signed 16-bit integer in little endian.

int16B :: Serializer s => Int16 -> s Source #

Serialize a signed 16-bit integer in big endian.

int16H :: Serializer s => Int16 -> s Source #

Serialize a signed 16-bit integer in host byte order.

int32 :: Serializer s => Int32 -> s Source #

Serialize a signed 32-bit integer in serializer default byte order.

int32L :: Serializer s => Int32 -> s Source #

Serialize a signed 32-bit integer in little endian.

int32B :: Serializer s => Int32 -> s Source #

Serialize a signed 32-bit integer in big endian.

int32H :: Serializer s => Int32 -> s Source #

Serialize a signed 32-bit integer in host byte order.

int64 :: Serializer s => Int64 -> s Source #

Serialize a signed 64-bit integer in serializer default byte order.

int64L :: Serializer s => Int64 -> s Source #

Serialize a signed 64-bit integer in little endian.

int64B :: Serializer s => Int64 -> s Source #

Serialize a signed 64-bit integer in big endian.

int64H :: Serializer s => Int64 -> s Source #

Serialize a signed 64-bit integer in host byte order.

int :: Serializer s => Int -> s Source #

Serialize a signed native-sized integer in serializer default byte order.

intL :: Serializer s => Int -> s Source #

Serialize a signed native-sized integer in little endian.

intB :: Serializer s => Int64 -> s Source #

Serialize a signed native-sized integer in big endian.

intH :: Serializer s => Int -> s Source #

Serialize a signed native-sized integer in host byte order.

Endian serializers

newtype LittleEndianSerializer s Source #

Serializer wrapper with little endian default byte order.

Constructors

LittleEndianSerializer 

Fields

Instances

Data s => Data (LittleEndianSerializer s) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LittleEndianSerializer s -> c (LittleEndianSerializer s) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s) #

toConstr :: LittleEndianSerializer s -> Constr #

dataTypeOf :: LittleEndianSerializer s -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (LittleEndianSerializer s)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (LittleEndianSerializer s)) #

gmapT :: (forall b. Data b => b -> b) -> LittleEndianSerializer s -> LittleEndianSerializer s #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LittleEndianSerializer s -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LittleEndianSerializer s -> r #

gmapQ :: (forall d. Data d => d -> u) -> LittleEndianSerializer s -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> LittleEndianSerializer s -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> LittleEndianSerializer s -> m (LittleEndianSerializer s) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LittleEndianSerializer s -> m (LittleEndianSerializer s) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LittleEndianSerializer s -> m (LittleEndianSerializer s) #

Generic (LittleEndianSerializer s) Source # 
Semigroup s => Semigroup (LittleEndianSerializer s) Source # 
Monoid s => Monoid (LittleEndianSerializer s) Source # 
Serializer s => Serializer (LittleEndianSerializer s) Source # 
type Rep (LittleEndianSerializer s) Source # 
type Rep (LittleEndianSerializer s) = D1 (MetaData "LittleEndianSerializer" "Data.Serializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "LittleEndianSerializer" PrefixI True) (S1 (MetaSel (Just Symbol "serializeL") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 s)))

newtype BigEndianSerializer s Source #

Serializer wrapper with big endian default byte order.

Constructors

BigEndianSerializer 

Fields

Instances

Data s => Data (BigEndianSerializer s) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BigEndianSerializer s -> c (BigEndianSerializer s) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s) #

toConstr :: BigEndianSerializer s -> Constr #

dataTypeOf :: BigEndianSerializer s -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (BigEndianSerializer s)) #

gmapT :: (forall b. Data b => b -> b) -> BigEndianSerializer s -> BigEndianSerializer s #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r #

gmapQ :: (forall d. Data d => d -> u) -> BigEndianSerializer s -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> BigEndianSerializer s -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BigEndianSerializer s -> m (BigEndianSerializer s) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BigEndianSerializer s -> m (BigEndianSerializer s) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BigEndianSerializer s -> m (BigEndianSerializer s) #

Generic (BigEndianSerializer s) Source # 

Associated Types

type Rep (BigEndianSerializer s) :: * -> * #

Semigroup s => Semigroup (BigEndianSerializer s) Source # 
Monoid s => Monoid (BigEndianSerializer s) Source # 
Serializer s => Serializer (BigEndianSerializer s) Source # 
type Rep (BigEndianSerializer s) Source # 
type Rep (BigEndianSerializer s) = D1 (MetaData "BigEndianSerializer" "Data.Serializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "BigEndianSerializer" PrefixI True) (S1 (MetaSel (Just Symbol "serializeB") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 s)))

serializeIn :: Serializer s => Endian -> (forall s'. Serializer s' => s') -> s Source #

Force the default byte order.

serializeH :: Serializer s => (forall s'. Serializer s' => s') -> s Source #

Force the default byte order to be the host byte order.

Serializable types

class Serializable α where Source #

Serializable type. put must work under assumption that it will be followed by more output.

Minimal complete definition

put

Methods

put :: Serializer s => α -> s Source #

putIn :: (Serializer s, Serializable α) => Endian -> α -> s Source #

Serialize a value using the provided default byte order.

putL :: (Serializer s, Serializable α) => α -> s Source #

Serialize a value using little endian as the default byte order.

putB :: (Serializer s, Serializable α) => α -> s Source #

Serialize a value using big endian as the default byte order.

putH :: (Serializer s, Serializable α) => α -> s Source #

Serialize a value using host byte order as the default byte order.

class RestSerializable α where Source #

Serializable type. putRest must work under assumption that it will not be followed by any more output.

Minimal complete definition

putRest

Methods

putRest :: Serializer s => α -> s Source #