encodeObject<T> method

  1. @override
void encodeObject<T>(
  1. T value, {
  2. Encodable<T>? using,
})
override

Encodes an object of type T.

This tries to encode the object using one of the following ways:

  1. If the using parameter is provided, it forwards the encoding to the provided Encodable implementation.
  2. If the object is a SelfEncodable, it calls SelfEncodable.encode on the object.
  3. If the object is a supported primitive value, it encodes it as such.
  4. If none of the above applies, an error is thrown.

This should only be called if the format returned true from canEncodeCustom

Implementation

@override
void encodeObject<T>(T value, {Encodable<T>? using}) {
  if (value is Stream && (using is AsyncEncodable || using == null)) {
    final marker = _values.addStream(value, using is AsyncEncodable ? using as AsyncEncodable : null);
    _encodeMarker(marker);
  } else if (value is Future && (using is AsyncEncodable || using == null)) {
    final marker = _values.addFuture(value, using is AsyncEncodable ? using as AsyncEncodable : null);
    _encodeMarker(marker);
  } else if (value is Reference) {
    final marker = _values.addReference(value);
    _encodeMarker(marker);
  } else if (_values.get(value) case int marker when marker != _marker) {
    _encodeMarker(marker);
  } else {
    super.encodeObject(value, using: using);
  }
}