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.
The buffer to read from
The offset in the buffer to start reading
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} Copy
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}
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.