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) {
  final int envelopeOffset = offset + 8;
  final int ordinal = decoder.decodeUint64(offset);
  if (ordinal == 0) {
    if (!nullable) {
      throw FidlError('Zero xunion ordinal on non-nullable');
    }
    _decodeEnvelope(decoder, envelopeOffset, null, isEmpty: true);
    return null;
  } else {
    final header = _decodeEnvelopeHeader(decoder, envelopeOffset);
    var fieldType = members[ordinal];
    if (fieldType == null) {
      final unknownData = _decodeEnvelopeContent(decoder, header,
          UnknownRawDataType(header.numBytes, header.numHandles), false);
      if (unknownData == null) throw FidlError('Bad xunion: missing content');

      if (!flexible) {
        unknownData.closeHandles();
        throw FidlError('Bad xunion ordinal: $ordinal',
            FidlErrorCode.fidlStrictXUnionUnknownField);
      }
      return ctor(ordinal, unknownData);
    }
    final field = _decodeEnvelopeContent(decoder, header, fieldType, false);
    if (field == null) throw FidlError('Bad xunion: missing content');
    return ctor(ordinal, field);
  }
}