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

encode method

  • @override

void encode (Encoder encoder, T value, int offset) override

Implementation

@override
void encode(Encoder encoder, T value, int offset) {
  final int envelopeOffset = offset + 8;
  if (value == null) {
    if (!nullable) {
      _throwIfNotNullable(nullable);
    }
    encoder.encodeUint64(0, offset);
    _encodeEnvelopeAbsent(encoder, envelopeOffset);
  } else {
    final int ordinal = value.$ordinal;
    var fieldType = members[ordinal];
    if (fieldType == null && flexible) {
      UnknownRawData rawData = value.$data;
      fieldType =
          UnknownRawDataType(rawData.data.length, rawData.handles.length);
    }
    if (fieldType == null)
      throw FidlError('Bad xunion ordinal: $ordinal',
          FidlErrorCode.fidlStrictXUnionUnknownField);

    encoder.encodeUint64(ordinal, offset);
    _encodeEnvelopePresent(encoder, envelopeOffset, value.$data, fieldType);
  }
}