| Flutter macOS Embedder |

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

`#include <standard_codec_serializer.h>`

## Public Member Functions
virtual | ~StandardCodecSerializer ()
| StandardCodecSerializer (StandardCodecSerializer const &)=delete
StandardCodecSerializer & | operator= (StandardCodecSerializer const &)=delete
EncodableValue | ReadValue (ByteStreamReader *stream) const
virtual void | WriteValue (const EncodableValue &value, ByteStreamWriter *stream) const

## Static Public Member Functions
static const StandardCodecSerializer & | GetInstance ()

## 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 87 of file standard_codec.cc.

87 {
88 static StandardCodecSerializer sInstance;
89 return sInstance;
90 };

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

## ◆ operator=()

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

## ◆ ReadSize()

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

Definition at line 229 of file standard_codec.cc.

229 {
230 uint8_t byte = stream->ReadByte();
231 if (byte < 254) {
232 return byte;
233 } else if (byte == 254) {
234 uint16_t value = 0;
235 stream->ReadBytes(reinterpret_cast<uint8_t*>(&value), 2);
236 return value;
237 } else {
238 uint32_t value = 0;
239 stream->ReadBytes(reinterpret_cast<uint8_t*>(&value), 4);
240 return value;
241 }
242 }

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

Referenced by ReadValueOfType().

## ◆ ReadValue()

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

Definition at line 92 of file standard_codec.cc.

93 {
94 uint8_t type = stream->ReadByte();
95 return ReadValueOfType(type, stream);
96 }

References flutter::ByteStreamReader::ReadByte(), and ReadValueOfType().

Referenced by flutter::StandardMethodCodec::DecodeAndProcessResponseEnvelopeInternal(), flutter::StandardMessageCodec::DecodeMessageInternal(), flutter::StandardMethodCodec::DecodeMethodCallInternal(), and ReadValueOfType().

## ◆ ReadValueOfType()

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

Definition at line 168 of file standard_codec.cc.

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

References flutter::ByteStreamReader::ReadAlignment(), flutter::ByteStreamReader::ReadBytes(), flutter::ByteStreamReader::ReadDouble(), flutter::ByteStreamReader::ReadInt32(), flutter::ByteStreamReader::ReadInt64(), ReadSize(), and ReadValue().

Referenced by ReadValue().

## ◆ WriteSize()

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

Definition at line 244 of file standard_codec.cc.

245 {
246 if (size < 254) {
247 stream->WriteByte(static_cast<uint8_t>(size));
248 } else if (size <= 0xffff) {
249 stream->WriteByte(254);
250 uint16_t value = static_cast<uint16_t>(size);
251 stream->WriteBytes(reinterpret_cast<uint8_t*>(&value), 2);
252 } else {
253 stream->WriteByte(255);
254 uint32_t value = static_cast<uint32_t>(size);
255 stream->WriteBytes(reinterpret_cast<uint8_t*>(&value), 4);
256 }
257 }

References flutter::ByteStreamWriter::WriteByte(), and flutter::ByteStreamWriter::WriteBytes().

Referenced by WriteValue().

## ◆ WriteValue()

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

Definition at line 98 of file standard_codec.cc.

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

References flutter::ByteStreamWriter::WriteAlignment(), flutter::ByteStreamWriter::WriteByte(), flutter::ByteStreamWriter::WriteBytes(), flutter::ByteStreamWriter::WriteDouble(), flutter::ByteStreamWriter::WriteInt32(), flutter::ByteStreamWriter::WriteInt64(), and WriteSize().

Referenced by flutter::StandardMethodCodec::EncodeErrorEnvelopeInternal(), flutter::StandardMessageCodec::EncodeMessageInternal(), flutter::StandardMethodCodec::EncodeMethodCallInternal(), and flutter::StandardMethodCodec::EncodeSuccessEnvelopeInternal().

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

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

flutter::StandardCodecSerializer::ReadValue
EncodableValue ReadValue(ByteStreamReader *stream) const
Definition: standard_codec.cc:92
flutter::StandardCodecSerializer::ReadValueOfType
virtual EncodableValue ReadValueOfType(uint8_t type, ByteStreamReader *stream) const
Definition: standard_codec.cc:168
flutter::StandardCodecSerializer::WriteValue
virtual void WriteValue(const EncodableValue &value, ByteStreamWriter *stream) const
Definition: standard_codec.cc:98
flutter::StandardCodecSerializer::ReadSize
size_t ReadSize(ByteStreamReader *stream) const
Definition: standard_codec.cc:229
flutter::StandardCodecSerializer::StandardCodecSerializer
StandardCodecSerializer()
flutter::EncodableList
std::vector< EncodableValue > EncodableList
Definition: encodable_value.h:94
flutter::StandardCodecSerializer::WriteSize
void WriteSize(size_t size, ByteStreamWriter *stream) const
Definition: standard_codec.cc:244
flutter::EncodableMap
std::map< EncodableValue, EncodableValue > EncodableMap
Definition: encodable_value.h:95