vlq-buffer
A simple set of functions for converting between integer and VLQ buffer values
Installation
$ npm install --save vlq-buffer
Reference vlq-buffer
var vlqBuffer = ;
Usage
int2VLQBuffer
This method converts an integer to a Buffer containing the VLQ representation of that integer.
var myInt = 2097151;var bufferValue = vlqBuffer; // bufferValue == <Buffer ff ff 7f>
vlqBuffer2Int
This method converts a Buffer containing a VLQ value to an integer.
var myVLQValue = 0x81 0x80 0x00;var intValue = vlqBuffer; // intValue == 16384
isVLQLastByte
This method returns true if the given integer's binary value starts with zero, indicating tne end of the VLQ value. This is useful for identifying the final byte in a VLQ value when reading binary data.
var vlqStartIndex = readIndex; // start reading a vlq value and the current read indexvar currentByte = bufferData;while !vlqBuffer if ++readIndex >= bufferDatalength throw 'EOF error'; // EOF, no vql end found currentByte = bufferData;var vlqValueBytes = bufferData;var intValue = vlq;