data-serializer-0.3: Common API for serialization libraries

Safe HaskellNone
LanguageHaskell2010

Data.Deserializer

Contents

Description

Deserialization monad and deserializable types.

Synopsis

Deserialization monad

class (Monad μ, Parsing μ) => Deserializer μ where Source #

Deserialization monad.

Minimal complete definition

ensure, take, chunk, isolate

Methods

endian :: Proxy μ -> Endian Source #

Default byte order of the deserializer.

word8 :: μ Word8 Source #

Deserialze a byte.

word16 :: μ Word16 Source #

Deserialize an unsigned 16-bit integer in default byte order.

word32 :: μ Word32 Source #

Deserialize an unsigned 32-bit integer in default byte order.

word64 :: μ Word64 Source #

Deserialize an unsigned 64-bit integer in default byte order.

word16L :: μ Word16 Source #

Deserialize an unsigned 16-bit integer in little endian.

word16B :: μ Word16 Source #

Deserialize an unsigned 16-bit integer in big endian.

word32L :: μ Word32 Source #

Deserialize an unsigned 32-bit integer in little endian.

word32B :: μ Word32 Source #

Deserialize an unsigned 32-bit integer in big endian.

word64L :: μ Word64 Source #

Deserialize an unsigned 64-bit integer in little endian.

word64B :: μ Word64 Source #

Deserialize an unsigned 64-bit integer in big endian.

satisfy :: (Word8 -> Bool) -> μ Word8 Source #

satisfy p deserializes a byte that satisfies the predicate p, failing otherwise.

byte :: Word8 -> μ Word8 Source #

Deserialize the specified byte value, failing on any other input.

notByte :: Word8 -> μ Word8 Source #

notByte c deserializes any byte that is not equal to c, failing if c is encountered.

bytes :: ByteString -> μ ByteString Source #

bytes bs deserializes a sequence of bytes given by bs, failing on any other input.

skip :: Int -> μ () Source #

Skip exactly the given number of bytes.

ensure :: Int -> μ ByteString Source #

ensure n checks that the input has at least n more bytes and returns a portion of the input of length greater or equal to n (without consuming it).

ensure_ :: Int -> μ () Source #

ensure_ n fails if the input has less than n more bytes.

take :: Int -> μ ByteString Source #

Consume exactly the given number of bytes.

chunk :: μ ByteString Source #

Consume a portion of the input (the size of the returned ByteString is implementation dependent). Empty result means that the eof is reached.

isolate :: Int -> μ α -> μ α Source #

isolate n d feeds the next n bytes to the deserializer d. If d consumes less or more that n bytes, isolate will fail.

Instances

Deserializer CerealDeserializer Source # 
Deserializer BinaryDeserializer Source # 
Deserializer μ => Deserializer (BigEndianDeserializer μ) Source # 
Deserializer μ => Deserializer (LittleEndianDeserializer μ) Source # 

newtype BinaryDeserializer α Source #

A wrapper around the Get monad (to avoid orphan instances).

Constructors

BinaryDeserializer 

Fields

Instances

Monad BinaryDeserializer Source # 
Functor BinaryDeserializer Source # 
Applicative BinaryDeserializer Source # 
Alternative BinaryDeserializer Source # 
LookAheadParsing BinaryDeserializer Source # 
Parsing BinaryDeserializer Source # 
Deserializer BinaryDeserializer Source # 
Generic (BinaryDeserializer α) Source # 

Associated Types

type Rep (BinaryDeserializer α) :: * -> * #

