deserializeUleb128AsU32 method

int deserializeUleb128AsU32()

Implementation

int deserializeUleb128AsU32() {
  var value = BigInt.zero;
  var shift = 0;

  while (value < BigInt.from(MAX_U32_NUMBER)) {
    int byte = deserializeU8();
    value |= BigInt.from(byte & 0x7f) << shift;

    if ((byte & 0x80) == 0) {
      break;
    }
    shift += 7;
  }

  if (value > BigInt.from(MAX_U32_NUMBER)) {
    throw ArgumentError("Overflow while parsing uleb128-encoded uint32 value");
  }

  return value.toInt();
}