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

Types

newtypenewtype Builder

An unmaterialized sequence of bytes that may be pasted into a mutable byte array.

Constructors

Instances4IsString, Semigroup, Monoid, ToBuilder
  • IsString BuilderDefined in bytebuild-0.3.17.0 · Data.Bytes.Builder.Unsafe
  • Semigroup BuilderDefined in bytebuild-0.3.17.0 · Data.Bytes.Builder.Unsafe
  • Monoid BuilderDefined in bytebuild-0.3.17.0 · Data.Bytes.Builder.Unsafe
  • ToBuilder BuilderDefined in bytebuild-0.3.17.0 · Data.Bytes.Builder.Class

    Identity

Execution

Run a builder, performing an in-place update on the state. The BuilderState argument must not be reused after being passed to this function. That is, its use must be affine.

Construction

valuefromEffect
  1. :: Int

    Maximum number of bytes the paste function needs

  2. -> (forall s. MutableByteArray s -> Int -> ST s Int)

    Paste function. Takes a byte array and an offset and returns the new offset and having pasted into the buffer.

  3. -> Builder
#

Builder State

Push the active chunk onto the top of the commits. The BuilderState argument must not be reused after being passed to this function. That is, its use must be affine.

Finalization

Cons the chunks from a list of Commits onto an initial Chunks list (this argument is often ChunksNil). This reverses the order of the chunks, which is desirable since builders assemble Commits with the chunks backwards. This performs an in-place shrink and freezes any mutable byte arrays it encounters. Consequently, these must not be reused.

valuecopyReverseCommits
  1. :: MutableByteArray s

    Destination

  2. -> Int

    Destination range successor

  3. -> Commits s

    Source

  4. -> ST s Int

Copy the contents of the chunks into a mutable array, reversing the order of the chunks. Precondition: The destination must have enough space to house the contents. This is not checked.

Commit Distance

Compute the number of bytes between the last byte and the offset specified in a chunk. Precondition: the chunk must exist in the list of committed chunks. This relies on mutable byte arrays having identity (e.g. it uses sameMutableByteArray#).

Safe Functions

These functions are actually completely safe, but they are defined here because they are used by typeclass instances. Import them from Data.Bytes.Builder instead.

Pasting with Preconditions

valuepasteUtf8TextJson#
  1. :: ByteArray#

    source

  2. -> Int#

    source offset

  3. -> Int#

    source length

  4. -> MutableByteArray# s

    destination buffer

  5. -> Int#

    offset into destination buffer

  6. -> State# s

    state token

  7. -> (# State# s, Int# #)

Encode (UTF-8 encoded) text as a JSON string, wrapping it in double quotes. This escapes all characters with code points below 0x20.

  • Precondition: The slice of the byte argument is UTF-8 encoded text.

  • Precondition: There is enough space in the buffer for the result to be written to. A simple way to ensure enough space is to allocate 6N + 2 bytes, where N is the length of the argument. However, the caller may use clever heuristics to find a lower upper bound.

  • Result: The next offset in the destination buffer