| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Morley.Util.Binary
Description
This module contains helper functions to deal with encoding and decoding of binary data.
Synopsis
- newtype UnpackError = UnpackError {}
- ensureEnd :: Get ()
- launchGet :: Get a -> LByteString -> Either UnpackError a
- type TaggedDecoder a = TaggedDecoderM IdentityT a
- data TaggedDecoderM t a = TaggedDecoder {}
- (#:) :: Word8 -> Get a -> TaggedDecoder a
- (##:) :: Word8 -> t Get a -> TaggedDecoderM t a
- decodeBytesLike :: Buildable err => String -> (ByteString -> Either err a) -> Get a
- decodeWithTag :: String -> [TaggedDecoder a] -> Get a
- decodeWithTagM :: (MonadTrans t, Monad (t Get)) => String -> (Word8 -> t Get a) -> [TaggedDecoderM t a] -> t Get a
- getByteStringCopy :: Int -> Get ByteString
- getRemainingByteStringCopy :: Get ByteString
- unknownTag :: String -> Word8 -> Get a
Documentation
newtype UnpackError Source #
Any decoding error.
Constructors
| UnpackError | |
Fields | |
Instances
| Exception UnpackError Source # | |
Defined in Morley.Util.Binary Methods toException :: UnpackError -> SomeException # fromException :: SomeException -> Maybe UnpackError # displayException :: UnpackError -> String # | |
| Show UnpackError Source # | |
Defined in Morley.Util.Binary Methods showsPrec :: Int -> UnpackError -> ShowS # show :: UnpackError -> String # showList :: [UnpackError] -> ShowS # | |
| Eq UnpackError Source # | |
Defined in Morley.Util.Binary | |
| Buildable UnpackError Source # | |
Defined in Morley.Util.Binary | |
launchGet :: Get a -> LByteString -> Either UnpackError a Source #
type TaggedDecoder a = TaggedDecoderM IdentityT a Source #
Specialization of TaggedDecoderM to IdentityT transformer.
data TaggedDecoderM t a Source #
Describes how decodeWithTagM should decode tag-dependent data.
We expect bytes of such structure: tdTag followed by a bytestring
which will be parsed with tdDecoder.
Constructors
| TaggedDecoder | |
(#:) :: Word8 -> Get a -> TaggedDecoder a infixr 0 Source #
Alias for TaggedDecoder constructor specialized to Get
(##:) :: Word8 -> t Get a -> TaggedDecoderM t a infixr 0 Source #
Alias for TaggedDecoder constructor.
decodeBytesLike :: Buildable err => String -> (ByteString -> Either err a) -> Get a Source #
decodeWithTag :: String -> [TaggedDecoder a] -> Get a Source #
Common decoder for the case when packed data starts with a tag (1 byte) that specifies how to decode remaining data.
This is a version of decodeWithTagM specialized to naked Get monad.
decodeWithTagM :: (MonadTrans t, Monad (t Get)) => String -> (Word8 -> t Get a) -> [TaggedDecoderM t a] -> t Get a Source #
Common decoder for the case when packed data starts with a tag (1 byte) that specifies how to decode remaining data.
This is a general version of decodeWithTag that allows Get to be wrapped
in a monad transformer.
getByteStringCopy :: Int -> Get ByteString Source #
Get a bytestring of the given length leaving no references to the original data in serialized form.
getRemainingByteStringCopy :: Get ByteString Source #
Get remaining available bytes.
Note that reading all remaining decoded input may be expensive and is thus
discouraged, use can use this function only when you know that amount
of data to be consumed is limited, e.g. within decodeBytesLike call.