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_
35 template <
typename T = EncodableValue>
41 const std::string& name,
43 : messenger_(messenger), name_(name), codec_(codec) {}
52 void Send(
const T& message) {
53 std::unique_ptr<std::vector<uint8_t>> raw_message =
54 codec_->EncodeMessage(message);
55 messenger_->
Send(name_, raw_message->data(), raw_message->size());
60 std::unique_ptr<std::vector<uint8_t>> raw_message =
61 codec_->EncodeMessage(message);
62 messenger_->
Send(name_, raw_message->data(), raw_message->size(),
77 const auto* codec = codec_;
78 std::string channel_name = name_;
80 const uint8_t* binary_message,
81 const size_t binary_message_size,
85 std::unique_ptr<T> message =
86 codec->DecodeMessage(binary_message, binary_message_size);
88 std::cerr <<
"Unable to decode message on channel " << channel_name
90 binary_reply(
nullptr, 0);
95 codec](
const T& unencoded_response) {
96 auto binary_response = codec->EncodeMessage(unencoded_response);
97 binary_reply(binary_response->data(), binary_response->size());
99 handler(*message, std::move(unencoded_reply));
112 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BASIC_MESSAGE_CHANNEL_H_