Flutter Engine
fl_standard_message_codec.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"
6 #include "flutter/shell/platform/linux/fl_standard_message_codec_private.h"
7 
8 #include <gmodule.h>
9 
10 #include <cstring>
11 
12 // See lib/src/services/message_codecs.dart in Flutter source for description of
13 // encoding.
14 
15 // Type values.
16 static constexpr int kValueNull = 0;
17 static constexpr int kValueTrue = 1;
18 static constexpr int kValueFalse = 2;
19 static constexpr int kValueInt32 = 3;
20 static constexpr int kValueInt64 = 4;
21 static constexpr int kValueFloat64 = 6;
22 static constexpr int kValueString = 7;
23 static constexpr int kValueUint8List = 8;
24 static constexpr int kValueInt32List = 9;
25 static constexpr int kValueInt64List = 10;
26 static constexpr int kValueFloat64List = 11;
27 static constexpr int kValueList = 12;
28 static constexpr int kValueMap = 13;
29 
31  FlMessageCodec parent_instance;
32 };
33 
34 G_DEFINE_TYPE(FlStandardMessageCodec,
35  fl_standard_message_codec,
37 
38 // Functions to write standard C number types.
39 
40 static void write_uint8(GByteArray* buffer, uint8_t value) {
41  g_byte_array_append(buffer, &value, sizeof(uint8_t));
42 }
43 
44 static void write_uint16(GByteArray* buffer, uint16_t value) {
45  g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
46  sizeof(uint16_t));
47 }
48 
49 static void write_uint32(GByteArray* buffer, uint32_t value) {
50  g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
51  sizeof(uint32_t));
52 }
53 
54 static void write_int32(GByteArray* buffer, int32_t value) {
55  g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
56  sizeof(int32_t));
57 }
58 
59 static void write_int64(GByteArray* buffer, int64_t value) {
60  g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
61  sizeof(int64_t));
62 }
63 
64 static void write_float64(GByteArray* buffer, double value) {
65  g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
66  sizeof(double));
67 }
68 
69 // Write padding bytes to align to @align multiple of bytes.
70 static void write_align(GByteArray* buffer, guint align) {
71  while (buffer->len % align != 0) {
72  write_uint8(buffer, 0);
73  }
74 }
75 
76 // Checks there is enough data in @buffer to be read.
77 static gboolean check_size(GBytes* buffer,
78  size_t offset,
79  size_t required,
80  GError** error) {
81  if (offset + required > g_bytes_get_size(buffer)) {
82  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
83  FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, "Unexpected end of data");
84  return FALSE;
85  }
86  return TRUE;
87 }
88 
89 // Skip bytes to align next read on @align multiple of bytes.
90 static gboolean read_align(GBytes* buffer,
91  size_t* offset,
92  size_t align,
93  GError** error) {
94  if ((*offset) % align == 0) {
95  return TRUE;
96  }
97 
98  size_t required = align - (*offset) % align;
99  if (!check_size(buffer, *offset, required, error)) {
100  return FALSE;
101  }
102 
103  (*offset) += required;
104  return TRUE;
105 }
106 
107 // Gets a pointer to the given offset in @buffer.
108 static const uint8_t* get_data(GBytes* buffer, size_t* offset) {
109  return static_cast<const uint8_t*>(g_bytes_get_data(buffer, nullptr)) +
110  *offset;
111 }
112 
113 // Reads an unsigned 8 bit number from @buffer and writes it to @value.
114 // Returns TRUE if successful, otherwise sets an error.
115 static gboolean read_uint8(GBytes* buffer,
116  size_t* offset,
117  uint8_t* value,
118  GError** error) {
119  if (!check_size(buffer, *offset, sizeof(uint8_t), error)) {
120  return FALSE;
121  }
122 
123  *value = get_data(buffer, offset)[0];
124  (*offset)++;
125  return TRUE;
126 }
127 
128 // Reads an unsigned 16 bit integer from @buffer and writes it to @value.
129 // Returns TRUE if successful, otherwise sets an error.
130 static gboolean read_uint16(GBytes* buffer,
131  size_t* offset,
132  uint16_t* value,
133  GError** error) {
134  if (!check_size(buffer, *offset, sizeof(uint16_t), error)) {
135  return FALSE;
136  }
137 
138  *value = reinterpret_cast<const uint16_t*>(get_data(buffer, offset))[0];
139  *offset += sizeof(uint16_t);
140  return TRUE;
141 }
142 
143 // Reads an unsigned 32 bit integer from @buffer and writes it to @value.
144 // Returns TRUE if successful, otherwise sets an error.
145 static gboolean read_uint32(GBytes* buffer,
146  size_t* offset,
147  uint32_t* value,
148  GError** error) {
149  if (!check_size(buffer, *offset, sizeof(uint32_t), error)) {
150  return FALSE;
151  }
152 
153  *value = reinterpret_cast<const uint32_t*>(get_data(buffer, offset))[0];
154  *offset += sizeof(uint32_t);
155  return TRUE;
156 }
157 
158 // Reads a #FL_VALUE_TYPE_INT stored as a signed 32 bit integer from @buffer.
159 // Returns a new #FlValue of type #FL_VALUE_TYPE_INT if successful or %NULL on
160 // error.
161 static FlValue* read_int32_value(GBytes* buffer,
162  size_t* offset,
163  GError** error) {
164  if (!check_size(buffer, *offset, sizeof(int32_t), error)) {
165  return nullptr;
166  }
167 
169  reinterpret_cast<const int32_t*>(get_data(buffer, offset))[0]);
170  *offset += sizeof(int32_t);
171  return value;
172 }
173 
174 // Reads a #FL_VALUE_TYPE_INT stored as a signed 64 bit integer from @buffer.
175 // Returns a new #FlValue of type #FL_VALUE_TYPE_INT if successful or %NULL on
176 // error.
177 static FlValue* read_int64_value(GBytes* buffer,
178  size_t* offset,
179  GError** error) {
180  if (!check_size(buffer, *offset, sizeof(int64_t), error)) {
181  return nullptr;
182  }
183 
185  reinterpret_cast<const int64_t*>(get_data(buffer, offset))[0]);
186  *offset += sizeof(int64_t);
187  return value;
188 }
189 
190 // Reads a 64 bit floating point number from @buffer and writes it to @value.
191 // Returns a new #FlValue of type #FL_VALUE_TYPE_FLOAT if successful or %NULL on
192 // error.
193 static FlValue* read_float64_value(GBytes* buffer,
194  size_t* offset,
195  GError** error) {
196  if (!read_align(buffer, offset, 8, error)) {
197  return nullptr;
198  }
199  if (!check_size(buffer, *offset, sizeof(double), error)) {
200  return nullptr;
201  }
202 
204  reinterpret_cast<const double*>(get_data(buffer, offset))[0]);
205  *offset += sizeof(double);
206  return value;
207 }
208 
209 // Reads an UTF-8 text string from @buffer in standard codec format.
210 // Returns a new #FlValue of type #FL_VALUE_TYPE_STRING if successful or %NULL
211 // on error.
212 static FlValue* read_string_value(FlStandardMessageCodec* self,
213  GBytes* buffer,
214  size_t* offset,
215  GError** error) {
216  uint32_t length;
217  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
218  error)) {
219  return nullptr;
220  }
221  if (!check_size(buffer, *offset, length, error)) {
222  return nullptr;
223  }
225  reinterpret_cast<const gchar*>(get_data(buffer, offset)), length);
226  *offset += length;
227  return value;
228 }
229 
230 // Reads an unsigned 8 bit list from @buffer in standard codec format.
231 // Returns a new #FlValue of type #FL_VALUE_TYPE_UINT8_LIST if successful or
232 // %NULL on error.
233 static FlValue* read_uint8_list_value(FlStandardMessageCodec* self,
234  GBytes* buffer,
235  size_t* offset,
236  GError** error) {
237  uint32_t length;
238  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
239  error)) {
240  return nullptr;
241  }
242  if (!check_size(buffer, *offset, sizeof(uint8_t) * length, error)) {
243  return nullptr;
244  }
245  FlValue* value = fl_value_new_uint8_list(get_data(buffer, offset), length);
246  *offset += length;
247  return value;
248 }
249 
250 // Reads a signed 32 bit list from @buffer in standard codec format.
251 // Returns a new #FlValue of type #FL_VALUE_TYPE_INT32_LIST if successful or
252 // %NULL on error.
253 static FlValue* read_int32_list_value(FlStandardMessageCodec* self,
254  GBytes* buffer,
255  size_t* offset,
256  GError** error) {
257  uint32_t length;
258  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
259  error)) {
260  return nullptr;
261  }
262  if (!read_align(buffer, offset, 4, error)) {
263  return nullptr;
264  }
265  if (!check_size(buffer, *offset, sizeof(int32_t) * length, error)) {
266  return nullptr;
267  }
269  reinterpret_cast<const int32_t*>(get_data(buffer, offset)), length);
270  *offset += sizeof(int32_t) * length;
271  return value;
272 }
273 
274 // Reads a signed 64 bit list from @buffer in standard codec format.
275 // Returns a new #FlValue of type #FL_VALUE_TYPE_INT64_LIST if successful or
276 // %NULL on error.
277 static FlValue* read_int64_list_value(FlStandardMessageCodec* self,
278  GBytes* buffer,
279  size_t* offset,
280  GError** error) {
281  uint32_t length;
282  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
283  error)) {
284  return nullptr;
285  }
286  if (!read_align(buffer, offset, 8, error)) {
287  return nullptr;
288  }
289  if (!check_size(buffer, *offset, sizeof(int64_t) * length, error)) {
290  return nullptr;
291  }
293  reinterpret_cast<const int64_t*>(get_data(buffer, offset)), length);
294  *offset += sizeof(int64_t) * length;
295  return value;
296 }
297 
298 // Reads a floating point number list from @buffer in standard codec format.
299 // Returns a new #FlValue of type #FL_VALUE_TYPE_FLOAT_LIST if successful or
300 // %NULL on error.
301 static FlValue* read_float64_list_value(FlStandardMessageCodec* self,
302  GBytes* buffer,
303  size_t* offset,
304  GError** error) {
305  uint32_t length;
306  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
307  error)) {
308  return nullptr;
309  }
310  if (!read_align(buffer, offset, 8, error)) {
311  return nullptr;
312  }
313  if (!check_size(buffer, *offset, sizeof(double) * length, error)) {
314  return nullptr;
315  }
317  reinterpret_cast<const double*>(get_data(buffer, offset)), length);
318  *offset += sizeof(double) * length;
319  return value;
320 }
321 
322 // Reads a list from @buffer in standard codec format.
323 // Returns a new #FlValue of type #FL_VALUE_TYPE_LIST if successful or %NULL on
324 // error.
325 static FlValue* read_list_value(FlStandardMessageCodec* self,
326  GBytes* buffer,
327  size_t* offset,
328  GError** error) {
329  uint32_t length;
330  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
331  error)) {
332  return nullptr;
333  }
334 
335  g_autoptr(FlValue) list = fl_value_new_list();
336  for (size_t i = 0; i < length; i++) {
337  g_autoptr(FlValue) child =
338  fl_standard_message_codec_read_value(self, buffer, offset, error);
339  if (child == nullptr) {
340  return nullptr;
341  }
342  fl_value_append(list, child);
343  }
344 
345  return fl_value_ref(list);
346 }
347 
348 // Reads a map from @buffer in standard codec format.
349 // Returns a new #FlValue of type #FL_VALUE_TYPE_MAP if successful or %NULL on
350 // error.
351 static FlValue* read_map_value(FlStandardMessageCodec* self,
352  GBytes* buffer,
353  size_t* offset,
354  GError** error) {
355  uint32_t length;
356  if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
357  error)) {
358  return nullptr;
359  }
360 
361  g_autoptr(FlValue) map = fl_value_new_map();
362  for (size_t i = 0; i < length; i++) {
363  g_autoptr(FlValue) key =
364  fl_standard_message_codec_read_value(self, buffer, offset, error);
365  if (key == nullptr) {
366  return nullptr;
367  }
368  g_autoptr(FlValue) value =
369  fl_standard_message_codec_read_value(self, buffer, offset, error);
370  if (value == nullptr) {
371  return nullptr;
372  }
373  fl_value_set(map, key, value);
374  }
375 
376  return fl_value_ref(map);
377 }
378 
379 // Implements FlMessageCodec::encode_message.
380 static GBytes* fl_standard_message_codec_encode_message(FlMessageCodec* codec,
381  FlValue* message,
382  GError** error) {
383  FlStandardMessageCodec* self =
384  reinterpret_cast<FlStandardMessageCodec*>(codec);
385 
386  g_autoptr(GByteArray) buffer = g_byte_array_new();
387  if (!fl_standard_message_codec_write_value(self, buffer, message, error)) {
388  return nullptr;
389  }
390  return g_byte_array_free_to_bytes(
391  static_cast<GByteArray*>(g_steal_pointer(&buffer)));
392 }
393 
394 // Implements FlMessageCodec::decode_message.
395 static FlValue* fl_standard_message_codec_decode_message(FlMessageCodec* codec,
396  GBytes* message,
397  GError** error) {
398  FlStandardMessageCodec* self =
399  reinterpret_cast<FlStandardMessageCodec*>(codec);
400 
401  size_t offset = 0;
402  g_autoptr(FlValue) value =
403  fl_standard_message_codec_read_value(self, message, &offset, error);
404  if (value == nullptr) {
405  return nullptr;
406  }
407 
408  if (offset != g_bytes_get_size(message)) {
409  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
411  "Unused %zi bytes after standard message",
412  g_bytes_get_size(message) - offset);
413  return nullptr;
414  }
415 
416  return fl_value_ref(value);
417 }
418 
420  FlStandardMessageCodecClass* klass) {
421  FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
423  FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
425 }
426 
427 static void fl_standard_message_codec_init(FlStandardMessageCodec* self) {}
428 
429 G_MODULE_EXPORT FlStandardMessageCodec* fl_standard_message_codec_new() {
430  return static_cast<FlStandardMessageCodec*>(
431  g_object_new(fl_standard_message_codec_get_type(), nullptr));
432 }
433 
434 void fl_standard_message_codec_write_size(FlStandardMessageCodec* codec,
435  GByteArray* buffer,
436  uint32_t size) {
437  if (size < 254) {
438  write_uint8(buffer, size);
439  } else if (size <= 0xffff) {
440  write_uint8(buffer, 254);
441  write_uint16(buffer, size);
442  } else {
443  write_uint8(buffer, 255);
444  write_uint32(buffer, size);
445  }
446 }
447 
448 gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec* codec,
449  GBytes* buffer,
450  size_t* offset,
451  uint32_t* value,
452  GError** error) {
453  uint8_t value8;
454  if (!read_uint8(buffer, offset, &value8, error)) {
455  return FALSE;
456  }
457 
458  if (value8 == 255) {
459  if (!read_uint32(buffer, offset, value, error)) {
460  return FALSE;
461  }
462  } else if (value8 == 254) {
463  uint16_t value16;
464  if (!read_uint16(buffer, offset, &value16, error)) {
465  return FALSE;
466  }
467  *value = value16;
468  } else {
469  *value = value8;
470  }
471 
472  return TRUE;
473 }
474 
475 gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* self,
476  GByteArray* buffer,
477  FlValue* value,
478  GError** error) {
479  if (value == nullptr) {
480  write_uint8(buffer, kValueNull);
481  return TRUE;
482  }
483 
484  switch (fl_value_get_type(value)) {
485  case FL_VALUE_TYPE_NULL:
486  write_uint8(buffer, kValueNull);
487  return TRUE;
488  case FL_VALUE_TYPE_BOOL:
489  if (fl_value_get_bool(value)) {
490  write_uint8(buffer, kValueTrue);
491  } else {
492  write_uint8(buffer, kValueFalse);
493  }
494  return TRUE;
495  case FL_VALUE_TYPE_INT: {
496  int64_t v = fl_value_get_int(value);
497  if (v >= INT32_MIN && v <= INT32_MAX) {
498  write_uint8(buffer, kValueInt32);
499  write_int32(buffer, v);
500  } else {
501  write_uint8(buffer, kValueInt64);
502  write_int64(buffer, v);
503  }
504  return TRUE;
505  }
506  case FL_VALUE_TYPE_FLOAT:
507  write_uint8(buffer, kValueFloat64);
508  write_align(buffer, 8);
509  write_float64(buffer, fl_value_get_float(value));
510  return TRUE;
511  case FL_VALUE_TYPE_STRING: {
512  write_uint8(buffer, kValueString);
513  const char* text = fl_value_get_string(value);
514  size_t length = strlen(text);
515  fl_standard_message_codec_write_size(self, buffer, length);
516  g_byte_array_append(buffer, reinterpret_cast<const uint8_t*>(text),
517  length);
518  return TRUE;
519  }
521  write_uint8(buffer, kValueUint8List);
522  size_t length = fl_value_get_length(value);
523  fl_standard_message_codec_write_size(self, buffer, length);
524  g_byte_array_append(buffer, fl_value_get_uint8_list(value),
525  sizeof(uint8_t) * length);
526  return TRUE;
527  }
529  write_uint8(buffer, kValueInt32List);
530  size_t length = fl_value_get_length(value);
531  fl_standard_message_codec_write_size(self, buffer, length);
532  write_align(buffer, 4);
533  g_byte_array_append(
534  buffer,
535  reinterpret_cast<const uint8_t*>(fl_value_get_int32_list(value)),
536  sizeof(int32_t) * length);
537  return TRUE;
538  }
540  write_uint8(buffer, kValueInt64List);
541  size_t length = fl_value_get_length(value);
542  fl_standard_message_codec_write_size(self, buffer, length);
543  write_align(buffer, 8);
544  g_byte_array_append(
545  buffer,
546  reinterpret_cast<const uint8_t*>(fl_value_get_int64_list(value)),
547  sizeof(int64_t) * length);
548  return TRUE;
549  }
551  write_uint8(buffer, kValueFloat64List);
552  size_t length = fl_value_get_length(value);
553  fl_standard_message_codec_write_size(self, buffer, length);
554  write_align(buffer, 8);
555  g_byte_array_append(
556  buffer,
557  reinterpret_cast<const uint8_t*>(fl_value_get_float_list(value)),
558  sizeof(double) * length);
559  return TRUE;
560  }
561  case FL_VALUE_TYPE_LIST:
562  write_uint8(buffer, kValueList);
564  fl_value_get_length(value));
565  for (size_t i = 0; i < fl_value_get_length(value); i++) {
567  self, buffer, fl_value_get_list_value(value, i), error)) {
568  return FALSE;
569  }
570  }
571  return TRUE;
572  case FL_VALUE_TYPE_MAP:
573  write_uint8(buffer, kValueMap);
575  fl_value_get_length(value));
576  for (size_t i = 0; i < fl_value_get_length(value); i++) {
578  self, buffer, fl_value_get_map_key(value, i), error) ||
580  self, buffer, fl_value_get_map_value(value, i), error)) {
581  return FALSE;
582  }
583  }
584  return TRUE;
585  }
586 
587  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
589  "Unexpected FlValue type %d", fl_value_get_type(value));
590  return FALSE;
591 }
592 
593 FlValue* fl_standard_message_codec_read_value(FlStandardMessageCodec* self,
594  GBytes* buffer,
595  size_t* offset,
596  GError** error) {
597  uint8_t type;
598  if (!read_uint8(buffer, offset, &type, error)) {
599  return nullptr;
600  }
601 
602  g_autoptr(FlValue) value = nullptr;
603  if (type == kValueNull) {
604  return fl_value_new_null();
605  } else if (type == kValueTrue) {
606  return fl_value_new_bool(TRUE);
607  } else if (type == kValueFalse) {
608  return fl_value_new_bool(FALSE);
609  } else if (type == kValueInt32) {
610  value = read_int32_value(buffer, offset, error);
611  } else if (type == kValueInt64) {
612  value = read_int64_value(buffer, offset, error);
613  } else if (type == kValueFloat64) {
614  value = read_float64_value(buffer, offset, error);
615  } else if (type == kValueString) {
616  value = read_string_value(self, buffer, offset, error);
617  } else if (type == kValueUint8List) {
618  value = read_uint8_list_value(self, buffer, offset, error);
619  } else if (type == kValueInt32List) {
620  value = read_int32_list_value(self, buffer, offset, error);
621  } else if (type == kValueInt64List) {
622  value = read_int64_list_value(self, buffer, offset, error);
623  } else if (type == kValueFloat64List) {
624  value = read_float64_list_value(self, buffer, offset, error);
625  } else if (type == kValueList) {
626  value = read_list_value(self, buffer, offset, error);
627  } else if (type == kValueMap) {
628  value = read_map_value(self, buffer, offset, error);
629  } else {
630  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
632  "Unexpected standard codec type %02x", type);
633  return nullptr;
634  }
635 
636  return value == nullptr ? nullptr : fl_value_ref(value);
637 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
static constexpr int kValueInt32List
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition: fl_value.cc:240
static constexpr int kValueFloat64List
static constexpr int kValueFalse
gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:263
static void fl_standard_message_codec_init(FlStandardMessageCodec *self)
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
Definition: fl_value.cc:290
static gboolean read_uint16(GBytes *buffer, size_t *offset, uint16_t *value, GError **error)
static GBytes * fl_standard_message_codec_encode_message(FlMessageCodec *codec, FlValue *message, GError **error)
static void write_align(GByteArray *buffer, guint align)
G_MODULE_EXPORT void fl_value_set(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:523
static void write_float64(GByteArray *buffer, double value)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static constexpr int kValueTrue
FlMethodResponse GError ** error
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:327
static constexpr int kValueInt64
static constexpr int kValueFloat64
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
Definition: fl_value.cc:280
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:624
static constexpr int kValueMap
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:582
void fl_standard_message_codec_write_size(FlStandardMessageCodec *codec, GByteArray *buffer, uint32_t size)
static FlValue * read_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FL_MESSAGE_CODEC_ERROR
G_DEFINE_TYPE(FlStandardMessageCodec, fl_standard_message_codec, fl_message_codec_get_type()) static void write_uint8(GByteArray *buffer
static void write_int64(GByteArray *buffer, int64_t value)
static FlValue * read_float64_value(GBytes *buffer, size_t *offset, GError **error)
static gboolean check_size(GBytes *buffer, size_t offset, size_t required, GError **error)
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new()
static gboolean read_uint32(GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:617
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:226
static FlValue * read_string_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static gboolean read_uint8(GBytes *buffer, size_t *offset, uint8_t *value, GError **error)
static constexpr int kValueString
static constexpr int kValueUint8List
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:603
static constexpr int kValueInt32
static constexpr int kValueNull
static constexpr int kValueInt64List
static FlValue * fl_standard_message_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
static const uint8_t * get_data(GBytes *buffer, size_t *offset)
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition: fl_value.cc:506
static FlValue * read_int64_value(GBytes *buffer, size_t *offset, GError **error)
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:589
uint8_t value
static gboolean read_align(GBytes *buffer, size_t *offset, size_t align, GError **error)
static void fl_standard_message_codec_class_init(FlStandardMessageCodecClass *klass)
static FlValue * read_int32_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
size_t length
static FlValue * read_float64_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static void write_uint32(GByteArray *buffer, uint32_t value)
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:677
static void write_uint16(GByteArray *buffer, uint16_t value)
static FlValue * read_int64_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static FlValue * read_uint8_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT GType fl_message_codec_get_type()
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition: fl_value.cc:693
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:335
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition: fl_value.cc:685
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:610
static constexpr int kValueList
return TRUE
Definition: fl_view.cc:107
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
static FlValue * read_map_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static FlValue * read_int32_value(GBytes *buffer, size_t *offset, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
Definition: fl_value.cc:300
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:254
FlValue * fl_standard_message_codec_read_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:631
static void write_int32(GByteArray *buffer, int32_t value)
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222
gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec *self, GByteArray *buffer, FlValue *value, GError **error)
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition: fl_value.cc:575