Stability | experimental |
---|---|
Maintainer | Dominic Steinitz <dominic.steinitz@blueyonder.co.uk> |
This is the writer dual to BitGet. It allows one to append bits in a monad and get a strict ByteString as a result. Bits are appended from the MSB of the first byte towards the LSB of the last byte.
This is best suited to small bit-fields because it accumulates bytes using snoc, so large results will cause a lot of copying. It would be possible to switch to using something similar to the Builder monad if need arises. However, since most protocols only have small bit fields, this should suffice for many cases.
- type BitPut = BitPutM ()
- data BitPutM a
- data BitPutT m a
- runBitPut :: BitPut -> ByteString
- runBitPutM :: BitPutM a -> (a, ByteString)
- runBitPutT :: Monad m => BitPutT m a -> m (a, ByteString)
- putBit :: Bool -> BitPut
- putBitT :: Monad m => Bool -> BitPutT m ()
- putNBits :: (Integral a, Bits a) => Int -> a -> BitPut
- putNBitsT :: (Monad m, Integral a, Bits a) => Int -> a -> BitPutT m ()
- putBits :: (Integral a, Bits a) => a -> BitPut
- putByteString :: ByteString -> BitPut
- putLeftByteString :: (ByteString, Int) -> BitPut
Documentation
MonadTrans BitPutT | |
MonadError e m => MonadError e (BitPutT m) | |
Monad m => Monad (BitPutT m) | |
Monad m => Functor (BitPutT m) |
runBitPut :: BitPut -> ByteStringSource
runBitPutM :: BitPutM a -> (a, ByteString)Source
runBitPutT :: Monad m => BitPutT m a -> m (a, ByteString)Source
putNBits :: (Integral a, Bits a) => Int -> a -> BitPutSource
Append the bottom n bits of the given bits value. In the case that more bits are requested than the value provides, this acts as if the value has as unlimited number of leading 0 bits.
putBits :: (Integral a, Bits a) => a -> BitPutSource
Append a value. Note that this function is undefined for instances of Bits which have no fixed bitsize (like Integer)
putByteString :: ByteString -> BitPutSource
Append a ByteString
putLeftByteString :: (ByteString, Int) -> BitPutSource
Append a left aligned ByteString where ByteString has a partial byte with the given number of valid bits, from the MSB downwards. The number of such bits must be 0..7. (A normal ByteString, which all bytes full would use 0)