Creates a new binary writer.
Initial buffer size (default: 256)
Gets the current write position (number of bytes written).
Reserves space for bytes to be written later.
Returns the offset where the reserved space starts.
Number of bytes to reserve
The offset where reserved space starts
Resets the writer for reuse.
Gets the final bytes as a new Uint8Array.
Returns a trimmed copy of the internal buffer.
Gets a view of the written data.
Returns a view into the internal buffer (no copy). The view is only valid until the next write operation.
Writes bytes at a specific offset (for filling reserved space).
Does not advance the write position.
The offset to write at
The bytes to write
Writes raw bytes.
Writes binary data with MQTT length prefix.
Writes an unsigned 16-bit integer (big-endian).
Writes an unsigned 32-bit integer (big-endian).
Writes a single unsigned 8-bit integer.
Writes a single byte at a specific offset.
The offset to write at
The byte value to write
Writes a raw UTF-8 string without length prefix.
A binary writer with automatic buffer growth.
The writer maintains a position cursor and automatically grows the internal buffer as needed. Use toUint8Array to get the final bytes.
Example