-- 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.5


-- | Put bits easily.
module Data.Binary.Bits.Put
data BitPut a

-- | Run the <a>BitPut</a> monad inside <a>Put</a>.
runBitPut :: BitPut () -> Put

-- | Run a <a>Put</a> inside <a>BitPut</a>. Any partially written bytes
--   will be flushed before <a>Put</a> executes to ensure byte alignment.
joinPut :: Put -> BitPut ()

-- | Put a 1 bit <a>Bool</a>.
putBool :: Bool -> BitPut ()

-- | Put the <tt>n</tt> lower bits of a <a>Word8</a>.
putWord8 :: Int -> Word8 -> BitPut ()

-- | Put the <tt>n</tt> lower bits of a <a>Word16</a>.
putWord16be :: Int -> Word16 -> BitPut ()

-- | Put the <tt>n</tt> lower bits of a <a>Word32</a>.
putWord32be :: Int -> Word32 -> BitPut ()

-- | Put the <tt>n</tt> lower bits of a <a>Word64</a>.
putWord64be :: Int -> Word64 -> BitPut ()

-- | Put a <a>ByteString</a>.
putByteString :: ByteString -> BitPut ()
instance GHC.Base.Functor Data.Binary.Bits.Put.BitPut
instance GHC.Base.Applicative Data.Binary.Bits.Put.BitPut
instance GHC.Base.Monad Data.Binary.Bits.Put.BitPut


-- | Parse bits easily. Parsing can be done either in a monadic style, or
--   more efficiently, using the <a>Applicative</a> style.
--   
--   For the monadic style, write your parser as a <a>BitGet</a> monad
--   using the
--   
--   <ul>
--   <li><a>getBool</a></li>
--   <li><a>getWord8</a></li>
--   <li><a>getWord16be</a></li>
--   <li><a>getWord32be</a></li>
--   <li><a>getWord64be</a></li>
--   <li><a>getByteString</a></li>
--   </ul>
--   
--   functions and run it with <a>runBitGet</a>.
--   
--   For the applicative style, compose the fuctions
--   
--   <ul>
--   <li><a>bool</a></li>
--   <li><a>word8</a></li>
--   <li><a>word16be</a></li>
--   <li><a>word32be</a></li>
--   <li><a>word64be</a></li>
--   <li><a>byteString</a></li>
--   </ul>
--   
--   to make a <a>Block</a>. Use <a>block</a> to turn it into the
--   <a>BitGet</a> monad to be able to run it with <a>runBitGet</a>.
module Data.Binary.Bits.Get

-- | <a>BitGet</a> is a monad, applicative and a functor. See
--   <a>runBitGet</a> for how to run it.
data BitGet a

-- | Run a <a>BitGet</a> within the Binary packages <a>Get</a> monad. If a
--   byte has been partially consumed it will be discarded once
--   <a>runBitGet</a> is finished.
runBitGet :: BitGet a -> Get a

-- | Get 1 bit as a <a>Bool</a>.
getBool :: BitGet Bool

-- | Get <tt>n</tt> bits as a <a>Word8</a>. <tt>n</tt> must be within
--   <tt>[0..8]</tt>.
getWord8 :: Int -> BitGet Word8

-- | Get <tt>n</tt> bits as a <a>Word16</a>. <tt>n</tt> must be within
--   <tt>[0..16]</tt>.
getWord16be :: Int -> BitGet Word16

-- | Get <tt>n</tt> bits as a <a>Word32</a>. <tt>n</tt> must be within
--   <tt>[0..32]</tt>.
getWord32be :: Int -> BitGet Word32

-- | Get <tt>n</tt> bits as a <a>Word64</a>. <tt>n</tt> must be within
--   <tt>[0..64]</tt>.
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
--   <a>bool</a>, <a>word8</a>, <a>word16be</a>, <a>word32be</a>,
--   <a>word64be</a>, <a>byteString</a> and <a>Applicative</a>.
block :: Block a -> BitGet a

-- | Read a 1 bit <a>Bool</a>.
bool :: Block Bool

-- | Read <tt>n</tt> bits as a <a>Word8</a>. <tt>n</tt> must be within
--   <tt>[0..8]</tt>.
word8 :: Int -> Block Word8

-- | Read <tt>n</tt> bits as a <a>Word16</a>. <tt>n</tt> must be within
--   <tt>[0..16]</tt>.
word16be :: Int -> Block Word16

-- | Read <tt>n</tt> bits as a <a>Word32</a>. <tt>n</tt> must be within
--   <tt>[0..32]</tt>.
word32be :: Int -> Block Word32

-- | Read <tt>n</tt> bits as a <a>Word64</a>. <tt>n</tt> must be within
--   <tt>[0..64]</tt>.
word64be :: Int -> Block Word64

-- | Read <tt>n</tt> bytes as a <a>ByteString</a>.
byteString :: Int -> Block ByteString

-- | Get <tt>n</tt> bytes as a <a>ByteString</a>.
getByteString :: Int -> BitGet ByteString

-- | Get <tt>n</tt> bytes as a lazy ByteString.
getLazyByteString :: Int -> BitGet ByteString

-- | Test whether all input has been consumed, i.e. there are no remaining
--   undecoded bytes.
isEmpty :: BitGet Bool
instance GHC.Show.Show Data.Binary.Bits.Get.S
instance GHC.Base.Functor Data.Binary.Bits.Get.Block
instance GHC.Base.Applicative Data.Binary.Bits.Get.Block
instance GHC.Base.Monad Data.Binary.Bits.Get.BitGet
instance GHC.Base.Functor Data.Binary.Bits.Get.BitGet
instance GHC.Base.Applicative Data.Binary.Bits.Get.BitGet


-- | Parse and write bits easily. Parsing can be done either in a monadic
--   style, or more efficiently, using the <a>Applicative</a> style.
--   Writing is monadic style only. See <a>Data.Binary.Bits.Get</a> and
--   <a>Data.Binary.Bits.Put</a>, respectively.
module Data.Binary.Bits
class BinaryBit a
putBits :: BinaryBit a => Int -> a -> BitPut ()
getBits :: BinaryBit a => Int -> BitGet a
instance Data.Binary.Bits.BinaryBit GHC.Types.Bool
instance Data.Binary.Bits.BinaryBit GHC.Word.Word8
instance Data.Binary.Bits.BinaryBit GHC.Word.Word16
instance Data.Binary.Bits.BinaryBit GHC.Word.Word32
instance Data.Binary.Bits.BinaryBit GHC.Word.Word64
