5#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BASIC_MESSAGE_CHANNEL_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BASIC_MESSAGE_CHANNEL_H_
55template <
typename T = EncodableValue>
61 const std::string&
name,
63 : messenger_(messenger), name_(
name), codec_(codec) {}
73 std::unique_ptr<std::vector<uint8_t>> raw_message =
75 messenger_->
Send(name_, raw_message->data(), raw_message->size());
80 std::unique_ptr<std::vector<uint8_t>> raw_message =
82 messenger_->
Send(name_, raw_message->data(), raw_message->size(),
97 const auto* codec = codec_;
98 std::string channel_name = name_;
100 const uint8_t* binary_message,
101 const size_t binary_message_size,
106 codec->DecodeMessage(binary_message, binary_message_size);
108 std::cerr <<
"Unable to decode message on channel " << channel_name
110 binary_reply(
nullptr, 0);
115 codec](
const T& unencoded_response) {
116 auto binary_response = codec->EncodeMessage(unencoded_response);
117 binary_reply(binary_response->data(), binary_response->size());
119 handler(*
message, std::move(unencoded_reply));
void Send(const T &message)
BasicMessageChannel(BasicMessageChannel const &)=delete
~BasicMessageChannel()=default
void Send(const T &message, BinaryReply reply)
void Resize(int new_size)
BasicMessageChannel & operator=(BasicMessageChannel const &)=delete
void SetMessageHandler(const MessageHandler< T > &handler) const
void SetWarnsOnOverflow(bool warns)
BasicMessageChannel(BinaryMessenger *messenger, const std::string &name, const MessageCodec< T > *codec)
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
Dart_NativeFunction function
void SetChannelWarnsOnOverflow(BinaryMessenger *messenger, std::string name, bool warns)
void ResizeChannel(BinaryMessenger *messenger, std::string name, int new_size)
std::function< void(const T &message, const MessageReply< T > &reply)> MessageHandler
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
DEF_SWITCHES_START aot vmservice shared library name
std::function< void(const T &reply)> MessageReply