decodeLength static method

Tuple<int, BigInt> decodeLength(
  1. List<int> bytes, {
  2. int offset = 0,
})

Implementation

static Tuple<int, BigInt> decodeLength(List<int> bytes, {int offset = 0}) {
  final byte = bytes[offset];

  switch (byte & 0x03) {
    case 0x00:
      return Tuple(1, BigInt.from(byte) >> 2);
    case 0x01:
      final val = fromBytes(
          bytes: bytes,
          offset: offset,
          end: offset + 2,
          sign: false,
          byteOrder: Endian.little);
      return Tuple(2, val >> 2);
    case 0x02:
      final val = fromBytes(
          bytes: bytes,
          offset: offset,
          end: offset + 4,
          byteOrder: Endian.little);
      return Tuple(4, val >> 2);
    default:
      final int o = (byte >> 2) + 5;
      final val = fromBytes(
          bytes: bytes,
          offset: offset + 1,
          end: offset + o,
          byteOrder: Endian.little);
      return Tuple(o, val);
  }
}