decode method

  1. @override
int decode(
  1. Input input
)
override

Implementation

@override
int decode(Input input) {
  var prefix = input.read();
  switch (prefix % 4) {
    case 0:
      {
        return prefix >> 2;
      }
    case 1:
      {
        prefix >>= 2;
        prefix |= input.read() << 6;
        assertion(prefix > 0x3f && prefix <= 0x3fff, 'Out of range');
        return prefix;
      }
    case 2:
      {
        prefix >>= 2;
        prefix |=
            (input.read() << 6) | (input.read() << 14) | (input.read() << 22);
        assertion(prefix > 0x3fff && prefix <= 0x3fffffff, 'Out of range');
        return prefix;
      }
    default:
      {
        final bytesNeeded = (prefix >> 2) + 4;
        var value = 0;
        for (var i = 0; i < bytesNeeded; i++) {
          value |= input.read() << (8 * i);
        }
        assertion(value > 0x3fffffff, 'Out of range');
        return value;
      }
  }
}