decodeUnsigned static method

int decodeUnsigned(
  1. Uint8List bytes, {
  2. int n = 64,
})

Converts a list of bytes that represent an LEB128 unsigned integer into an ordinary integer. The optional argument specifies the number of bits in the integer. For example, while dealing with a varuint7, the second argument would be 7.

Implementation

static int decodeUnsigned(Uint8List bytes, {int n = 64}) {
  int result = 0;
  int shift = 0;
  int i = 0;
  while (true) {
    int byte = bytes[i++] & 0xff;
    result |= (byte & 0x7f) << shift;
    if ((byte & 0x80) == 0) break;
    shift += 7;
  }
  return result;
}