In-memory encoder backed by an auto-growing buffer.
Bytes currently held in the buffer (since construction or the last flush).
The encoded message so far, as a view into the working buffer. Meaningful for the in-memory mode; in streaming mode it is only the not-yet-flushed tail. The view is valid until the next write.
Drain buffered bytes to the flush sink (no-op without one).
Rewind the encoder to empty, reusing the existing buffer. Lets a caller pool one OStream across many messages instead of allocating a fresh buffer per encode. Any view previously returned by bytes is invalidated.
Install a fresh output buffer to write into, mid-stream. Intended for the
streaming (flush-sink) mode: call it from inside your flush callback to hand
the encoder a new buffer for the next batch of bytes, so encoding continues
without interruption. offset reserves space at the front of the new
buffer. Any not-yet-flushed bytes in the old buffer are dropped, so
flush first (the flush callback fires before you swap).
Write a blob (arbitrary bytes) field.
Write a boolean field (encoded as the unsigned value 0 or 1).
Write a fixed-length field of the given subtype from raw bytes.
Write an IEEE-754 32-bit float field.
Write an array of IEEE-754 32-bit floats.
Write an fp32 array from its raw little-endian element payload. The bytes
are emitted verbatim — no per-element setFloat32 — so a signaling NaN
survives bit-for-bit (§4.6), which writeFp32Array cannot guarantee
because it re-quantizes each JS number. payload.length must be a
multiple of 4; the element count is payload.length / 4.
Write an IEEE-754 64-bit double field.
Write an array of IEEE-754 64-bit doubles.
Open a nested sequence (a fresh id scope) whose header is held back until the sequence turns out to have content.
MESSAGE_SPEC §2 omits a sequence-typed field whose value equals its declared default, and "not one child was written" is exactly that condition — evaluated per child field, recursively, for free, because the message layer already omits every child equal to its default. A sequence closed with nothing in it therefore emits nothing instead of a two-byte empty frame, and an all-default message becomes the empty byte string. No byte image is ever compared, so in-memory layout never enters the decision.
This is the only way to open a sequence. How it closes decides whether a contentless one survives: OStream.writeSequenceEnd drops it, OStream.writeSequenceEndKeep forces the frame out.
Close the current sequence, letting it vanish if it received no content.
Use it wherever absence encodes the same value as an empty frame: a
struct/union field, and an array field whose declared default is the
empty collection (MESSAGE_SPEC §2). Where the frame must be visible, close
with OStream.writeSequenceEndKeep instead.
An end with no matching begin is not rejected: the encoder writes what it is told, and the resulting bytes are then malformed, which is the decoder's verdict to make. No other port refuses it. The depth counter stops at zero so the MAX_DEPTH check on begin cannot be fooled by an underflow.
Close the current sequence, keeping its frame even when it received no content.
Behaves like a write: it first emits any held-back headers — this frame's
and every enclosing one's — and then the end marker, so an empty sequence
reaches the wire as begin + end.
Required wherever the frame carries information beyond its contents:
struct/union/nested row): element
presence is what carries a dynamic array's length — highest present id +
1 (MESSAGE_SPEC §5.1) — so dropping an all-default element would change
the decoded length, not just the bytes;default: absence would reconstruct that default, so the empty frame is
the only encoding of "explicitly empty" (§2, §3).The two failure directions are not symmetric, which is why this is the safe choice when in doubt: using it where OStream.writeSequenceEnd would do costs one non-canonical empty frame that a decoder normalizes away, while the reverse silently changes an array's length.
Write a signed integer field (zig-zag encoded).
Write an array of signed integers (each zig-zag + varint).
Write a UTF-8 string field.
Write an unsigned integer field.
Write an array of unsigned integers (each a varint).
Write an unsigned 64-bit array from Long[] — the bigint-free path.
Produces the identical wire to writeUnsignedArray; reads each Long's
32-bit halves directly, so no bigint is created per element.
Encoder for the SofaBuffers wire format. Each
write*method appends one field and maps one-to-one onto a wire type. Construct it in-memory (an auto-growing buffer, read back with OStream.bytes) or in streaming mode over a caller-provided buffer that drains to a FlushSink as it fills, so the message can outgrow the buffer. Invalid arguments and a full buffer with no sink throw SofabError.