Copyright | Adam Langley |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | Adam Langley <agl@imperialviolet.org> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This is a reader monad for parsing bit-aligned data. The usual Get monad handles byte aligned data well.
In this monad, the current offset into the input is a number of bits, and
fetching n bits from the current position will shift everything correctly.
Bit vectors are represented as ByteStrings here either the first n
bits
are valid (left aligned) or the last n
bits are (right aligned).
If one is looking to parse integers etc, right alignment is the easist to work with, however left alignment makes more sense in some situations.
Synopsis
- data BitGet a
- runBitGet :: ByteString -> BitGet a -> Either String a
- skip :: Int -> BitGet ()
- remaining :: BitGet Int
- isEmpty :: BitGet Bool
- lookAhead :: BitGet a -> BitGet a
- getBit :: BitGet Bool
- getLeftByteString :: Int -> BitGet ByteString
- getRightByteString :: Int -> BitGet ByteString
- getAsWord8 :: Int -> BitGet Word8
- getAsWord16 :: Int -> BitGet Word16
- getAsWord32 :: Int -> BitGet Word32
- getAsWord64 :: Int -> BitGet Word64
- getAsInt8 :: Int -> BitGet Int8
- getAsInt16 :: Int -> BitGet Int16
- getAsInt32 :: Int -> BitGet Int32
- getAsInt64 :: Int -> BitGet Int64
- getWord8 :: BitGet Word8
- getWord16le :: BitGet Word16
- getWord16be :: BitGet Word16
- getWord16host :: BitGet Word16
- getWord32le :: BitGet Word32
- getWord32be :: BitGet Word32
- getWord32host :: BitGet Word32
- getWord64le :: BitGet Word64
- getWord64be :: BitGet Word64
- getWord64host :: BitGet Word64
- getWordhost :: BitGet Word
Get BitGet
type
Utility
lookAhead :: BitGet a -> BitGet a Source #
Run ga
, but return without consuming its input.
Fails if ga
fails.
Generic parsing
getLeftByteString :: Int -> BitGet ByteString Source #
Get a ByteString with the given number of bits, left aligned.
getRightByteString :: Int -> BitGet ByteString Source #
Get a ByteString with the given number of bits in, right aligned.
Interpreting some number of bits as an unsigned integer
Interpreting some number of bits as a signed integer
getAsInt8 :: Int -> BitGet Int8 Source #
Reads an Int8
, sign-extending the input if it has
fewer than 8 bits.
getAsInt16 :: Int -> BitGet Int16 Source #
Reads an Int16
in big endian format, sign-extending the input if it has
fewer than 16 bits.
getAsInt32 :: Int -> BitGet Int32 Source #
Reads an Int32
in big endian format, sign-extending the input if it has
fewer than 32 bits.
getAsInt64 :: Int -> BitGet Int64 Source #
Reads an Int64
in big endian format, sign-extending the input if it has
fewer than 64 bits.
Parsing particular types
getWordhost :: BitGet Word Source #