Creates a new binary reader.
The buffer to read from
Starting offset (default: 0)
Optionallength: numberLength to read (default: rest of buffer)
Checks if the reader has reached the end.
Gets the current read position.
Gets the number of bytes remaining to read.
Checks if there are enough bytes remaining to read.
Peeks at the next byte without consuming it.
Reads a fixed number of bytes.
Number of bytes to read
A new Uint8Array containing the bytes (copy)
Reads a view of bytes without copying.
Use this for performance when you know the bytes won't be mutated and don't need to outlive the buffer.
Number of bytes to read
A view into the original buffer (no copy)
Reads binary data with MQTT length prefix.
Reads a raw UTF-8 string of specified length with MQTT validation.
Reads remaining bytes.
A new Uint8Array containing all remaining bytes (copy)
Reads an unsigned 16-bit integer (big-endian).
Reads an unsigned 32-bit integer (big-endian).
Reads a single unsigned 8-bit integer.
Reads a raw UTF-8 string of specified length.
Does not validate MQTT string restrictions.
Creates a sub-reader for a portion of the remaining data.
Useful for reading length-prefixed sections where you want to constrain the reader to that section.
Length of the sub-section
A binary reader that provides cursor-based reading with bounds checking.
The reader maintains a position cursor and provides methods for reading various data types. All read operations return DecodeResult to handle errors without exceptions.
Example