getVarint method

int getVarint()

Reads an unsigned integer as a base-128 varint. The number is written, 7 bits at a time, from the least significant to the most significant 7 bits. Each byte, except the last, has the MSB set.

return The int or long value at the reader's current position

Implementation

int getVarint() {
  var value = 0;
  var i = 0;
  int b;
  while (((b = getByte()) & 0x80) != 0) {
    value |= (b & 0x7F) << i;
    i += 7;
  }
  return value | (b << i);
}