@qualithm/mqtt-wire - v0.1.5
    Preparing search index...

    Class BinaryReader

    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.

    const reader = new BinaryReader(buffer)

    const byte = reader.readUint8()
    if (!byte.ok) return byte

    const str = reader.readMqttString()
    if (!str.ok) return str

    console.log(byte.value, str.value)
    Index

    Constructors

    • Creates a new binary reader.

      Parameters

      • buffer: Uint8Array

        The buffer to read from

      • offset: number = 0

        Starting offset (default: 0)

      • Optionallength: number

        Length to read (default: rest of buffer)

      Returns BinaryReader

    Accessors

    • get isAtEnd(): boolean

      Checks if the reader has reached the end.

      Returns boolean

    • get offset(): number

      Gets the current read position.

      Returns number

    • get remaining(): number

      Gets the number of bytes remaining to read.

      Returns number

    Methods

    • Checks if there are enough bytes remaining to read.

      Parameters

      • count: number

      Returns boolean

    • Reads a fixed number of bytes.

      Parameters

      • count: number

        Number of bytes to read

      Returns DecodeResult<Uint8Array<ArrayBufferLike>>

      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.

      Parameters

      • count: number

        Number of bytes to read

      Returns DecodeResult<Uint8Array<ArrayBufferLike>>

      A view into the original buffer (no copy)

    • Reads remaining bytes.

      Returns Uint8Array

      A new Uint8Array containing all remaining bytes (copy)

    • Reads a raw UTF-8 string of specified length.

      Does not validate MQTT string restrictions.

      Parameters

      • length: number

      Returns DecodeResult<string>