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_
27 std::function<void(
const MethodCall<T>& call,
32 template <
typename T = EncodableValue>
38 const std::string& name,
40 : messenger_(messenger), name_(name), codec_(codec) {}
53 std::unique_ptr<T> arguments,
56 std::unique_ptr<std::vector<uint8_t>> message =
59 messenger_->
Send(name_, message->data(), message->size(),
nullptr);
66 std::shared_ptr<MethodResult<T>> shared_result(
result.release());
67 const auto* codec = codec_;
68 std::string channel_name = name_;
69 BinaryReply reply_handler = [shared_result, codec, channel_name](
70 const uint8_t* reply,
size_t reply_size) {
71 if (reply_size == 0) {
72 shared_result->NotImplemented();
77 bool decoded = codec->DecodeAndProcessResponseEnvelope(
78 reply, reply_size, shared_result.get());
80 std::cerr <<
"Unable to decode reply to method "
81 "invocation on channel "
82 << channel_name << std::endl;
83 shared_result->NotImplemented();
87 messenger_->
Send(name_, message->data(), message->size(),
88 std::move(reply_handler));
103 const auto* codec = codec_;
104 std::string channel_name = name_;
106 const uint8_t* message,
111 std::make_unique<EngineMethodResult<T>>(std::move(reply), codec);
113 codec->DecodeMethodCall(message, message_size);
115 std::cerr <<
"Unable to construct method call from message on channel "
116 << channel_name << std::endl;
133 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_CHANNEL_H_