| Flutter iOS 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
void | Resize (int new_size)
void | SetWarnsOnOverflow (bool warns)

## Detailed Description

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

Definition at line 56 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 60 of file basic_message_channel.h.

63 : 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

## ◆ Resize()

template<typename T = EncodableValue>

void flutter::BasicMessageChannel< T >::Resize | ( | int | new_size | ) |
| inline

Definition at line 128 of file basic_message_channel.h.

128 {
129 internal::ResizeChannel(messenger_, name_, new_size);
130 }
flutter::internal::ResizeChannel
void ResizeChannel(BinaryMessenger *messenger, std::string name, int new_size)
Definition: core_implementations.cc:181

References flutter::internal::ResizeChannel().

Referenced by flutter::TEST().

## ◆ Send() [1/2]

template<typename T = EncodableValue>

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

Definition at line 72 of file basic_message_channel.h.

72 {
73 std::unique_ptr<std::vector<uint8_t>> raw_message =
74 codec_->EncodeMessage(message);
75 messenger_->Send(name_, raw_message->data(), raw_message->size());
76 }
flutter::BinaryMessenger::Send
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0

References flutter::BinaryMessenger::Send().

## ◆ Send() [2/2]

template<typename T = EncodableValue>

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

Definition at line 79 of file basic_message_channel.h.

79 {
80 std::unique_ptr<std::vector<uint8_t>> raw_message =
81 codec_->EncodeMessage(message);
82 messenger_->Send(name_, raw_message->data(), raw_message->size(),
83 std::move(reply));
84 }

References flutter::BinaryMessenger::Send().

## ◆ SetMessageHandler()

template<typename T = EncodableValue>

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

Definition at line 92 of file basic_message_channel.h.

92 {
93 if (!handler) {
94 messenger_->SetMessageHandler(name_, nullptr);
95 return;
96 }
97 const auto* codec = codec_;
98 std::string channel_name = name_;
99 BinaryMessageHandler binary_handler = [handler, codec, channel_name](
100 const uint8_t* binary_message,
101 const size_t binary_message_size,
102 const BinaryReply& binary_reply) {
103 // Use this channel's codec to decode the message and build a reply
104 // handler.
105 std::unique_ptr<T> message =
106 codec->DecodeMessage(binary_message, binary_message_size);
107 if (!message) {
108 std::cerr << "Unable to decode message on channel " << channel_name
109 << std::endl;
110 binary_reply(nullptr, 0);
111 return;
112 }
113
114 MessageReply<T> unencoded_reply = [binary_reply,
115 codec](const T& unencoded_response) {
116 auto binary_response = codec->EncodeMessage(unencoded_response);
117 binary_reply(binary_response->data(), binary_response->size());
118 };
119 handler(*message, std::move(unencoded_reply));
120 };
121 messenger_->SetMessageHandler(name_, std::move(binary_handler));
122 }
flutter::BinaryMessenger::SetMessageHandler
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
flutter::BinaryMessageHandler
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
Definition: binary_messenger.h:24
flutter::BinaryReply
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
Definition: binary_messenger.h:17

References flutter::BinaryMessenger::SetMessageHandler().

Referenced by flutter::TEST().

## ◆ SetWarnsOnOverflow()

template<typename T = EncodableValue>

void flutter::BasicMessageChannel< T >::SetWarnsOnOverflow | ( | bool | warns | ) |
| inline

Definition at line 137 of file basic_message_channel.h.

137 {
138 internal::SetChannelWarnsOnOverflow(messenger_, name_, warns);
139 }
flutter::internal::SetChannelWarnsOnOverflow
void SetChannelWarnsOnOverflow(BinaryMessenger *messenger, std::string name, bool warns)
Definition: core_implementations.cc:194

References flutter::internal::SetChannelWarnsOnOverflow().

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