Flutter Engine
fml::Message Class Reference

#include <message.h>

Public Member Functions

 Message ()
 
 ~Message ()
 
const uint8_t * GetBuffer () const
 
size_t GetBufferSize () const
 
size_t GetDataLength () const
 
size_t GetSizeRead () const
 
void ResetRead ()
 
template<typename T , typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
bool Encode (const T &value)
 
bool Encode (const MessageSerializable &value)
 
template<typename Traits , typename T , typename = std::enable_if_t< std::is_base_of<MessageSerializable, T>::value>>
bool Encode (const std::unique_ptr< T > &value)
 
template<typename T , typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
bool Decode (T &value)
 
bool Decode (MessageSerializable &value)
 
template<typename Traits , typename T , typename = std::enable_if_t< std::is_base_of<MessageSerializable, T>::value>>
bool Decode (std::unique_ptr< T > &value)
 

Detailed Description

Definition at line 70 of file message.h.

Constructor & Destructor Documentation

◆ Message()

fml::Message::Message ( )
default

◆ ~Message()

fml::Message::~Message ( )
default

Member Function Documentation

◆ Decode() [1/3]

template<typename T , typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
bool fml::Message::Decode ( T &  value)
inline

Definition at line 133 of file message.h.

Referenced by fml::TEST().

133  {
134  if (auto* buffer = PrepareDecode(sizeof(T))) {
135  ::memcpy(&value, buffer, sizeof(T));
136  return true;
137  }
138  return false;
139  }
uint8_t value

◆ Decode() [2/3]

bool fml::Message::Decode ( MessageSerializable value)
inline

Definition at line 141 of file message.h.

References fml::MessageSerializable::Deserialize(), and value.

141  {
142  return value.Deserialize(*this);
143  }
uint8_t value

◆ Decode() [3/3]

template<typename Traits , typename T , typename = std::enable_if_t< std::is_base_of<MessageSerializable, T>::value>>
bool fml::Message::Decode ( std::unique_ptr< T > &  value)
inline

Definition at line 149 of file message.h.

References FML_DISALLOW_COPY_AND_ASSIGN, fml::size(), and fml::swap().

149  {
150  // Decode if null.
151  bool is_null = false;
152  if (!Decode(is_null)) {
153  return false;
154  }
155 
156  if (is_null) {
157  return true;
158  }
159 
160  // Decode type.
161  size_t tag = 0;
162  if (!Decode(tag)) {
163  return false;
164  }
165 
166  std::unique_ptr<T> new_value = Traits::CreateForSerializableTag(tag);
167  if (!new_value) {
168  return false;
169  }
170 
171  // Decode value.
172  if (!Decode(*new_value.get())) {
173  return false;
174  }
175 
176  std::swap(value, new_value);
177 
178  return true;
179  }
bool Decode(T &value)
Definition: message.h:133
void swap(scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
uint8_t value

◆ Encode() [1/3]

template<typename T , typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
bool fml::Message::Encode ( const T &  value)
inline

Definition at line 90 of file message.h.

Referenced by fml::TEST().

90  {
91  if (auto* buffer = PrepareEncode(sizeof(T))) {
92  ::memcpy(buffer, &value, sizeof(T));
93  return true;
94  }
95  return false;
96  }
uint8_t value

◆ Encode() [2/3]

bool fml::Message::Encode ( const MessageSerializable value)
inline

Definition at line 98 of file message.h.

References fml::MessageSerializable::Serialize(), and value.

98  {
99  return value.Serialize(*this);
100  }
uint8_t value

◆ Encode() [3/3]

template<typename Traits , typename T , typename = std::enable_if_t< std::is_base_of<MessageSerializable, T>::value>>
bool fml::Message::Encode ( const std::unique_ptr< T > &  value)
inline

Definition at line 106 of file message.h.

References value.

106  {
107  // Encode if null.
108  if (!Encode(static_cast<bool>(value))) {
109  return false;
110  }
111 
112  if (!value) {
113  return true;
114  }
115 
116  // Encode the type.
117  if (!Encode(Traits::GetSerializableTag(*value.get()))) {
118  return false;
119  }
120 
121  // Encode the value.
122  if (!Encode(*value.get())) {
123  return false;
124  }
125 
126  return true;
127  }
uint8_t value
bool Encode(const T &value)
Definition: message.h:90

◆ GetBuffer()

const uint8_t * fml::Message::GetBuffer ( ) const

Definition at line 35 of file message.cc.

35  {
36  return buffer_;
37 }

◆ GetBufferSize()

size_t fml::Message::GetBufferSize ( ) const

Definition at line 39 of file message.cc.

Referenced by fml::TEST().

39  {
40  return buffer_length_;
41 }

◆ GetDataLength()

size_t fml::Message::GetDataLength ( ) const

Definition at line 43 of file message.cc.

Referenced by fml::TEST().

43  {
44  return data_length_;
45 }

◆ GetSizeRead()

size_t fml::Message::GetSizeRead ( ) const

Definition at line 47 of file message.cc.

References FML_DCHECK, fml::NextPowerOfTwoSize(), and fml::size().

Referenced by fml::TEST().

47  {
48  return size_read_;
49 }

◆ ResetRead()

void fml::Message::ResetRead ( )

Definition at line 108 of file message.cc.

108  {
109  size_read_ = 0;
110 }

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