ByteArrayBuilder

class ByteArrayBuilder(initialCapacity: Int = 64)

Grow-on-demand byte buffer. Pure Kotlin (no platform OutputStream classes), so it works in commonMain across all targets — and it's faster than mutableListOf<Byte>() because it stores into a contiguous primitive array.

Public because consumers building or assembling byte streams (e.g. demo PDF generators in tests/samples) need the same primitive.

Constructors

Link copied to clipboard
constructor(initialCapacity: Int = 64)

Functions

Link copied to clipboard
fun append(b: Byte)
fun append(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size - offset)
Link copied to clipboard

Append the low byte of each char in s directly — for pure-ASCII tokens (PDF keywords, numbers, operators). Avoids the transient ByteArray that s.encodeToByteArray() allocates per call. Callers must guarantee ASCII.

Link copied to clipboard
fun appendFill(b: Byte, count: Int)

Append count copies of b in one reserved span (no per-byte grow check).

Link copied to clipboard
fun appendLong(value: Long)

Append the base-10 ASCII representation of value directly into the buffer — no intermediate String. Used by the serializer for object numbers, generations and /Length, which are written per object.

Link copied to clipboard
fun size(): Int
Link copied to clipboard