PluginAwareMessageCodec.fromPlugins constructor

PluginAwareMessageCodec.fromPlugins({
  1. required MessageCodec<Message> defaultCodec,
  2. required List<SyncPlugin> plugins,
})

A message codec that can be used to encode and decode messages for a list of MessageCodecs.

The codec will try to decode the message with each MessageCodec until one of them succeeds. If no MessageCodec can decode the message, the codec will return null.

This codec is designed to support the plugin system. It is used to encode and decode messages with the default codec and the plugins' codecs.

Constructor from a default codec and a list of plugins

defaultCodec is the first codec used to encode and decode messages.

Implementation

factory PluginAwareMessageCodec.fromPlugins({
  required MessageCodec<Message> defaultCodec,
  required List<SyncPlugin> plugins,
}) {
  return PluginAwareMessageCodec(
    [
      defaultCodec,
      ...plugins.map((e) => e.messageCodec),
    ],
  );
}