Blaze.ByteString.Builder.Internal.Write

blaze-builder-0.2.1.4: Efficient buffered output.

Portability | tested on GHC only
Stability | experimental
Maintainer | Simon Meier <iridcode@gmail.com>
Safe Haskell | None

Blaze.ByteString.Builder.Internal.Write

Contents

- Abstracting writes to a buffer
- Constructing builders from writes
- Writing `Storable`s

Description

A general and efficient write type that allows for the easy construction of builders for (smallish) bounded size writes to a buffer.

Synopsis

- data Write
- data WriteIO
- writeN :: Int -> (Ptr Word8 -> IO ()) -> WriteIO
- exactWrite :: Int -> (Ptr Word8 -> IO ()) -> Write
- boundedWrite :: Int -> WriteIO -> Write
- runWrite :: Write -> WriteIO
- runWriteIO :: WriteIO -> Ptr Word8 -> IO (Ptr Word8)
- fromWrite :: Write -> Builder
- fromWriteSingleton :: (a -> Write) -> a -> Builder
- fromWriteList :: (a -> Write) -> [a] -> Builder
- writeStorable :: Storable a => a -> Write
- fromStorable :: Storable a => a -> Builder
- fromStorables :: Storable a => [a] -> Builder

# Abstracting writes to a buffer

data Write

A write of a bounded number of bytes.

Instances

Monoid Write |

data WriteIO

A write to a buffer.

FIXME: Find better name: what about `Poke` ?

Instances

Monoid WriteIO |

writeN :: Int -> (Ptr Word8 -> IO ()) -> WriteIO

`writeN size io` creates a write that denotes the writing of `size` bytes to a buffer using the IO action `io`. Note that `io` MUST write EXACTLY `size` bytes to the buffer!

exactWrite :: Int -> (Ptr Word8 -> IO ()) -> Write

`exactWrite size io` creates a bounded write that can later be converted to a builder that writes exactly `size` bytes. Note that `io` MUST write EXACTLY `size` bytes to the buffer!

boundedWrite :: Int -> WriteIO -> Write

`boundedWrite size write` creates a bounded write from a `write` that does not write more than `size` bytes.

runWrite :: Write -> WriteIO

Extract the `WriteIO` action of a write.

runWriteIO :: WriteIO -> Ptr Word8 -> IO (Ptr Word8)

# Constructing builders from writes

fromWrite :: Write -> Builder

fromWriteSingleton :: (a -> Write) -> a -> Builder

fromWriteList :: (a -> Write) -> [a] -> Builder

Construct a `Builder` writing a list of data one element at a time.

# Writing `Storable`s

writeStorable :: Storable a => a -> Write

Write a storable value.

fromStorable :: Storable a => a -> Builder

A builder that serializes a storable value. No alignment is done.

fromStorables :: Storable a => [a] -> Builder

A builder that serializes a list of storable values by writing them consecutively. No alignment is done. Parsing information needs to be provided externally.