Google is committed to advancing racial equity for Black communities. See how.

decode method

  • @override

T decode (Decoder decoder, int offset) override

Implementation

@override
T decode(Decoder decoder, int offset) {
  // Header.
  final int maxOrdinal = decoder.decodeUint64(offset);
  final int data = decoder.decodeUint64(offset + 8);
  switch (data) {
    case kAllocPresent:
      break; // good
    case kAllocAbsent:
      throw FidlError('Unexpected null reference');
    default:
      throw FidlError('Bad reference encoding');
  }

  // Early exit on empty table.
  if (maxOrdinal == 0) {
    return ctor({});
  }

  // Offsets.
  int envelopeOffset = decoder.claimMemory(maxOrdinal * _kEnvelopeSize);

  // Envelopes, and fields.
  final Map<int, dynamic> argv = {};
  for (int ordinal = 1; ordinal <= maxOrdinal; ordinal++) {
    FidlType fieldType;
    if (ordinal <= members.length) {
      fieldType = members[ordinal - 1];
    } else {
      fieldType = null;
    }
    final field = _decodeEnvelope(decoder, envelopeOffset, fieldType);
    if (field != null) argv[ordinal] = field;
    envelopeOffset += _kEnvelopeSize;
  }

  return ctor(argv);
}