type Rep (BinaryDeserializer α) Source # 
type Rep (BinaryDeserializer α) = D1 (MetaData "BinaryDeserializer" "Data.Deserializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "BinaryDeserializer" PrefixI True) (S1 (MetaSel (Just Symbol "binaryDeserializer") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Get α))))

newtype CerealDeserializer α Source #

A wrapper around the Get monad (to avoid orphan instances).

Constructors

CerealDeserializer 

Fields

Instances

Monad CerealDeserializer Source # 
Functor CerealDeserializer Source # 
Applicative CerealDeserializer Source # 
Alternative CerealDeserializer Source # 
LookAheadParsing CerealDeserializer Source # 
Parsing CerealDeserializer Source # 
Deserializer CerealDeserializer Source # 
Generic (CerealDeserializer α) Source # 

Associated Types

type Rep (CerealDeserializer α) :: * -> * #

type Rep (CerealDeserializer α) Source # 
type Rep (CerealDeserializer α) = D1 (MetaData "CerealDeserializer" "Data.Deserializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "CerealDeserializer" PrefixI True) (S1 (MetaSel (Just Symbol "cerealDeserializer") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Get α))))

Binary word parsing

word16H :: Deserializer μ => μ Word16 Source #

Deserialize an unsigned 16-bit integer in host byte order.

word32H :: Deserializer μ => μ Word32 Source #

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

word64H :: Deserializer μ => μ Word64 Source #

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

word :: Deserializer μ => μ Word Source #

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

wordL :: Deserializer μ => μ Word Source #

Deserialize an unsigned native-sized integer in little endian.

wordB :: Deserializer μ => μ Word Source #

Deserialize an unsigned native-sized integer in big endian.

wordH :: Deserializer μ => μ Word Source #

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

int8 :: Deserializer μ => μ Int8 Source #

Deserialize a signed 8-bit integer.

int16 :: Deserializer μ => μ Int16 Source #

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

int16L :: Deserializer μ => μ Int16 Source #

Deserialize a signed 16-bit integer in little endian.

int16B :: Deserializer μ => μ Int16 Source #

Deserialize a signed 16-bit integer in big endian.

int16H :: Deserializer μ => μ Int16 Source #

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

int32 :: Deserializer μ => μ Int32 Source #

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

int32L :: Deserializer μ => μ Int32 Source #

Deserialize a signed 32-bit integer in little endian.

int32B :: Deserializer μ => μ Int32 Source #

Deserialize a signed 32-bit integer in big endian.

int32H :: Deserializer μ => μ Int32 Source #

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

int64 :: Deserializer μ => μ Int64 Source #

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

int64L :: Deserializer μ => μ Int64 Source #

Deserialize a signed 64-bit integer in little endian.

int64B :: Deserializer μ => μ Int64 Source #

Deserialize a signed 64-bit integer in big endian.

int64H :: Deserializer μ => μ Int64 Source #

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

int :: Deserializer μ => μ Int Source #

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

intL :: Deserializer μ => μ Int Source #

Deserialize a signed native-sized integer in little endian.

intB :: Deserializer μ => μ Int Source #

Deserialize a signed native-sized integer in big endian.

intH :: Deserializer μ => μ Int Source #

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

Parsing combinators

label :: Parsing μ => String -> μ α -> μ α Source #

A shorthand for flip (<?>).

Endian deserializers

newtype LittleEndianDeserializer μ α Source #

Deserializer wrapper with little endian default byte order.

Constructors

LittleEndianDeserializer 

Fields

Instances

Monad μ => Monad (LittleEndianDeserializer μ) Source # 
Functor μ => Functor (LittleEndianDeserializer μ) Source # 
Applicative μ => Applicative (LittleEndianDeserializer μ) Source # 
Alternative μ => Alternative (LittleEndianDeserializer μ) Source # 
LookAheadParsing μ => LookAheadParsing (LittleEndianDeserializer μ) Source # 
Parsing μ => Parsing (LittleEndianDeserializer μ) Source # 
Deserializer μ => Deserializer (LittleEndianDeserializer μ) Source # 
(Data (μ α), Typeable * α, Typeable (* -> *) μ) => Data (LittleEndianDeserializer μ α) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LittleEndianDeserializer μ α -> c (LittleEndianDeserializer μ α) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (LittleEndianDeserializer μ α) #

toConstr :: LittleEndianDeserializer μ α -> Constr #

dataTypeOf :: LittleEndianDeserializer μ α -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (LittleEndianDeserializer μ α)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (LittleEndianDeserializer μ α)) #

gmapT :: (forall b. Data b => b -> b) -> LittleEndianDeserializer μ α -> LittleEndianDeserializer μ α #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LittleEndianDeserializer μ α -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LittleEndianDeserializer μ α -> r #

gmapQ :: (forall d. Data d => d -> u) -> LittleEndianDeserializer μ α -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> LittleEndianDeserializer μ α -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> LittleEndianDeserializer μ α -> m (LittleEndianDeserializer μ α) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LittleEndianDeserializer μ α -> m (LittleEndianDeserializer μ α) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LittleEndianDeserializer μ α -> m (LittleEndianDeserializer μ α) #

Generic (LittleEndianDeserializer μ α) Source # 

Associated Types

type Rep (LittleEndianDeserializer μ α) :: * -> * #

type Rep (LittleEndianDeserializer μ α) Source # 
type Rep (LittleEndianDeserializer μ α) = D1 (MetaData "LittleEndianDeserializer" "Data.Deserializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "LittleEndianDeserializer" PrefixI True) (S1 (MetaSel (Just Symbol "deserializeL") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (μ α))))

newtype BigEndianDeserializer μ α Source #

Deserializer wrapper with big endian default byte order.

Constructors

BigEndianDeserializer 

Fields

Instances

Monad μ => Monad (BigEndianDeserializer μ) Source # 
Functor μ => Functor (BigEndianDeserializer μ) Source # 
Applicative μ => Applicative (BigEndianDeserializer μ) Source # 
Alternative μ => Alternative (BigEndianDeserializer μ) Source # 
LookAheadParsing μ => LookAheadParsing (BigEndianDeserializer μ) Source # 
Parsing μ => Parsing (BigEndianDeserializer μ) Source # 
Deserializer μ => Deserializer (BigEndianDeserializer μ) Source # 
(Data (μ α), Typeable * α, Typeable (* -> *) μ) => Data (BigEndianDeserializer μ α) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BigEndianDeserializer μ α -> c (BigEndianDeserializer μ α) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (BigEndianDeserializer μ α) #

toConstr :: BigEndianDeserializer μ α -> Constr #

dataTypeOf :: BigEndianDeserializer μ α -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (BigEndianDeserializer μ α)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (BigEndianDeserializer μ α)) #

gmapT :: (forall b. Data b => b -> b) -> BigEndianDeserializer μ α -> BigEndianDeserializer μ α #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BigEndianDeserializer μ α -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BigEndianDeserializer μ α -> r #

gmapQ :: (forall d. Data d => d -> u) -> BigEndianDeserializer μ α -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> BigEndianDeserializer μ α -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> BigEndianDeserializer μ α -> m (BigEndianDeserializer μ α) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BigEndianDeserializer μ α -> m (BigEndianDeserializer μ α) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BigEndianDeserializer μ α -> m (BigEndianDeserializer μ α) #

Generic (BigEndianDeserializer μ α) Source # 

Associated Types

type Rep (BigEndianDeserializer μ α) :: * -> * #

type Rep (BigEndianDeserializer μ α) Source # 
type Rep (BigEndianDeserializer μ α) = D1 (MetaData "BigEndianDeserializer" "Data.Deserializer" "data-serializer-0.3-FSbsSRNEdXv7Y5LxQxRqC1" True) (C1 (MetaCons "BigEndianDeserializer" PrefixI True) (S1 (MetaSel (Just Symbol "deserializeB") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (μ α))))

deserializeIn :: Deserializer μ => Endian -> (forall μ'. Deserializer μ' => μ' α) -> μ α Source #

Force the default byte order.

deserializeH :: Deserializer μ => (forall μ'. Deserializer μ' => μ' α) -> μ α Source #

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

Deserializable types

class Deserializable α where Source #

Deserializable type. get must not rely on eof.

Minimal complete definition

get

Methods

get :: Deserializer μ => μ α Source #

getIn :: (Deserializer μ, Deserializable α) => Endian -> μ α Source #

Deserialize a value using the provided default byte order.

getL :: (Deserializer μ, Deserializable α) => μ α Source #

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

getB :: (Deserializer μ, Deserializable α) => μ α Source #

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

getH :: (Deserializer μ, Deserializable α) => μ α Source #

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

class RestDeserializable α where Source #

Deserializable type. getRest must consume all the remaining input or fail.

Minimal complete definition

getRest

Methods

getRest :: Deserializer μ => μ α Source #