Flutter Engine
flutter::StandardCodecSerializer Class Reference

#include <standard_codec_serializer.h>

Inheritance diagram for flutter::StandardCodecSerializer:
flutter::PointExtensionSerializer flutter::SomeDataExtensionSerializer

Public Member Functions

virtual ~StandardCodecSerializer ()
 
 StandardCodecSerializer (StandardCodecSerializer const &)=delete
 
StandardCodecSerializeroperator= (StandardCodecSerializer const &)=delete
 
EncodableValue ReadValue (ByteStreamReader *stream) const
 
virtual void WriteValue (const EncodableValue &value, ByteStreamWriter *stream) const
 

Static Public Member Functions

static const StandardCodecSerializerGetInstance ()
 

Protected Member Functions

 StandardCodecSerializer ()
 
virtual EncodableValue ReadValueOfType (uint8_t type, ByteStreamReader *stream) const
 
size_t ReadSize (ByteStreamReader *stream) const
 
void WriteSize (size_t size, ByteStreamWriter *stream) const
 

Detailed Description

Definition at line 18 of file standard_codec_serializer.h.

Constructor & Destructor Documentation

◆ ~StandardCodecSerializer()

flutter::StandardCodecSerializer::~StandardCodecSerializer ( )
virtualdefault

◆ StandardCodecSerializer() [1/2]

flutter::StandardCodecSerializer::StandardCodecSerializer ( StandardCodecSerializer const &  )
delete

◆ StandardCodecSerializer() [2/2]

flutter::StandardCodecSerializer::StandardCodecSerializer ( )
protecteddefault

Member Function Documentation

◆ GetInstance()

const StandardCodecSerializer & flutter::StandardCodecSerializer::GetInstance ( )
static

Definition at line 84 of file standard_codec.cc.

Referenced by flutter::StandardMessageCodec::GetInstance(), and flutter::StandardMethodCodec::GetInstance().

84  {
85  static StandardCodecSerializer sInstance;
86  return sInstance;
87 };

◆ operator=()

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

◆ ReadSize()

size_t flutter::StandardCodecSerializer::ReadSize ( ByteStreamReader stream) const
protected

Definition at line 219 of file standard_codec.cc.

References flutter::ByteStreamReader::ReadByte(), flutter::ByteStreamReader::ReadBytes(), and value.

Referenced by flutter::SomeDataExtensionSerializer::ReadValueOfType().

219  {
220  uint8_t byte = stream->ReadByte();
221  if (byte < 254) {
222  return byte;
223  } else if (byte == 254) {
224  uint16_t value;
225  stream->ReadBytes(reinterpret_cast<uint8_t*>(&value), 2);
226  return value;
227  } else {
228  uint32_t value;
229  stream->ReadBytes(reinterpret_cast<uint8_t*>(&value), 4);
230  return value;
231  }
232 }
uint8_t value

◆ ReadValue()

EncodableValue flutter::StandardCodecSerializer::ReadValue ( ByteStreamReader stream) const

Definition at line 89 of file standard_codec.cc.

References flutter::ByteStreamReader::ReadByte().

Referenced by flutter::SomeDataExtensionSerializer::ReadValueOfType().

90  {
91  uint8_t type = stream->ReadByte();
92  return ReadValueOfType(type, stream);
93 }
virtual EncodableValue ReadValueOfType(uint8_t type, ByteStreamReader *stream) const

◆ ReadValueOfType()

EncodableValue flutter::StandardCodecSerializer::ReadValueOfType ( uint8_t  type,
ByteStreamReader stream 
) const
protectedvirtual

Reimplemented in flutter::SomeDataExtensionSerializer, and flutter::PointExtensionSerializer.

Definition at line 161 of file standard_codec.cc.

References length, flutter::ByteStreamReader::ReadAlignment(), flutter::ByteStreamReader::ReadBytes(), flutter::ByteStreamReader::ReadDouble(), flutter::ByteStreamReader::ReadInt32(), flutter::ByteStreamReader::ReadInt64(), fml::size(), and value.

Referenced by flutter::PointExtensionSerializer::ReadValueOfType(), and flutter::SomeDataExtensionSerializer::ReadValueOfType().

