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). @param pipe A Buffer containing the leb encoded bits.

Implementation

BigInt lebDecode<T>(BufferPipe<T> pipe) {
  var weight = BigInt.one;
  var value = BigInt.zero;
  // ignore: prefer_typing_uninitialized_variables
  var byte;

  do {
    byte = safeRead(pipe, 1)[0];
    value += BigInt.from(byte & 0x7f) * weight;
    weight *= BigInt.from(128);
  } while (byte >= 0x80);

  return value;
}