binary-strict-0.4.8.6: Binary deserialisation using strict ByteStrings

CopyrightDominic Steinitz
LicenseBSD3-style (see LICENSE)
MaintainerDominic Steinitz <dominic.steinitz@blueyonder.co.uk>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.Binary.BitPut

Description

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.

Synopsis

Documentation

data BitPutM a Source #

Instances
Monad BitPutM Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

(>>=) :: BitPutM a -> (a -> BitPutM b) -> BitPutM b #

(>>) :: BitPutM a -> BitPutM b -> BitPutM b #

return :: a -> BitPutM a #

fail :: String -> BitPutM a #

Functor BitPutM Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

fmap :: (a -> b) -> BitPutM a -> BitPutM b #

(<$) :: a -> BitPutM b -> BitPutM a #

Applicative BitPutM Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

pure :: a -> BitPutM a #

(<*>) :: BitPutM (a -> b) -> BitPutM a -> BitPutM b #

liftA2 :: (a -> b -> c) -> BitPutM a -> BitPutM b -> BitPutM c #

(*>) :: BitPutM a -> BitPutM b -> BitPutM b #

(<*) :: BitPutM a -> BitPutM b -> BitPutM a #

data BitPutT m a Source #

Instances
MonadTrans BitPutT Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

lift :: Monad m => m a -> BitPutT m a #

MonadError e m => MonadError e (BitPutT m) Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

throwError :: e -> BitPutT m a #

catchError :: BitPutT m a -> (e -> BitPutT m a) -> BitPutT m a #

Monad m => Monad (BitPutT m) Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

(>>=) :: BitPutT m a -> (a -> BitPutT m b) -> BitPutT m b #

(>>) :: BitPutT m a -> BitPutT m b -> BitPutT m b #

return :: a -> BitPutT m a #

fail :: String -> BitPutT m a #

Monad m => Functor (BitPutT m) Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

fmap :: (a -> b) -> BitPutT m a -> BitPutT m b #

(<$) :: a -> BitPutT m b -> BitPutT m a #

Monad m => Applicative (BitPutT m) Source # 
Instance details

Defined in Data.Binary.BitPut

Methods

pure :: a -> BitPutT m a #

(<*>) :: BitPutT m (a -> b) -> BitPutT m a -> BitPutT m b #

liftA2 :: (a -> b -> c) -> BitPutT m a -> BitPutT m b -> BitPutT m c #

(*>) :: BitPutT m a -> BitPutT m b -> BitPutT m b #

(<*) :: BitPutT m a -> BitPutT m b -> BitPutT m a #

runBitPutT :: Monad m => BitPutT m a -> m (a, ByteString) Source #

putBit :: Bool -> BitPut Source #

Append a single bit

putBitT :: Monad m => Bool -> BitPutT m () Source #

putNBits :: (Integral a, Bits a) => Int -> a -> BitPut Source #

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.

putNBitsT :: (Monad m, Integral a, Bits a) => Int -> a -> BitPutT m () Source #

putBits :: (Integral a, Bits a) => a -> BitPut Source #

Append a value. Note that this function is undefined for instances of Bits which have no fixed bitsize (like Integer)

putByteString :: ByteString -> BitPut Source #

Append a ByteString

putLeftByteString :: (ByteString, Int) -> BitPut Source #

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)