Safe Haskell | None |
---|---|
Language | Haskell2010 |
Deserialization monad and deserializable types.
Synopsis
- class (Monad μ, Parsing μ) => Deserializer μ where
- endian :: Proxy μ -> Endian
- word8 :: μ Word8
- word16 :: μ Word16
- word32 :: μ Word32
- word64 :: μ Word64
- word16L :: μ Word16
- word16B :: μ Word16
- word32L :: μ Word32
- word32B :: μ Word32
- word64L :: μ Word64
- word64B :: μ Word64
- satisfy :: (Word8 -> Bool) -> μ Word8
- byte :: Word8 -> μ Word8
- notByte :: Word8 -> μ Word8
- bytes :: ByteString -> μ ByteString
- skip :: Int -> μ ()
- ensure :: Int -> μ ByteString
- ensure_ :: Int -> μ ()
- check :: Int -> μ Bool
- take :: Int -> μ ByteString
- chunk :: μ ByteString
- isolate :: Int -> μ α -> μ α
- newtype BinaryDeserializer α = BinaryDeserializer {
- binaryDeserializer :: Get α
- newtype CerealDeserializer α = CerealDeserializer {
- cerealDeserializer :: Get α
- word16H :: Deserializer μ => μ Word16
- word32H :: Deserializer μ => μ Word32
- word64H :: Deserializer μ => μ Word64
- word :: Deserializer μ => μ Word
- wordL :: Deserializer μ => μ Word
- wordB :: Deserializer μ => μ Word
- wordH :: Deserializer μ => μ Word
- int8 :: Deserializer μ => μ Int8
- int16 :: Deserializer μ => μ Int16
- int16L :: Deserializer μ => μ Int16
- int16B :: Deserializer μ => μ Int16
- int16H :: Deserializer μ => μ Int16
- int32 :: Deserializer μ => μ Int32
- int32L :: Deserializer μ => μ Int32
- int32B :: Deserializer μ => μ Int32
- int32H :: Deserializer μ => μ Int32
- int64 :: Deserializer μ => μ Int64
- int64L :: Deserializer μ => μ Int64
- int64B :: Deserializer μ => μ Int64
- int64H :: Deserializer μ => μ Int64
- int :: Deserializer μ => μ Int
- intL :: Deserializer μ => μ Int
- intB :: Deserializer μ => μ Int
- intH :: Deserializer μ => μ Int
- module Text.Parser.Combinators
- label :: Parsing μ => String -> μ α -> μ α
- module Text.Parser.LookAhead
- newtype LittleEndianDeserializer μ α = LittleEndianDeserializer {
- deserializeL :: μ α
- newtype BigEndianDeserializer μ α = BigEndianDeserializer {
- deserializeB :: μ α
- deserializeIn :: Deserializer μ => Endian -> (forall μ'. Deserializer μ' => μ' α) -> μ α
- deserializeH :: Deserializer μ => (forall μ'. Deserializer μ' => μ' α) -> μ α
- data Deserialized α
- = Deserialized α
- | Malformed [String] String
- isDeserialized :: Deserialized α -> Bool
- isMalformed :: Deserialized α -> Bool
- maybeDeserialized :: Deserialized α -> Maybe α
- defaultDeserializer :: (forall μ. Deserializer μ => μ α) -> ByteString -> Deserialized α
- class Deserializable α where
- get :: Deserializer μ => μ α
- getIn :: (Deserializer μ, Deserializable α) => Endian -> μ α
- getL :: (Deserializer μ, Deserializable α) => μ α
- getB :: (Deserializer μ, Deserializable α) => μ α
- getH :: (Deserializer μ, Deserializable α) => μ α
- deserializeBytes :: Deserializable α => [Word8] -> Deserialized α
- deserializeBytesAs :: Deserializable α => p α -> [Word8] -> Deserialized α
- deserializeByteString :: Deserializable α => ByteString -> Deserialized α
- deserializeByteStringAs :: Deserializable α => p α -> ByteString -> Deserialized α
- deserializeLazyByteString :: Deserializable α => ByteString -> Deserialized α
- deserializeLazyByteStringAs :: Deserializable α => p α -> ByteString -> Deserialized α
- fromBytes :: Deserializable α => [Word8] -> Maybe α
- fromBytesAs :: Deserializable α => p α -> [Word8] -> Maybe α
- fromByteString :: Deserializable α => ByteString -> Maybe α
- fromByteStringAs :: Deserializable α => p α -> ByteString -> Maybe α
- fromLazyByteString :: Deserializable α => ByteString -> Maybe α
- fromLazyByteStringAs :: Deserializable α => p α -> ByteString -> Maybe α
- class RestDeserializable α where
- getRest :: Deserializer μ => μ α
Deserialization monad
class (Monad μ, Parsing μ) => Deserializer μ where Source #
Deserialization monad.
endian :: Proxy μ -> Endian Source #
Default byte order of the deserializer.
Deserialze a byte.
Deserialize an unsigned 16-bit integer in default byte order.
Deserialize an unsigned 32-bit integer in default byte order.
Deserialize an unsigned 64-bit integer in default byte order.
Deserialize an unsigned 16-bit integer in little endian.
Deserialize an unsigned 16-bit integer in big endian.
Deserialize an unsigned 32-bit integer in little endian.
Deserialize an unsigned 32-bit integer in big endian.
Deserialize an unsigned 64-bit integer in little endian.
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 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 #
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.
Instances
newtype BinaryDeserializer α Source #
A wrapper around the Get
monad (to avoid orphan instances).
Instances
newtype CerealDeserializer α Source #
A wrapper around the Get
monad (to avoid orphan instances).
Instances
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
module Text.Parser.Combinators
module Text.Parser.LookAhead
Endian deserializers
newtype LittleEndianDeserializer μ α Source #
Deserializer wrapper with little endian default byte order.
Instances
newtype BigEndianDeserializer μ α Source #
Deserializer wrapper with big endian default byte order.
Instances
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
isDeserialized :: Deserialized α -> Bool Source #
Map Deserialized
to True
and Malformed
to False
.
isMalformed :: Deserialized α -> Bool Source #
Map Deserialized
to False
and Malformed
to True
.
maybeDeserialized :: Deserialized α -> Maybe α Source #
Map Deserialized
values to Just
and Malformed
to Nothing
.
defaultDeserializer :: (forall μ. Deserializer μ => μ α) -> ByteString -> Deserialized α Source #
Deserialize a ByteString
via the default deserializer.
Deserializable types
class Deserializable α where Source #
get :: Deserializer μ => μ α Source #
Instances
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
.
fromBytes :: Deserializable α => [Word8] -> Maybe α Source #
A shorthand for
.maybeDeserialized
. deserializeBytes
fromBytesAs :: Deserializable α => p α -> [Word8] -> Maybe α Source #
Provide a hint for the type system when using fromBytes
fromByteString :: Deserializable α => ByteString -> Maybe α Source #
A shorthand for
.maybeDeserialized
. deserializeByteString
fromByteStringAs :: Deserializable α => p α -> ByteString -> Maybe α Source #
Provide a hint for the type system when using fromByteString
fromLazyByteString :: Deserializable α => ByteString -> Maybe α Source #
A shorthand for
.maybeDeserialized
. deserializeLazyByteString
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.
getRest :: Deserializer μ => μ α Source #
Instances
RestDeserializable ByteString Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ ByteString Source # | |
RestDeserializable ByteString Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ ByteString Source # | |
RestDeserializable ShortByteString Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ ShortByteString Source # | |
RestDeserializable Builder Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ Builder Source # | |
Deserializable α => RestDeserializable [α] Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ [α] Source # | |
(RestDeserializable α, RestDeserializable β) => RestDeserializable (Either α β) Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ (Either α β) Source # | |
(Deserializable α, RestDeserializable β) => RestDeserializable (α, β) Source # | |
Defined in Data.Deserializer getRest :: Deserializer μ => μ (α, β) Source # |