PluginAwareMessageCodec constructor

const PluginAwareMessageCodec({
  1. required MessageCodec<Message> defaultCodec,
  2. List<MessageCodec<Message>> pluginCodecs = const [],
})

The codec of the protocol plus one per plugin, picked by message type.

A message in the plugin range (from MessageTypeValue.firstPluginValue) belongs to a plugin; anything below it belongs to the protocol. encode routes on that, so a plugin's codec is the one that writes its own messages. decode has bytes rather than a message, so it asks each codec in turn and takes the first that reads them — a codec answers null for a frame that is not its own.

Either way null means no codec here handles that message, which is what a peer running a plugin this build does not have looks like.

defaultCodec reads and writes the protocol's own messages. pluginCodecs are consulted for the plugin range, in order.

Implementation

const PluginAwareMessageCodec({
  required MessageCodec<Message> defaultCodec,
  List<MessageCodec<Message>> pluginCodecs = const [],
})  : _defaultCodec = defaultCodec,
      _pluginCodecs = pluginCodecs;