Bounded package:bytestring

A builder primitive that always results in sequence of bytes that is no longer than a pre-determined bound.
Lift a FixedPrim to a BoundedPrim.
Create a Builder that encodes values with the given BoundedPrim. We rewrite consecutive uses of primBounded such that the bound-checks are fused. For example,
primBounded (word32 c1) `mappend` primBounded (word32 c2)
is rewritten such that the resulting Builder checks only once, if ther are at 8 free bytes, instead of checking twice, if there are 4 free bytes. This optimization is not observationally equivalent in a strict sense, as it influences the boundaries of the generated chunks. However, for a user of this library it is observationally equivalent, as chunk boundaries of a LazyByteString can only be observed through the internal interface. Moreover, we expect that all primitives write much fewer than 4kb (the default short buffer size). Hence, it is safe to ignore the additional memory spilled due to the more aggressive buffer wrapping introduced by this optimization.
Create a Builder that encodes each Word8 of a StrictByteString using a BoundedPrim. For example, we can write a Builder that filters a StrictByteString as follows.
import qualified Data.ByteString.Builder.Prim as P
filterBS p = P.condB p (P.liftFixedToBounded P.word8) P.emptyB
Chunk-wise application of primMapByteStringBounded.
Create a Builder that encodes a list of values consecutively using a BoundedPrim for each element. This function is more efficient than
mconcat . map (primBounded w)
or
foldMap (primBounded w)
because it moves several variables out of the inner loop.
Create a Builder that encodes a sequence generated from a seed value using a BoundedPrim for each sequence element.