data-serializer-0.3.4.1: 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 # 
Instance details

Defined in Data.Serializer

Serializer Builder Source # 
Instance details

Defined in Data.Serializer

Serializer CerealSerializer Source # 
Instance details

Defined in Data.Serializer

Serializer BinarySerializer Source # 
Instance details

Defined in Data.Serializer

Serializer [Word8] Source # 
Instance details

Defined in Data.Serializer

Serializer s => Serializer (BigEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

Serializer s => Serializer (LittleEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

buildBytes :: Builder -> [Word8] Source #

A shorthand for "LBS.unpack' . toLazyByteString.

newtype BinarySerializer Source #

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

Constructors

BinarySerializer 
Instances
Generic BinarySerializer Source # 
Instance details

Defined in Data.Serializer

Associated Types

type Rep BinarySerializer :: Type -> Type #

Semigroup BinarySerializer Source # 
Instance details

Defined in Data.Serializer

Monoid BinarySerializer Source # 
Instance details

Defined in Data.Serializer

Serializer BinarySerializer Source # 
Instance details

Defined in Data.Serializer

type Rep BinarySerializer Source # 
Instance details

Defined in Data.Serializer

type Rep BinarySerializer = D1 (MetaData "BinarySerializer" "Data.Serializer" "data-serializer-0.3.4.1-KE0Z8xoLqlE9nkV6DGXUq0" True) (C1 (MetaCons "BinarySerializer" PrefixI True) (S1 (MetaSel (Just "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 # 
Instance details

Defined in Data.Serializer

Associated Types

type Rep CerealSerializer :: Type -> Type #

Semigroup CerealSerializer Source # 
Instance details

Defined in Data.Serializer

Monoid CerealSerializer Source # 
Instance details

Defined in Data.Serializer

Serializer CerealSerializer Source # 
Instance details

Defined in Data.Serializer

type Rep CerealSerializer Source # 
Instance details

Defined in Data.Serializer

type Rep CerealSerializer = D1 (MetaData "CerealSerializer" "Data.Serializer" "data-serializer-0.3.4.1-KE0Z8xoLqlE9nkV6DGXUq0" True) (C1 (MetaCons "CerealSerializer" PrefixI True) (S1 (MetaSel (Just "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 # 
Instance details

Defined in Data.Serializer

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 # 
Instance details

Defined in Data.Serializer

Associated Types

type Rep (LittleEndianSerializer s) :: Type -> Type #

Semigroup s => Semigroup (LittleEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

Monoid s => Monoid (LittleEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

Serializer s => Serializer (LittleEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

type Rep (LittleEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

type Rep (LittleEndianSerializer s) = D1 (MetaData "LittleEndianSerializer" "Data.Serializer" "data-serializer-0.3.4.1-KE0Z8xoLqlE9nkV6DGXUq0" True) (C1 (MetaCons "LittleEndianSerializer" PrefixI True) (S1 (MetaSel (Just "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 # 
Instance details

Defined in Data.Serializer

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 # 
Instance details

Defined in Data.Serializer

Associated Types

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

Semigroup s => Semigroup (BigEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

Monoid s => Monoid (BigEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

Serializer s => Serializer (BigEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

type Rep (BigEndianSerializer s) Source # 
Instance details

Defined in Data.Serializer

type Rep (BigEndianSerializer s) = D1 (MetaData "BigEndianSerializer" "Data.Serializer" "data-serializer-0.3.4.1-KE0Z8xoLqlE9nkV6DGXUq0" True) (C1 (MetaCons "BigEndianSerializer" PrefixI True) (S1 (MetaSel (Just "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.

Methods

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

Instances
Serializable Bool Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Int Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Int8 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Int16 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Int32 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Int64 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Word Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Word8 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Word16 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Word32 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable Word64 Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable ByteString Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable ShortByteString Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable α => Serializable (Maybe α) Source # 
Instance details

Defined in Data.Serializer

Methods

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

(Serializable α, Serializable β) => Serializable (Either α β) Source # 
Instance details

Defined in Data.Serializer

Methods

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

(Serializable α, Serializable β) => Serializable (α, β) Source # 
Instance details

Defined in Data.Serializer

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.

toBytes :: Serializable α => α -> [Word8] Source #

A shorthand for buildBytes . put.

class Serializable α => SizedSerializable α where Source #

Types with fixed serialized size.

Methods

size :: Proxy α -> Int Source #

Serialized size in bytes.

Instances
SizedSerializable Bool Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Bool -> Int Source #

SizedSerializable Int Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Int -> Int Source #

SizedSerializable Int8 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Int8 -> Int Source #

SizedSerializable Int16 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Int16 -> Int Source #

SizedSerializable Int32 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Int32 -> Int Source #

SizedSerializable Int64 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Int64 -> Int Source #

SizedSerializable Word Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Word -> Int Source #

SizedSerializable Word8 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Word8 -> Int Source #

SizedSerializable Word16 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Word16 -> Int Source #

SizedSerializable Word32 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Word32 -> Int Source #

SizedSerializable Word64 Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy Word64 -> Int Source #

(SizedSerializable α, SizedSerializable β) => SizedSerializable (α, β) Source # 
Instance details

Defined in Data.Serializer

Methods

size :: Proxy (α, β) -> Int Source #

class RestSerializable α where Source #

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

Methods

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

Instances
RestSerializable ByteString Source # 
Instance details

Defined in Data.Serializer

Methods

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

RestSerializable ByteString Source # 
Instance details

Defined in Data.Serializer

Methods

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

RestSerializable ShortByteString Source # 
Instance details

Defined in Data.Serializer

RestSerializable Builder Source # 
Instance details

Defined in Data.Serializer

Methods

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

Serializable α => RestSerializable [α] Source # 
Instance details

Defined in Data.Serializer

Methods

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

(Serializable α, RestSerializable β) => RestSerializable (α, β) Source # 
Instance details

Defined in Data.Serializer

Methods

putRest :: Serializer s => (α, β) -> s Source #