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

decode method

*<Null safety>*
  • @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 = {};
  Map<int, UnknownRawData> unknownData = {};
  for (int ordinal = 1; ordinal <= maxOrdinal; ordinal++) {
    FidlType? fieldType;
    if (ordinal <= members.length) {
      fieldType = members[ordinal - 1];
    } else {
      fieldType = null;
    }

    final header = _decodeEnvelopeHeader(decoder, envelopeOffset);
    final field = _decodeEnvelopeContent(
        decoder,
        header,
        fieldType ??
            UnknownRawDataType(
                numBytes: header.numBytes, numHandles: header.numHandles),
        false);
    if (field != null) {
      if (fieldType != null) {
        argv[ordinal] = field;
      } else {
        _maybeThrowOnUnknownHandles(resource, field);
        unknownData[ordinal] = field;
      }
    }
    envelopeOffset += _kEnvelopeSize;
  }

  return ctor(argv, unknownData);
}