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

    Function encodeVariableByteInteger

    • Encodes a variable byte integer into a buffer at the specified offset.

      The encoding scheme uses the high bit of each byte as a continuation flag. If the high bit is 1, there are more bytes to follow.

      Parameters

      • value: number

        The integer value to encode (0 to 268,435,455)

      • buffer: Uint8Array

        The buffer to write to

      • offset: number

        The offset in the buffer to start writing

      Returns number

      Number of bytes written (1-4)

      RangeError if value is out of range or buffer is too small

      MQTT 5.0 §2.2.3

      const buffer = new Uint8Array(4)
      encodeVariableByteInteger(321, buffer, 0)
      // buffer is now [0xc1, 0x02, 0x00, 0x00]