data-serializer-0.3.5: Common API for serialization libraries
Safe HaskellNone
LanguageHaskell2010

Data.Deserializer

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.

check :: Int -> μ Bool Source #

check n returns True if the input has at least 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

Instances details
Deserializer CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Deserializer BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Deserializer μ => Deserializer (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Deserializer μ => Deserializer (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

newtype BinaryDeserializer α Source #

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

Constructors

BinaryDeserializer 

Fields

Instances

Instances details
Monad BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Functor BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Applicative BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Alternative BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

LookAheadParsing BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Parsing BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Deserializer BinaryDeserializer Source # 
Instance details

Defined in Data.Deserializer

Generic (BinaryDeserializer α) Source # 
Instance details

Defined in Data.Deserializer

Associated Types

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

type Rep (BinaryDeserializer α) Source # 
Instance details

Defined in Data.Deserializer

type Rep (BinaryDeserializer α) = D1 ('MetaData "BinaryDeserializer" "Data.Deserializer" "data-serializer-0.3.5-5ZaBepw8A5rA8RyTzqFuRS" 'True) (C1 ('MetaCons "BinaryDeserializer" 'PrefixI 'True) (S1 ('MetaSel ('Just "binaryDeserializer") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Get α))))

newtype CerealDeserializer α Source #

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

Constructors

CerealDeserializer 

Fields

Instances

Instances details
Monad CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Functor CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Applicative CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Alternative CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

LookAheadParsing CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Parsing CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Deserializer CerealDeserializer Source # 
Instance details

Defined in Data.Deserializer

Generic (CerealDeserializer α) Source # 
Instance details

Defined in Data.Deserializer

Associated Types

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

type Rep (CerealDeserializer α) Source # 
Instance details

Defined in Data.Deserializer

type Rep (CerealDeserializer α) = D1 ('MetaData "CerealDeserializer" "Data.Deserializer" "data-serializer-0.3.5-5ZaBepw8A5rA8RyTzqFuRS" 'True) (C1 ('MetaCons "CerealDeserializer" 'PrefixI 'True) (S1 ('MetaSel ('Just "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

Instances details
Monad μ => Monad (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Functor μ => Functor (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Applicative μ => Applicative (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Alternative μ => Alternative (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

LookAheadParsing μ => LookAheadParsing (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Parsing μ => Parsing (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Deserializer μ => Deserializer (LittleEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

(Typeable μ, Typeable α, Data (μ α)) => Data (LittleEndianDeserializer μ α) Source # 
Instance details

Defined in Data.Deserializer

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 :: forall r r'. (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 # 
Instance details

Defined in Data.Deserializer

Associated Types

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

type Rep (LittleEndianDeserializer μ α) Source # 
Instance details

Defined in Data.Deserializer

type Rep (LittleEndianDeserializer μ α) = D1 ('MetaData "LittleEndianDeserializer" "Data.Deserializer" "data-serializer-0.3.5-5ZaBepw8A5rA8RyTzqFuRS" 'True) (C1 ('MetaCons "LittleEndianDeserializer" 'PrefixI 'True) (S1 ('MetaSel ('Just "deserializeL") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (μ α))))

newtype BigEndianDeserializer μ α Source #

Deserializer wrapper with big endian default byte order.

Constructors

BigEndianDeserializer 

Fields

Instances

Instances details
Monad μ => Monad (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Functor μ => Functor (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Applicative μ => Applicative (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Alternative μ => Alternative (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

LookAheadParsing μ => LookAheadParsing (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Parsing μ => Parsing (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

Deserializer μ => Deserializer (BigEndianDeserializer μ) Source # 
Instance details

Defined in Data.Deserializer

(Typeable μ, Typeable α, Data (μ α)) => Data (BigEndianDeserializer μ α) Source # 
Instance details

Defined in Data.Deserializer

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 :: forall r r'. (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 # 
Instance details

Defined in Data.Deserializer

Associated Types

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

type Rep (BigEndianDeserializer μ α) Source # 
Instance details

Defined in Data.Deserializer

type Rep (BigEndianDeserializer μ α) = D1 ('MetaData "BigEndianDeserializer" "Data.Deserializer" "data-serializer-0.3.5-5ZaBepw8A5rA8RyTzqFuRS" 'True) (C1 ('MetaCons "BigEndianDeserializer" 'PrefixI 'True) (S1 ('MetaSel ('Just "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.

Default deserializer

data Deserialized α Source #

Deserialization result.

Constructors

Deserialized α 
Malformed [String] String 

defaultDeserializer :: (forall μ. Deserializer μ => μ α) -> ByteString -> Deserialized α Source #

Deserialize a ByteString via the default deserializer.

Deserializable types

class Deserializable α where Source #

Deserializable type. get must not rely on eof.

Methods

get :: Deserializer μ => μ α Source #

Instances

Instances details
Deserializable Bool Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Bool Source #

Deserializable Int Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Int Source #

Deserializable Int8 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Int8 Source #

Deserializable Int16 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Int16 Source #

Deserializable Int32 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Int32 Source #

Deserializable Int64 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Int64 Source #

Deserializable Word Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Word Source #

Deserializable Word8 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Word8 Source #

Deserializable Word16 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Word16 Source #

Deserializable Word32 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Word32 Source #

Deserializable Word64 Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ Word64 Source #

Deserializable ByteString Source # 
Instance details

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ ByteString Source #

Deserializable ShortByteString Source # 
Instance details

Defined in Data.Deserializer

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

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ (Maybe α) Source #

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

Defined in Data.Deserializer

Methods

get :: Deserializer μ => μ (Either α β) Source #

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

Defined in Data.Deserializer

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.

deserializeBytes :: Deserializable α => [Word8] -> Deserialized α Source #

Deserialize a value of type α from a list of bytes via the defaultDeserializer.

deserializeBytesAs :: Deserializable α => p α -> [Word8] -> Deserialized α Source #

Provide a hint for the type system when using deserializeBytes.

deserializeByteString :: Deserializable α => ByteString -> Deserialized α Source #

Deserialize a value of type α from a ByteString via the defaultDeserializer.

deserializeByteStringAs :: Deserializable α => p α -> ByteString -> Deserialized α Source #

Provide a hint for the type system when using deserializeByteString.

deserializeLazyByteString :: Deserializable α => ByteString -> Deserialized α Source #

Deserialize a value of type α from a ByteString via the defaultDeserializer.

deserializeLazyByteStringAs :: Deserializable α => p α -> ByteString -> Deserialized α Source #

Provide a hint for the type system when using deserializeLazyByteString.

fromBytesAs :: Deserializable α => p α -> [Word8] -> Maybe α Source #

Provide a hint for the type system when using fromBytes

fromByteStringAs :: Deserializable α => p α -> ByteString -> Maybe α Source #

Provide a hint for the type system when using fromByteString

fromLazyByteStringAs :: Deserializable α => p α -> ByteString -> Maybe α Source #

Provide a hint for the type system when using fromLazyByteString

class RestDeserializable α where Source #

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

Methods

getRest :: Deserializer μ => μ α Source #

Instances

Instances details
RestDeserializable ByteString Source # 
Instance details

Defined in Data.Deserializer

RestDeserializable ByteString Source # 
Instance details

Defined in Data.Deserializer

RestDeserializable ShortByteString Source # 
Instance details

Defined in Data.Deserializer

RestDeserializable Builder Source # 
Instance details

Defined in Data.Deserializer

Methods

getRest :: Deserializer μ => μ Builder Source #

Deserializable α => RestDeserializable [α] Source # 
Instance details

Defined in Data.Deserializer

Methods

getRest :: Deserializer μ => μ [α] Source #

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

Defined in Data.Deserializer

Methods

getRest :: Deserializer μ => μ (Either α β) Source #

(Deserializable α, RestDeserializable β) => RestDeserializable (α, β) Source # 
Instance details

Defined in Data.Deserializer

Methods

getRest :: Deserializer μ => μ (α, β) Source #