| Flutter macOS Embedder |

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
flutter::StandardMethodCodec Class Reference

`#include <standard_method_codec.h>`

Inheritance diagram for flutter::StandardMethodCodec:

## Public Member Functions
| ~StandardMethodCodec ()
| StandardMethodCodec (StandardMethodCodec const &)=delete
StandardMethodCodec & | operator= (StandardMethodCodec const &)=delete
Public Member Functions inherited from flutter::MethodCodec< EncodableValue >
| MethodCodec ()=default
| MethodCodec (MethodCodec< EncodableValue > const &)=delete
virtual | ~MethodCodec ()=default
MethodCodec & | operator= (MethodCodec< EncodableValue > const &)=delete
std::unique_ptr< MethodCall< EncodableValue > > | DecodeMethodCall (const uint8_t *message, size_t message_size) const
std::unique_ptr< MethodCall< EncodableValue > > | DecodeMethodCall (const std::vector< uint8_t > &message) const
std::unique_ptr< std::vector< uint8_t > > | EncodeMethodCall (const MethodCall< EncodableValue > &method_call) const
std::unique_ptr< std::vector< uint8_t > > | EncodeSuccessEnvelope (const EncodableValue *result=nullptr) const
std::unique_ptr< std::vector< uint8_t > > | EncodeErrorEnvelope (const std::string &error_code, const std::string &error_message="", const EncodableValue *error_details=nullptr) const
bool | DecodeAndProcessResponseEnvelope (const uint8_t *response, size_t response_size, MethodResult< EncodableValue > *result) const

## Static Public Member Functions
static const StandardMethodCodec & | GetInstance (const StandardCodecSerializer *serializer=nullptr)

## Protected Member Functions
std::unique_ptr< MethodCall< EncodableValue > > | DecodeMethodCallInternal (const uint8_t *message, size_t message_size) const override
std::unique_ptr< std::vector< uint8_t > > | EncodeMethodCallInternal (const MethodCall< EncodableValue > &method_call) const override
std::unique_ptr< std::vector< uint8_t > > | EncodeSuccessEnvelopeInternal (const EncodableValue *result) const override
std::unique_ptr< std::vector< uint8_t > > | EncodeErrorEnvelopeInternal (const std::string &error_code, const std::string &error_message, const EncodableValue *error_details) const override
bool | DecodeAndProcessResponseEnvelopeInternal (const uint8_t *response, size_t response_size, MethodResult< EncodableValue > *result) const override

## Detailed Description

Definition at line 18 of file standard_method_codec.h.

## Constructor & Destructor Documentation

## ◆ ~StandardMethodCodec()

flutter::StandardMethodCodec::~StandardMethodCodec | ( |  | ) |
| default

## ◆ StandardMethodCodec()

flutter::StandardMethodCodec::StandardMethodCodec | ( | StandardMethodCodec const & |  | ) |
| delete

Referenced by GetInstance().

## Member Function Documentation

## ◆ DecodeAndProcessResponseEnvelopeInternal()

bool flutter::StandardMethodCodec::DecodeAndProcessResponseEnvelopeInternal | ( | const uint8_t * | response,
|  | size_t | response_size,
|  | MethodResult< EncodableValue > * | result
| ) |  | const
| overrideprotectedvirtual

Implements flutter::MethodCodec< EncodableValue >.

Definition at line 434 of file standard_codec.cc.

437 {
438 ByteBufferStreamReader stream(response, response_size);
439 uint8_t flag = stream.ReadByte();
440 switch (flag) {
441 case 0: {
442 EncodableValue value = serializer_->ReadValue(&stream);
443 if (value.IsNull()) {
444 result->Success();
445 } else {
446 result->Success(value);
447 }
448 return true;
449 }
450 case 1: {
451 EncodableValue code = serializer_->ReadValue(&stream);
452 EncodableValue message = serializer_->ReadValue(&stream);
453 EncodableValue details = serializer_->ReadValue(&stream);
454 const std::string& message_string =
455 message.IsNull() ? "" : std::get<std::string>(message);
456 if (details.IsNull()) {
457 result->Error(std::get<std::string>(code), message_string);
458 } else {
459 result->Error(std::get<std::string>(code), message_string, details);
460 }
461 return true;
462 }
463 default:
464 return false;
465 }
466 }
flutter::EncodableValue::IsNull
bool IsNull() const
Definition: encodable_value.h:203
flutter::MethodResult::Error
void Error(const std::string &error_code, const std::string &error_message, const T &error_details)
Definition: method_result.h:41
flutter::MethodResult::Success
void Success(const T &result)
Definition: method_result.h:29
flutter::StandardCodecSerializer::ReadValue
EncodableValue ReadValue(ByteStreamReader *stream) const
Definition: standard_codec.cc:92

References flutter::MethodResult< T >::Error(), flutter::EncodableValue::IsNull(), flutter::ByteBufferStreamReader::ReadByte(), flutter::StandardCodecSerializer::ReadValue(), and flutter::MethodResult< T >::Success().

## ◆ DecodeMethodCallInternal()

std::unique_ptr< MethodCall< EncodableValue > > flutter::StandardMethodCodec::DecodeMethodCallInternal | ( | const uint8_t * | message,
|  | size_t | message_size
| ) |  | const
| overrideprotectedvirtual

Implements flutter::MethodCodec< EncodableValue >.

Definition at line 368 of file standard_codec.cc.

