Portability | portable to Hugs and GHC. |
---|---|
Stability | experimental |
Maintainer | Lennart Kolmodin <kolmodin@dtek.chalmers.se> |
The Get monad. A monad for efficiently building structures from encoded lazy ByteStrings
- data Get a
- runGet :: Get a -> ByteString -> a
- runGetState :: Get a -> ByteString -> Int64 -> (a, ByteString, Int64)
- skip :: Int -> Get ()
- uncheckedSkip :: Int64 -> Get ()
- lookAhead :: Get a -> Get a
- lookAheadM :: Get (Maybe a) -> Get (Maybe a)
- lookAheadE :: Get (Either a b) -> Get (Either a b)
- uncheckedLookAhead :: Int64 -> Get ByteString
- bytesRead :: Get Int64
- getBytes :: Int -> Get ByteString
- remaining :: Get Int64
- isEmpty :: Get Bool
- getWord8 :: Get Word8
- getByteString :: Int -> Get ByteString
- getLazyByteString :: Int64 -> Get ByteString
- getLazyByteStringNul :: Get ByteString
- getRemainingLazyByteString :: Get ByteString
- getWord16be :: Get Word16
- getWord32be :: Get Word32
- getWord64be :: Get Word64
- getWord16le :: Get Word16
- getWord32le :: Get Word32
- getWord64le :: Get Word64
- getWordhost :: Get Word
- getWord16host :: Get Word16
- getWord32host :: Get Word32
- getWord64host :: Get Word64
The Get type
The Get monad is just a State monad carrying around the input ByteString
runGet :: Get a -> ByteString -> aSource
Run the Get monad applies a get
-based parser on the input ByteString
runGetState :: Get a -> ByteString -> Int64 -> (a, ByteString, Int64)Source
Run the Get monad applies a get
-based parser on the input
ByteString. Additional to the result of get it returns the number of
consumed bytes and the rest of the input.
Parsing
uncheckedSkip :: Int64 -> Get ()Source
Skip ahead n
bytes. No error if there isn't enough bytes.
lookAheadM :: Get (Maybe a) -> Get (Maybe a)Source
Like lookAhead
, but consume the input if gma
returns 'Just _'.
Fails if gma
fails.
lookAheadE :: Get (Either a b) -> Get (Either a b)Source
Like lookAhead
, but consume the input if gea
returns 'Right _'.
Fails if gea
fails.
uncheckedLookAhead :: Int64 -> Get ByteStringSource
Get the next up to n
bytes as a lazy ByteString, without consuming them.
Utility
getBytes :: Int -> Get ByteStringSource
Pull n
bytes from the input, as a strict ByteString.
important
Get the number of remaining unparsed bytes. Useful for checking whether all input has been consumed. Note that this forces the rest of the input.
Test whether all input has been consumed, i.e. there are no remaining unparsed bytes.
Parsing particular types
ByteStrings
getByteString :: Int -> Get ByteStringSource
An efficient get
method for strict ByteStrings. Fails if fewer
than n
bytes are left in the input.
getLazyByteString :: Int64 -> Get ByteStringSource
An efficient get
method for lazy ByteStrings. Does not fail if fewer than
n
bytes are left in the input.
getLazyByteStringNul :: Get ByteStringSource
Get a lazy ByteString that is terminated with a NUL byte. Fails if it reaches the end of input without hitting a NUL.
getRemainingLazyByteString :: Get ByteStringSource
Get the remaining bytes as a lazy ByteString
Big-endian reads
getWord16be :: Get Word16Source
Read a Word16 in big endian format
getWord32be :: Get Word32Source
Read a Word32 in big endian format
getWord64be :: Get Word64Source
Read a Word64 in big endian format
Little-endian reads
getWord16le :: Get Word16Source
Read a Word16 in little endian format
getWord32le :: Get Word32Source
Read a Word32 in little endian format
getWord64le :: Get Word64Source
Read a Word64 in little endian format
Host-endian, unaligned reads
O(1). Read a single native machine word. The word is read in host order, host endian form, for the machine you're on. On a 64 bit machine the Word is an 8 byte value, on a 32 bit machine, 4 bytes.
getWord16host :: Get Word16Source
O(1). Read a 2 byte Word16 in native host order and host endianness.
getWord32host :: Get Word32Source
O(1). Read a Word32 in native host order and host endianness.
getWord64host :: Get Word64Source
O(1). Read a Word64 in native host order and host endianess.