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.
The integer value to encode (0 to 268,435,455)
The buffer to write to
The offset in the buffer to start writing
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] Copy
const buffer = new Uint8Array(4)encodeVariableByteInteger(321, buffer, 0)// buffer is now [0xc1, 0x02, 0x00, 0x00]
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.