369 {
370 ByteBufferStreamReader stream(message, message_size);
371 EncodableValue method_name_value = serializer_->ReadValue(&stream);
372 const auto* method_name = std::get_if<std::string>(&method_name_value);
373 if (!method_name) {
374 std::cerr << "Invalid method call; method name is not a string."
375 << std::endl;
376 return nullptr;
377 }
378 auto arguments =
379 std::make_unique<EncodableValue>(serializer_->ReadValue(&stream));
380 return std::make_unique<MethodCall<EncodableValue>>(*method_name,
381 std::move(arguments));
382 }

References flutter::StandardCodecSerializer::ReadValue().

## ◆ EncodeErrorEnvelopeInternal()

std::unique_ptr< std::vector< uint8_t > > flutter::StandardMethodCodec::EncodeErrorEnvelopeInternal | ( | const std::string & | error_code,
|  | const std::string & | error_message,
|  | const EncodableValue * | error_details
| ) |  | const
| overrideprotectedvirtual

Implements flutter::MethodCodec< EncodableValue >.

Definition at line 413 of file standard_codec.cc.

416 {
417 auto encoded = std::make_unique<std::vector<uint8_t>>();
418 ByteBufferStreamWriter stream(encoded.get());
419 stream.WriteByte(1);
420 serializer_->WriteValue(EncodableValue(error_code), &stream);
421 if (error_message.empty()) {
422 serializer_->WriteValue(EncodableValue(), &stream);
423 } else {
424 serializer_->WriteValue(EncodableValue(error_message), &stream);
425 }
426 if (error_details) {
427 serializer_->WriteValue(*error_details, &stream);
428 } else {
429 serializer_->WriteValue(EncodableValue(), &stream);
430 }
431 return encoded;
432 }
flutter::StandardCodecSerializer::WriteValue
virtual void WriteValue(const EncodableValue &value, ByteStreamWriter *stream) const
Definition: standard_codec.cc:98

References flutter::StandardCodecSerializer::WriteValue().

## ◆ EncodeMethodCallInternal()

std::unique_ptr< std::vector< uint8_t > > flutter::StandardMethodCodec::EncodeMethodCallInternal | ( | const MethodCall< EncodableValue > & | method_call | ) | const
| overrideprotectedvirtual

Implements flutter::MethodCodec< EncodableValue >.

Definition at line 385 of file standard_codec.cc.

386 {
387 auto encoded = std::make_unique<std::vector<uint8_t>>();
388 ByteBufferStreamWriter stream(encoded.get());
389 serializer_->WriteValue(EncodableValue(method_call.method_name()), &stream);
390 if (method_call.arguments()) {
391 serializer_->WriteValue(*method_call.arguments(), &stream);
392 } else {
393 serializer_->WriteValue(EncodableValue(), &stream);
394 }
395 return encoded;
396 }

References flutter::MethodCall< T >::arguments(), flutter::MethodCall< T >::method_name(), and flutter::StandardCodecSerializer::WriteValue().

## ◆ EncodeSuccessEnvelopeInternal()

std::unique_ptr< std::vector< uint8_t > > flutter::StandardMethodCodec::EncodeSuccessEnvelopeInternal | ( | const EncodableValue * | result | ) | const
| overrideprotectedvirtual

Implements flutter::MethodCodec< EncodableValue >.

Definition at line 399 of file standard_codec.cc.

400 {
401 auto encoded = std::make_unique<std::vector<uint8_t>>();
402 ByteBufferStreamWriter stream(encoded.get());
403 stream.WriteByte(0);
404 if (result) {
405 serializer_->WriteValue(*result, &stream);
406 } else {
407 serializer_->WriteValue(EncodableValue(), &stream);
408 }
409 return encoded;
410 }

References flutter::StandardCodecSerializer::WriteValue().

## ◆ GetInstance()

const StandardMethodCodec & flutter::StandardMethodCodec::GetInstance | ( | const StandardCodecSerializer * | serializer = `nullptr` | ) |
| static

Definition at line 341 of file standard_codec.cc.

342 {
343 if (!serializer) {
344 serializer = &StandardCodecSerializer::GetInstance();
345 }
346 static auto* sInstances = new std::map<const StandardCodecSerializer*,
347 std::unique_ptr<StandardMethodCodec>>;
348 auto it = sInstances->find(serializer);
349 if (it == sInstances->end()) {
350 // Uses new due to private constructor (to prevent API clients from
351 // accidentally passing temporary codec instances to channels).
352 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
353 auto emplace_result = sInstances->emplace(
354 serializer, std::unique_ptr<StandardMethodCodec>(
355 new StandardMethodCodec(serializer)));
356 it = emplace_result.first;
357 }
358 return *(it->second);
359 }
flutter::StandardCodecSerializer::GetInstance
static const StandardCodecSerializer & GetInstance()
Definition: standard_codec.cc:87
flutter::StandardMethodCodec::StandardMethodCodec
StandardMethodCodec(StandardMethodCodec const &)=delete

References flutter::StandardCodecSerializer::GetInstance(), and StandardMethodCodec().

Referenced by flutter::internal::ResizeChannel(), flutter::internal::SetChannelWarnsOnOverflow(), and flutter::TEST().

## ◆ operator=()

StandardMethodCodec& flutter::StandardMethodCodec::operator= | ( | StandardMethodCodec const & |  | ) |
| delete

The documentation for this class was generated from the following files:

- shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h
- shell/platform/common/client_wrapper/standard_codec.cc