bits-0.4: Various bit twiddling and bitwise serialization primitives

Copyright(c) Edward Kmett 2013
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Bits.Coding

Contents

Description

 

Synopsis

Documentation

newtype Coding m a Source

Constructors

Coding 

Fields

runCoding :: forall r. (a -> Int -> Word8 -> m r) -> Int -> Word8 -> m r
 

Get

getAligned :: MonadGet m => m a -> Coding m a Source

Get something from byte-aligned storage, starting on the next byte and discarding any left over bits in the buffer.

NB: Using any operation from MonadGet other than checking remaining or isEmpty will implicitly perform this operation.

getBit :: MonadGet m => Coding m Bool Source

Get a single bit, consuming an entire byte if the bit buffer is empty

getBits :: (MonadGet m, Bits b) => Int -> Int -> b -> Coding m b Source

getBitsFrom :: (MonadGet m, Bits b) => Int -> b -> Coding m b Source

Put

putAligned :: MonadPut m => m a -> Coding m a Source

Emit any remaining contents from the bit buffer.

Any use of the combinators from MonadPut (including flush) will cause this to happen.

putUnaligned :: (MonadPut m, FiniteBits b) => b -> Coding m () Source

Put all the bits without a flush

putBit :: MonadPut m => Bool -> Coding m () Source

Put a single bit, emitting an entire byte if the bit buffer is full

putBits :: (MonadPut m, Bits b) => Int -> Int -> b -> Coding m () Source

Put a (closed) range of bits

putBitsFrom :: (MonadPut m, Bits b) => Int -> b -> Coding m () Source

putBitsFrom from b = putBits from 0 b