| Flutter Windows Embedder |

Public Member Functions | List of all members
flutter::BasicMessageChannel< T > Class Template Reference

`#include <basic_message_channel.h>`

## Public Member Functions
| BasicMessageChannel (BinaryMessenger *messenger, const std::string &name, const MessageCodec< T > *codec)
| ~BasicMessageChannel ()=default
| BasicMessageChannel (BasicMessageChannel const &)=delete
BasicMessageChannel & | operator= (BasicMessageChannel const &)=delete
void | Send (const T &message)
void | Send (const T &message, BinaryReply reply)
void | SetMessageHandler (const MessageHandler< T > &handler) const

## Detailed Description

### template<typename T = EncodableValue>
class flutter::BasicMessageChannel< T >

Definition at line 36 of file basic_message_channel.h.

## Constructor & Destructor Documentation

## ◆ BasicMessageChannel() [1/2]

template<typename T = EncodableValue>

flutter::BasicMessageChannel< T >::BasicMessageChannel | ( | BinaryMessenger * | messenger,
|  | const std::string & | name,
|  | const MessageCodec< T > * | codec
| ) |  |
| inline

Definition at line 40 of file basic_message_channel.h.

43 : messenger_(messenger), name_(name), codec_(codec) {}

## ◆ ~BasicMessageChannel()

template<typename T = EncodableValue>

flutter::BasicMessageChannel< T >::~BasicMessageChannel | ( |  | ) |
| default

## ◆ BasicMessageChannel() [2/2]

template<typename T = EncodableValue>

flutter::BasicMessageChannel< T >::BasicMessageChannel | ( | BasicMessageChannel< T > const & |  | ) |
| delete

## Member Function Documentation

## ◆ operator=()

template<typename T = EncodableValue>

BasicMessageChannel& flutter::BasicMessageChannel< T >::operator= | ( | BasicMessageChannel< T > const & |  | ) |
| delete

## ◆ Send() [1/2]

template<typename T = EncodableValue>

void flutter::BasicMessageChannel< T >::Send | ( | const T & | message | ) |
| inline

Definition at line 52 of file basic_message_channel.h.

52 {
53 std::unique_ptr<std::vector<uint8_t>> raw_message =
54 codec_->EncodeMessage(message);
55 messenger_->Send(name_, raw_message->data(), raw_message->size());
56 }

References message, and flutter::BinaryMessenger::Send().

## ◆ Send() [2/2]

template<typename T = EncodableValue>

void flutter::BasicMessageChannel< T >::Send | ( | const T & | message,
|  | BinaryReply | reply
| ) |  |
| inline

Definition at line 59 of file basic_message_channel.h.

59 {
60 std::unique_ptr<std::vector<uint8_t>> raw_message =
61 codec_->EncodeMessage(message);
62 messenger_->Send(name_, raw_message->data(), raw_message->size(),
63 std::move(reply));
64 }

References message, and flutter::BinaryMessenger::Send().

## ◆ SetMessageHandler()

template<typename T = EncodableValue>

void flutter::BasicMessageChannel< T >::SetMessageHandler | ( | const MessageHandler< T > & | handler | ) | const
| inline

Definition at line 72 of file basic_message_channel.h.

72 {
73 if (!handler) {
74 messenger_->SetMessageHandler(name_, nullptr);
75 return;
76 }
77 const auto* codec = codec_;
78 std::string channel_name = name_;
79 BinaryMessageHandler binary_handler = [handler, codec, channel_name](
80 const uint8_t* binary_message,
81 const size_t binary_message_size,
82 const BinaryReply& binary_reply) {
83 // Use this channel's codec to decode the message and build a reply
84 // handler.
85 std::unique_ptr<T> message =
86 codec->DecodeMessage(binary_message, binary_message_size);
87 if (!message) {
88 std::cerr << "Unable to decode message on channel " << channel_name
89 << std::endl;
90 binary_reply(nullptr, 0);
91 return;
92 }
93
94 MessageReply<T> unencoded_reply = [binary_reply,
95 codec](const T& unencoded_response) {
96 auto binary_response = codec->EncodeMessage(unencoded_response);
97 binary_reply(binary_response->data(), binary_response->size());
98 };
99 handler(*message, std::move(unencoded_reply));
100 };
101 messenger_->SetMessageHandler(name_, std::move(binary_handler));
102 }

References message, and flutter::BinaryMessenger::SetMessageHandler().

Referenced by flutter::TEST().

The documentation for this class was generated from the following file:

- shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h

flutter::BinaryMessenger::SetMessageHandler
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
flutter::BinaryReply
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
Definition: binary_messenger.h:17
message
Win32Message message
Definition: keyboard_unittests.cc:137
flutter::BinaryMessenger::Send
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0
flutter::BinaryMessageHandler
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
Definition: binary_messenger.h:24