lebDecode<T> function

BigInt lebDecode<T>(
  1. BufferPipe<T> pipe
)

Decode a leb encoded buffer into a bigint. The number will always be positive (does not support signed leb encoding).

Implementation

BigInt lebDecode<T>(BufferPipe<T> pipe) {
  BigInt weight = BigInt.one;
  BigInt value = BigInt.zero;
  int byte;
  do {
    byte = safeRead(pipe, 1)[0] as int;
    value += BigInt.from(byte & 0x7f) * weight;
    weight *= BigInt.from(128);
  } while (byte >= 0x80);

  return value;
}