Flutter Engine
flutter::StandardMessageCodec Class Reference

#include <standard_message_codec.h>

Inheritance diagram for flutter::StandardMessageCodec:
flutter::MessageCodec< EncodableValue >

Public Member Functions

 ~StandardMessageCodec ()
 
 StandardMessageCodec (StandardMessageCodec const &)=delete
 
StandardMessageCodecoperator= (StandardMessageCodec const &)=delete
 
- Public Member Functions inherited from flutter::MessageCodec< EncodableValue >
 MessageCodec ()=default
 
 MessageCodec (MessageCodec< EncodableValue > const &)=delete
 
virtual ~MessageCodec ()=default
 
MessageCodecoperator= (MessageCodec< EncodableValue > const &)=delete
 
std::unique_ptr< EncodableValueDecodeMessage (const uint8_t *binary_message, const size_t message_size) const
 
std::unique_ptr< EncodableValueDecodeMessage (const std::vector< uint8_t > &binary_message) const
 
std::unique_ptr< std::vector< uint8_t > > EncodeMessage (const EncodableValue &message) const
 

Static Public Member Functions

static const StandardMessageCodecGetInstance (const StandardCodecSerializer *serializer=nullptr)
 

Protected Member Functions

std::unique_ptr< EncodableValueDecodeMessageInternal (const uint8_t *binary_message, const size_t message_size) const override
 
std::unique_ptr< std::vector< uint8_t > > EncodeMessageInternal (const EncodableValue &message) const override
 

Detailed Description

Definition at line 18 of file standard_message_codec.h.

Constructor & Destructor Documentation

◆ ~StandardMessageCodec()

flutter::StandardMessageCodec::~StandardMessageCodec ( )
default

Referenced by GetInstance().

◆ StandardMessageCodec()

flutter::StandardMessageCodec::StandardMessageCodec ( StandardMessageCodec const &  )
delete

Referenced by GetInstance().

Member Function Documentation

◆ DecodeMessageInternal()

std::unique_ptr< EncodableValue > flutter::StandardMessageCodec::DecodeMessageInternal ( const uint8_t *  binary_message,
const size_t  message_size 
) const
overrideprotectedvirtual

Implements flutter::MessageCodec< EncodableValue >.

Definition at line 308 of file standard_codec.cc.

310  {
311  ByteBufferStreamReader stream(binary_message, message_size);
312  return std::make_unique<EncodableValue>(serializer_->ReadValue(&stream));
313 }
EncodableValue ReadValue(ByteStreamReader *stream) const

◆ EncodeMessageInternal()

std::unique_ptr< std::vector< uint8_t > > flutter::StandardMessageCodec::EncodeMessageInternal ( const EncodableValue message) const
overrideprotectedvirtual

Implements flutter::MessageCodec< EncodableValue >.

Definition at line 316 of file standard_codec.cc.

317  {
318  auto encoded = std::make_unique<std::vector<uint8_t>>();
319  ByteBufferStreamWriter stream(encoded.get());
320  serializer_->WriteValue(message, &stream);
321  return encoded;
322 }
virtual void WriteValue(const EncodableValue &value, ByteStreamWriter *stream) const

◆ GetInstance()

const StandardMessageCodec & flutter::StandardMessageCodec::GetInstance ( const StandardCodecSerializer serializer = nullptr)
static

Definition at line 283 of file standard_codec.cc.

References flutter::StandardCodecSerializer::GetInstance(), StandardMessageCodec(), and ~StandardMessageCodec().

Referenced by flutter::CheckEncodeDecode(), flutter::CheckEncodeDecodeWithEncodePrefix(), and flutter::TEST().

284  {
285  if (!serializer) {
286  serializer = &StandardCodecSerializer::GetInstance();
287  }
288  auto* sInstances = new std::map<const StandardCodecSerializer*,
289  std::unique_ptr<StandardMessageCodec>>;
290  auto it = sInstances->find(serializer);
291  if (it == sInstances->end()) {
292  // Uses new due to private constructor (to prevent API clients from
293  // accidentally passing temporary codec instances to channels).
294  auto emplace_result = sInstances->emplace(
295  serializer, std::unique_ptr<StandardMessageCodec>(
296  new StandardMessageCodec(serializer)));
297  it = emplace_result.first;
298  }
299  return *(it->second);
300 }
StandardMessageCodec(StandardMessageCodec const &)=delete
static const StandardCodecSerializer & GetInstance()

◆ operator=()

StandardMessageCodec& flutter::StandardMessageCodec::operator= ( StandardMessageCodec const &  )
delete

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