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

    Function decodeVariableByteInteger

    • Decodes a variable byte integer from a buffer.

      Returns a result type to avoid exceptions in hot paths. The result includes both the decoded value and the number of bytes consumed.

      Parameters

      • buffer: Uint8Array

        The buffer to read from

      • offset: number

        The offset in the buffer to start reading

      Returns DecodeResult<VarintDecodeValue>

      DecodeResult containing value and bytesRead, or error

      MQTT 5.0 §2.2.3

      const buffer = new Uint8Array([0xc1, 0x02])
      const result = decodeVariableByteInteger(buffer, 0)
      if (result.ok) {
      console.log(result.value.value) // 321
      console.log(result.value.bytesRead) // 2
      }