blaze-builder-0.3.1.1: Efficient buffered output.

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

Blaze.ByteString.Builder.Word

Contents

- Writing words to a buffer
  - Big-endian writes
  - Little-endian writes
  - Host-endian writes
- Creating builders from words
  - Big-endian serialization
  - Little-endian serialization
  - Host-endian serialization

Description

`Write`s and `Builder`s for serializing words.

Note that for serializing a three tuple `(x,y,z)` of bytes (or other word values) you should use the expression

     fromWrite $ writeWord8 x `mappend` writeWord8 y `mappend` writeWord z

instead of

     fromWord8 x `mappend` fromWord8 y `mappend` fromWord z

The first expression will result in a single atomic write of three bytes, while the second expression will check for each byte, if there is free space left in the output buffer. Coalescing these checks can improve performance quite a bit, as long as you use it sensibly.

Synopsis

- writeWord8 :: Word8 -> Write
- writeWord16be :: Word16 -> Write
- writeWord32be :: Word32 -> Write
- writeWord64be :: Word64 -> Write
- writeWord16le :: Word16 -> Write
- writeWord32le :: Word32 -> Write
- writeWord64le :: Word64 -> Write
- writeWordhost :: Word -> Write
- writeWord16host :: Word16 -> Write
- writeWord32host :: Word32 -> Write
- writeWord64host :: Word64 -> Write
- fromWord8 :: Word8 -> Builder
- fromWord8s :: [Word8] -> Builder
- fromWord16be :: Word16 -> Builder
- fromWord32be :: Word32 -> Builder
- fromWord64be :: Word64 -> Builder
- fromWord32sbe :: [Word32] -> Builder
- fromWord16sbe :: [Word16] -> Builder
- fromWord64sbe :: [Word64] -> Builder
- fromWord16le :: Word16 -> Builder
- fromWord32le :: Word32 -> Builder
- fromWord64le :: Word64 -> Builder
- fromWord16sle :: [Word16] -> Builder
- fromWord32sle :: [Word32] -> Builder
- fromWord64sle :: [Word64] -> Builder
- fromWordhost :: Word -> Builder
- fromWord16host :: Word16 -> Builder
- fromWord32host :: Word32 -> Builder
- fromWord64host :: Word64 -> Builder
- fromWordshost :: [Word] -> Builder
- fromWord16shost :: [Word16] -> Builder
- fromWord32shost :: [Word32] -> Builder
- fromWord64shost :: [Word64] -> Builder

# Writing words to a buffer

writeWord8 :: Word8 -> Write

Write a single byte.

## Big-endian writes

writeWord16be :: Word16 -> Write

Write a `Word16` in big endian format.

writeWord32be :: Word32 -> Write

Write a `Word32` in big endian format.

writeWord64be :: Word64 -> Write

Write a `Word64` in big endian format.

## Little-endian writes

writeWord16le :: Word16 -> Write

Write a `Word16` in little endian format.

writeWord32le :: Word32 -> Write

Write a `Word32` in little endian format.

writeWord64le :: Word64 -> Write

Write a `Word64` in little endian format.

## Host-endian writes

writeWordhost :: Word -> Write

Write a single native machine `Word`. The `Word` is written in host order, host endian form, for the machine you're on. On a 64 bit machine the `Word` is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or word sized machines, without conversion.

writeWord16host :: Word16 -> Write

Write a `Word16` in native host order and host endianness.

writeWord32host :: Word32 -> Write

Write a `Word32` in native host order and host endianness.

writeWord64host :: Word64 -> Write

Write a `Word64` in native host order and host endianness.

# Creating builders from words

We provide serialization functions both for singleton words as well as for lists of words. Using these list serialization functions is much faster than using `mconcat . map fromWord<n>`, as the list serialization functions use a tighter inner loop.

fromWord8 :: Word8 -> Builder

Serialize a single byte.

fromWord8s :: [Word8] -> Builder

Serialize a list of bytes.

## Big-endian serialization

fromWord16be :: Word16 -> Builder

Serialize a `Word16` in big endian format.

fromWord32be :: Word32 -> Builder

Serialize a `Word32` in big endian format.

fromWord64be :: Word64 -> Builder

Serialize a `Word64` in big endian format.

fromWord32sbe :: [Word32] -> Builder

Serialize a list of `Word32`s in big endian format.

fromWord16sbe :: [Word16] -> Builder

Serialize a list of `Word16`s in big endian format.

fromWord64sbe :: [Word64] -> Builder

Serialize a list of `Word64`s in big endian format.

## Little-endian serialization

fromWord16le :: Word16 -> Builder

Serialize a `Word16` in little endian format.

fromWord32le :: Word32 -> Builder

Serialize a `Word32` in little endian format.

fromWord64le :: Word64 -> Builder

Serialize a `Word64` in little endian format.

fromWord16sle :: [Word16] -> Builder

Serialize a list of `Word16`s in little endian format.

fromWord32sle :: [Word32] -> Builder

Serialize a list of `Word32`s in little endian format.

fromWord64sle :: [Word64] -> Builder

Serialize a list of `Word64`s in little endian format.

## Host-endian serialization

fromWordhost :: Word -> Builder

Serialize a single native machine `Word`. The `Word` is serialized in host order, host endian form, for the machine you're on. On a 64 bit machine the `Word` is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or word sized machines, without conversion.

fromWord16host :: Word16 -> Builder

Write a `Word16` in native host order and host endianness.

fromWord32host :: Word32 -> Builder

Write a `Word32` in native host order and host endianness.

fromWord64host :: Word64 -> Builder

Write a `Word64` in native host order and host endianness.

fromWordshost :: [Word] -> Builder

Serialize a list of `Word`s. See `fromWordhost` for usage considerations.

fromWord16shost :: [Word16] -> Builder

Write a list of `Word16`s in native host order and host endianness.

fromWord32shost :: [Word32] -> Builder

Write a list of `Word32`s in native host order and host endianness.

fromWord64shost :: [Word64] -> Builder

Write a list of `Word64`s in native host order and host endianness.