-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bit parsing/writing on top of binary. -- -- Bit parsing/writing on top of binary. Provides functions to read and -- write bits to and from 8/16/32/64 words. @package binary-bits @version 0.2 -- | Put bits easily. module Data.Binary.Bits.Put data BitPut a -- | Run the BitPut monad inside Put. runBitPut :: BitPut () -> Put -- | Run a Put inside BitPut. Any partially written bytes -- will be flushed before Put executes to ensure byte alignment. joinPut :: Put -> BitPut () -- | Put a 1 bit Bool. putBool :: Bool -> BitPut () -- | Put the n lower bits of a Word8. putWord8 :: Int -> Word8 -> BitPut () -- | Put the n lower bits of a Word16. putWord16be :: Int -> Word16 -> BitPut () -- | Put the n lower bits of a Word32. putWord32be :: Int -> Word32 -> BitPut () -- | Put the n lower bits of a Word64. putWord64be :: Int -> Word64 -> BitPut () -- | Put a ByteString. putByteString :: ByteString -> BitPut () instance Monad BitPut -- | Parse bits easily. Parsing can be done either in a monadic style, or -- more efficiently, using the Applicative style. -- -- For the monadic style, write your parser as a BitGet monad -- using the -- -- -- -- functions and run it with runBitGet. -- -- For the applicative style, compose the fuctions -- -- -- -- to make a Block. Use block to turn it into the -- BitGet monad to be able to run it with runBitGet. module Data.Binary.Bits.Get -- | BitGet is a monad, applicative and a functor. See -- runBitGet for how to run it. data BitGet a -- | Run a BitGet within the Binary packages Get monad. If a -- byte has been partially consumed it will be discarded once -- runBitGet is finished. runBitGet :: BitGet a -> Get a -- | Get 1 bit as a Bool. getBool :: BitGet Bool -- | Get n bits as a Word8. n must be within -- [0..8]. getWord8 :: Int -> BitGet Word8 -- | Get n bits as a Word16. n must be within -- [0..16]. getWord16be :: Int -> BitGet Word16 -- | Get n bits as a Word32. n must be within -- [0..32]. getWord32be :: Int -> BitGet Word32 -- | Get n bits as a Word64. n must be within -- [0..64]. getWord64be :: Int -> BitGet Word64 -- | A block that will be read with only one boundry check. Needs to know -- the number of bits in advance. data Block a -- | Get a block. Will be read with one single boundry check, and therefore -- requires a statically known number of bits. Build blocks using -- bool, word8, word16be, word32be, -- word64be, byteString and Applicative. block :: Block a -> BitGet a -- | Read a 1 bit Bool. bool :: Block Bool -- | Read n bits as a Word8. n must be within -- [0..8]. word8 :: Int -> Block Word8 -- | Read n bits as a Word16. n must be within -- [0..16]. word16be :: Int -> Block Word16 -- | Read n bits as a Word32. n must be within -- [0..32]. word32be :: Int -> Block Word32 -- | Read n bits as a Word64. n must be within -- [0..64]. word64be :: Int -> Block Word64 -- | Read n bytes as a ByteString. byteString :: Int -> Block ByteString -- | Get n bytes as a ByteString. getByteString :: Int -> BitGet ByteString instance Show S instance Applicative BitGet instance Functor BitGet instance Monad BitGet instance Applicative Block instance Functor Block -- | Parse and write bits easily. Parsing can be done either in a monadic -- style, or more efficiently, using the Applicative style. -- Writing is monadic style only. See Data.Binary.Bits.Get and -- Data.Binary.Bits.Put, respectively. module Data.Binary.Bits class BinaryBit a putBits :: BinaryBit a => Int -> a -> BitPut () getBits :: BinaryBit a => Int -> BitGet a instance BinaryBit Word64 instance BinaryBit Word32 instance BinaryBit Word16 instance BinaryBit Word8 instance BinaryBit Bool