encodeTo method

  1. @override
void encodeTo(
  1. MapEntry<String, V> value,
  2. Output output
)
override

Convert self to a slice and append it to the destination.

Implementation

@override
void encodeTo(MapEntry<String, V> value, Output output) {
  final type = value.key;

  final index = map.inverse[type];

  if (index == null) {
    throw EnumException(
        'Invalid enum value: $value. Can only accept: ${map.values.join(', ')}');
  }

  output.pushByte(index);

  final codec = registry.getCodec(type);

  assertion(codec != null, 'Codec for type:$type not found.');

  codec!.encodeTo(value.value, output);
}