setMockDecodedMessageHandler<T> method

void setMockDecodedMessageHandler<T>(
  1. BasicMessageChannel<T> channel,
  2. Future<T> handler(
    1. T? message
    )?
)

Intercepts messages sent on channel, decoding them with the channel's codec before handing them to handler.

Mirrors TestDefaultBinaryMessenger.setMockDecodedMessageHandler.

Implementation

void setMockDecodedMessageHandler<T>(
  BasicMessageChannel<T> channel,
  Future<T> Function(T? message)? handler,
) {
  if (handler == null) {
    _setMockMessageHandler(channel.name, null);
    return;
  }
  _setMockMessageHandler(channel.name, (ByteData? message) async {
    return channel.codec
        .encodeMessage(await handler(channel.codec.decodeMessage(message)));
  });
}