5 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_
28 std::function<void(
const MethodCall<T>& call,
33 template <
typename T = EncodableValue>
39 const std::string& name,
41 : messenger_(messenger), name_(name), codec_(codec) {}
54 std::unique_ptr<T> arguments,
57 std::unique_ptr<std::vector<uint8_t>> message =
60 messenger_->
Send(name_, message->data(), message->size(),
nullptr);
67 std::shared_ptr<MethodResult<T>> shared_result(
result.release());
68 const auto* codec = codec_;
69 std::string channel_name = name_;
70 BinaryReply reply_handler = [shared_result, codec, channel_name](
71 const uint8_t* reply,
size_t reply_size) {
72 if (reply_size == 0) {
73 shared_result->NotImplemented();
78 bool decoded = codec->DecodeAndProcessResponseEnvelope(
79 reply, reply_size, shared_result.get());
81 std::cerr <<
"Unable to decode reply to method "
82 "invocation on channel "
83 << channel_name << std::endl;
84 shared_result->NotImplemented();
88 messenger_->
Send(name_, message->data(), message->size(),
89 std::move(reply_handler));
104 const auto* codec = codec_;
105 std::string channel_name = name_;
107 const uint8_t* message,
112 std::make_unique<EngineMethodResult<T>>(std::move(reply), codec);
114 codec->DecodeMethodCall(message, message_size);
116 std::cerr <<
"Unable to construct method call from message on channel "
117 << channel_name << std::endl;
151 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_