Creates a decoder for the given byte buffer.
Binary data to decode
Current read position in the buffer (bytes consumed).
Bytes remaining to be read from current position.
Decodes a tagged variable-length integer (varint) from the buffer.
The Relish wire format uses tagged varints for length fields. The encoding uses bit 0 as a flag: if 0, the upper 7 bits contain the length (short form); if 1, the next 4 bytes contain a 32-bit little-endian length (long form).
Short form handles lengths 0-127 in a single byte. Long form handles lengths up to 2^31-1 in 4 bytes, supporting large payloads.
A Result containing the decoded length, or DecodeError if not enough data
Advances the cursor past the varint bytes consumed (1 byte for short form,
4 bytes for long form). Returns UNEXPECTED_EOF if insufficient bytes remain.
This is a public method since decoders in other packages need direct byte tracking during streaming operations.
decode for full message decoding
Decodes the next value from the buffer at the current cursor position.
Advances the cursor past the decoded value. Returns raw JavaScript values (number, bigint, boolean, null, string, DateTime, Array, Map, object) rather than wrapped RelishValue objects.
Result containing decoded value, or DecodeError on validation failure
Cursor-based binary decoder with validation for Relish wire format.
Reads bytes sequentially using an internal cursor, validating structure and constraints (field order, map key uniqueness, enum length, bit 7 rules).
Example
Decoding with error handling:
Remarks
The Decoder validates all wire format constraints:
Decoding produces DecodedValue (raw JavaScript values), not wrapped RelishValue objects. This asymmetry simplifies consumption of decoded data.
See
decode for one-shot decoding convenience function