variableNatDecode static method

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

Implementation

static (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 > BinaryOps.maxU64) {
      throw ArgumentException.invalidOperationArguments(
        "variableNatDecode",
        name: "bytes",
        reason: "The variable size exceeds the limit for nat decode.",
      );
    }
    bytesRead++;
    if ((byte & 0x80) == 0) {
      return (output, bytesRead);
    }
  }
  throw ArgumentException.invalidOperationArguments(
    "variableNatDecode",
    name: "bytes",
    reason: "Invalid nat encode bytes.",
  );
}