decodeLength static method

Tuple<int, BigInt> decodeLength(
  1. List<int> bytes, {
  2. bool sign = false,
})

Implementation

static Tuple<int, BigInt> decodeLength(List<int> bytes, {bool sign = false}) {
  switch (bytes[0] & 0x03) {
    case 0x00:
      return Tuple(1, BigInt.from(bytes[0]) >> 2);
    case 0x01:
      final val = BigintUtils.fromBytes(bytes.sublist(0, 2),
          sign: sign, byteOrder: Endian.little);
      return Tuple(2, val >> 2);
    case 0x02:
      final val = BigintUtils.fromBytes(bytes.sublist(0, 4),
          sign: sign, byteOrder: Endian.little);
      return Tuple(4, val >> 2);
    default:
      final int offset = (bytes[0] >> 2) + 5;
      final val = BigintUtils.fromBytes(bytes.sublist(1, offset),
          sign: sign, byteOrder: Endian.little);
      return Tuple(offset, val);
  }
}