HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleblaze-builder-0.4.4.1Haskell98

Blaze.ByteString.Builder.Word

Writes and Builders 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.

Contents
  1. Writing words to a buffer
  2. Big-endian writes
  3. Little-endian writes
  4. Host-endian writes
  5. Creating builders from words
  6. Big-endian serialization
  7. Little-endian serialization
  8. Host-endian serialization
Synopsis

Writing words to a buffer

Big-endian writes

Little-endian writes

Host-endian writes

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.

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.

Big-endian serialization

Little-endian serialization

Host-endian serialization

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.