variableNatDecode static method

Tuple<BigInt, int> variableNatDecode(
  1. List<int> bytes
)

Implementation

static Tuple<BigInt, int> variableNatDecode(List<int> bytes) {
  BigInt output = BigInt.zero;
  int bytesRead = 0;
  for (final byte in bytes) {
    output = (output << 7) | BigInt.from(byte & 0x7F);
    if (output > maxU64) {
      throw const MessageException(
          "The variable size exceeds the limit for Nat Decode");
    }
    bytesRead++;
    if ((byte & 0x80) == 0) {
      return Tuple(output, bytesRead);
    }
  }
  throw const MessageException("Nat Decode failed.");
}