readVarUint method

int readVarUint()

Read a variable length unsigned integer from the buffer encoded as an LEB128 unsigned integer.

Implementation

int readVarUint() {
  int result = 0;
  int shift = 0;
  while (true) {
    int byte = buffer.getUint8(readIndex++) & 0xff;
    result |= (byte & 0x7f) << shift;
    if ((byte & 0x80) == 0) break;
    shift += 7;
  }
  return result;
}