163  {
164  switch (static_cast<EncodedType>(type)) {
165  case EncodedType::kNull:
166  return EncodableValue();
167  case EncodedType::kTrue:
168  return EncodableValue(true);
169  case EncodedType::kFalse:
170  return EncodableValue(false);
171  case EncodedType::kInt32:
172  return EncodableValue(stream->ReadInt32());
173  case EncodedType::kInt64:
174  return EncodableValue(stream->ReadInt64());
175  case EncodedType::kFloat64:
176  stream->ReadAlignment(8);
177  return EncodableValue(stream->ReadDouble());
178  case EncodedType::kLargeInt:
179  case EncodedType::kString: {
180  size_t size = ReadSize(stream);
181  std::string string_value;
182  string_value.resize(size);
183  stream->ReadBytes(reinterpret_cast<uint8_t*>(&string_value[0]), size);
184  return EncodableValue(string_value);
185  }
186  case EncodedType::kUInt8List:
187  return ReadVector<uint8_t>(stream);
188  case EncodedType::kInt32List:
189  return ReadVector<int32_t>(stream);
190  case EncodedType::kInt64List:
191  return ReadVector<int64_t>(stream);
192  case EncodedType::kFloat64List:
193  return ReadVector<double>(stream);
194  case EncodedType::kList: {
195  size_t length = ReadSize(stream);
196  EncodableList list_value;
197  list_value.reserve(length);
198  for (size_t i = 0; i < length; ++i) {
199  list_value.push_back(ReadValue(stream));
200  }
201  return EncodableValue(list_value);
202  }
203  case EncodedType::kMap: {
204  size_t length = ReadSize(stream);
205  EncodableMap map_value;
206  for (size_t i = 0; i < length; ++i) {
207  EncodableValue key = ReadValue(stream);
208  EncodableValue value = ReadValue(stream);
209  map_value.emplace(std::move(key), std::move(value));
210  }
211  return EncodableValue(map_value);
212  }
213  }
214  std::cerr << "Unknown type in StandardCodecSerializer::ReadValueOfType: "
215  << static_cast<int>(type) << std::endl;
216  return EncodableValue();
217 }
size_t ReadSize(ByteStreamReader *stream) const
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
EncodableValue ReadValue(ByteStreamReader *stream) const
uint8_t value
size_t length
std::vector< EncodableValue > EncodableList
std::map< EncodableValue, EncodableValue > EncodableMap

◆ WriteSize()

void flutter::StandardCodecSerializer::WriteSize ( size_t  size,
ByteStreamWriter stream 
) const
protected

Definition at line 234 of file standard_codec.cc.

References flutter::ByteStreamReader::ReadAlignment(), flutter::ByteStreamReader::ReadBytes(), fml::size(), value, flutter::ByteStreamWriter::WriteAlignment(), flutter::ByteStreamWriter::WriteByte(), and flutter::ByteStreamWriter::WriteBytes().

Referenced by flutter::SomeDataExtensionSerializer::WriteValue().

235  {
236  if (size < 254) {
237  stream->WriteByte(static_cast<uint8_t>(size));
238  } else if (size <= 0xffff) {
239  stream->WriteByte(254);
240  uint16_t value = static_cast<uint16_t>(size);
241  stream->WriteBytes(reinterpret_cast<uint8_t*>(&value), 2);
242  } else {
243  stream->WriteByte(255);
244  uint32_t value = static_cast<uint32_t>(size);
245  stream->WriteBytes(reinterpret_cast<uint8_t*>(&value), 4);
246  }
247 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
uint8_t value

◆ WriteValue()

void flutter::StandardCodecSerializer::WriteValue ( const EncodableValue value,
ByteStreamWriter stream 
) const
virtual

Reimplemented in flutter::SomeDataExtensionSerializer, and flutter::PointExtensionSerializer.

Definition at line 95 of file standard_codec.cc.

References fml::size(), value, flutter::ByteStreamWriter::WriteAlignment(), flutter::ByteStreamWriter::WriteByte(), flutter::ByteStreamWriter::WriteBytes(), flutter::ByteStreamWriter::WriteDouble(), flutter::ByteStreamWriter::WriteInt32(), and flutter::ByteStreamWriter::WriteInt64().

Referenced by flutter::PointExtensionSerializer::WriteValue(), and flutter::SomeDataExtensionSerializer::WriteValue().

96  {
97  stream->WriteByte(static_cast<uint8_t>(EncodedTypeForValue(value)));
98  // TODO: Consider replacing this this with a std::visitor.
99  switch (value.index()) {
100  case 0:
101  case 1:
102  // Null and bool are encoded directly in the type.
103  break;
104  case 2:
105  stream->WriteInt32(std::get<int32_t>(value));
106  break;
107  case 3:
108  stream->WriteInt64(std::get<int64_t>(value));
109  break;
110  case 4:
111  stream->WriteAlignment(8);
112  stream->WriteDouble(std::get<double>(value));
113  break;
114  case 5: {
115  const auto& string_value = std::get<std::string>(value);
116  size_t size = string_value.size();
117  WriteSize(size, stream);
118  if (size > 0) {
119  stream->WriteBytes(
120  reinterpret_cast<const uint8_t*>(string_value.data()), size);
121  }
122  break;
123  }
124  case 6:
125  WriteVector(std::get<std::vector<uint8_t>>(value), stream);
126  break;
127  case 7:
128  WriteVector(std::get<std::vector<int32_t>>(value), stream);
129  break;
130  case 8:
131  WriteVector(std::get<std::vector<int64_t>>(value), stream);
132  break;
133  case 9:
134  WriteVector(std::get<std::vector<double>>(value), stream);
135  break;
136  case 10: {
137  const auto& list = std::get<EncodableList>(value);
138  WriteSize(list.size(), stream);
139  for (const auto& item : list) {
140  WriteValue(item, stream);
141  }
142  break;
143  }
144  case 11: {
145  const auto& map = std::get<EncodableMap>(value);
146  WriteSize(map.size(), stream);
147  for (const auto& pair : map) {
148  WriteValue(pair.first, stream);
149  WriteValue(pair.second, stream);
150  }
151  break;
152  }
153  case 12:
154  std::cerr
155  << "Unhandled custom type in StandardCodecSerializer::WriteValue. "
156  << "Custom types require codec extensions." << std::endl;
157  break;
158  }
159 }
virtual void WriteValue(const EncodableValue &value, ByteStreamWriter *stream) const
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
uint8_t value
void WriteSize(size_t size, ByteStreamWriter *stream) const

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