Flutter Engine
 
Loading...
Searching...
No Matches
fl_standard_message_codec.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"
#include <gmodule.h>
#include <cstring>

Go to the source code of this file.

Functions

 G_DEFINE_TYPE (FlStandardMessageCodec, fl_standard_message_codec, fl_message_codec_get_type()) static void write_uint8(GByteArray *buffer
 
static void write_uint16 (GByteArray *buffer, uint16_t value)
 
static void write_uint32 (GByteArray *buffer, uint32_t value)
 
static void write_int32 (GByteArray *buffer, int32_t value)
 
static void write_int64 (GByteArray *buffer, int64_t value)
 
static void write_float64 (GByteArray *buffer, double value)
 
static void write_align (GByteArray *buffer, guint align)
 
static gboolean check_size (GBytes *buffer, size_t offset, size_t required, GError **error)
 
static gboolean read_align (GBytes *buffer, size_t *offset, size_t align, GError **error)
 
static const uint8_t * get_data (GBytes *buffer, size_t *offset)
 
static gboolean read_uint8 (GBytes *buffer, size_t *offset, uint8_t *value, GError **error)
 
static gboolean read_uint16 (GBytes *buffer, size_t *offset, uint16_t *value, GError **error)
 
static gboolean read_uint32 (GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
 
static FlValueread_int32_value (GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_int64_value (GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_float64_value (GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_string_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_uint8_list_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_int32_list_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_int64_list_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_float32_list_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_float64_list_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_list_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static FlValueread_map_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 
static GBytes * fl_standard_message_codec_encode_message (FlMessageCodec *codec, FlValue *message, GError **error)
 
static FlValuefl_standard_message_codec_decode_message (FlMessageCodec *codec, GBytes *message, GError **error)
 
static gboolean fl_standard_message_codec_real_write_value (FlStandardMessageCodec *self, GByteArray *buffer, FlValue *value, GError **error)
 
static FlValuefl_standard_message_codec_read_value_of_type (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, int type, GError **error)
 
static void fl_standard_message_codec_class_init (FlStandardMessageCodecClass *klass)
 
static void fl_standard_message_codec_init (FlStandardMessageCodec *self)
 
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new ()
 
G_MODULE_EXPORT void fl_standard_message_codec_write_size (FlStandardMessageCodec *codec, GByteArray *buffer, uint32_t size)
 
G_MODULE_EXPORT gboolean fl_standard_message_codec_read_size (FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
 
G_MODULE_EXPORT gboolean fl_standard_message_codec_write_value (FlStandardMessageCodec *self, GByteArray *buffer, FlValue *value, GError **error)
 
G_MODULE_EXPORT FlValuefl_standard_message_codec_read_value (FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
 

Variables

static constexpr int kValueNull = 0
 
static constexpr int kValueTrue = 1
 
static constexpr int kValueFalse = 2
 
static constexpr int kValueInt32 = 3
 
static constexpr int kValueInt64 = 4
 
static constexpr int kValueFloat64 = 6
 
static constexpr int kValueString = 7
 
static constexpr int kValueUint8List = 8
 
static constexpr int kValueInt32List = 9
 
static constexpr int kValueInt64List = 10
 
static constexpr int kValueFloat64List = 11
 
static constexpr int kValueList = 12
 
static constexpr int kValueMap = 13
 
static constexpr int kValueFloat32List = 14
 
uint8_t value
 

Function Documentation

◆ check_size()

static gboolean check_size ( GBytes *  buffer,
size_t  offset,
size_t  required,
GError **  error 
)
static

Definition at line 73 of file fl_standard_message_codec.cc.

76 {
77 if (offset + required > g_bytes_get_size(buffer)) {
78 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
79 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, "Unexpected end of data");
80 return FALSE;
81 }
82 return TRUE;
83}
return TRUE
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
#define FL_MESSAGE_CODEC_ERROR
const uint8_t uint32_t uint32_t GError ** error

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, and TRUE.

Referenced by read_align(), read_float32_list_value(), read_float64_list_value(), read_float64_value(), read_int32_list_value(), read_int32_value(), read_int64_list_value(), read_int64_value(), read_string_value(), read_uint16(), read_uint32(), read_uint8(), and read_uint8_list_value().

◆ fl_standard_message_codec_class_init()

static void fl_standard_message_codec_class_init ( FlStandardMessageCodecClass *  klass)
static

Definition at line 625 of file fl_standard_message_codec.cc.

626 {
627 FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
629 FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
632 klass->read_value_of_type = fl_standard_message_codec_read_value_of_type;
633}
static FlValue * fl_standard_message_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
static gboolean fl_standard_message_codec_real_write_value(FlStandardMessageCodec *self, GByteArray *buffer, FlValue *value, GError **error)
static GBytes * fl_standard_message_codec_encode_message(FlMessageCodec *codec, FlValue *message, GError **error)
static FlValue * fl_standard_message_codec_read_value_of_type(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, int type, GError **error)

References fl_standard_message_codec_decode_message(), fl_standard_message_codec_encode_message(), fl_standard_message_codec_read_value_of_type(), and fl_standard_message_codec_real_write_value().

◆ fl_standard_message_codec_decode_message()

static FlValue * fl_standard_message_codec_decode_message ( FlMessageCodec *  codec,
GBytes *  message,
GError **  error 
)
static

Definition at line 415 of file fl_standard_message_codec.cc.

417 {
418 if (g_bytes_get_size(message) == 0) {
419 return fl_value_new_null();
420 }
421
422 FlStandardMessageCodec* self =
423 reinterpret_cast<FlStandardMessageCodec*>(codec);
424
425 size_t offset = 0;
428 if (value == nullptr) {
429 return nullptr;
430 }
431
432 if (offset != g_bytes_get_size(message)) {
433 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
435 "Unused %zi bytes after standard message",
436 g_bytes_get_size(message) - offset);
437 return nullptr;
438 }
439
440 return fl_value_ref(value);
441}
g_autoptr(GMutexLocker) locker
@ FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA
G_BEGIN_DECLS GBytes * message
G_MODULE_EXPORT FlValue * fl_standard_message_codec_read_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
uint8_t value
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition fl_value.cc:394
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition fl_value.cc:251
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA, fl_standard_message_codec_read_value(), fl_value_new_null(), fl_value_ref(), g_autoptr(), message, self, and value.

Referenced by fl_standard_message_codec_class_init().

◆ fl_standard_message_codec_encode_message()

static GBytes * fl_standard_message_codec_encode_message ( FlMessageCodec *  codec,
FlValue message,
GError **  error 
)
static

Definition at line 400 of file fl_standard_message_codec.cc.

402 {
403 FlStandardMessageCodec* self =
404 reinterpret_cast<FlStandardMessageCodec*>(codec);
405
406 g_autoptr(GByteArray) buffer = g_byte_array_new();
408 return nullptr;
409 }
410 return g_byte_array_free_to_bytes(
411 static_cast<GByteArray*>(g_steal_pointer(&buffer)));
412}
G_MODULE_EXPORT gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec *self, GByteArray *buffer, FlValue *value, GError **error)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98

References error, fl_standard_message_codec_write_value(), g_autoptr(), message, and self.

Referenced by fl_standard_message_codec_class_init().

◆ fl_standard_message_codec_init()

static void fl_standard_message_codec_init ( FlStandardMessageCodec *  self)
static

Definition at line 635 of file fl_standard_message_codec.cc.

635{}

◆ fl_standard_message_codec_new()

◆ fl_standard_message_codec_read_size()

G_MODULE_EXPORT gboolean fl_standard_message_codec_read_size ( FlStandardMessageCodec *  codec,
GBytes *  buffer,
size_t *  offset,
uint32_t *  value,
GError **  error 
)

fl_standard_message_codec_read_size: @codec: an #FlStandardMessageCodec. @buffer: buffer to read from. @offset: (inout): read position in @buffer. @value: location to read size. @error: (allow-none): #GError location to store the error occurring, or NULL.

Reads a size field in Flutter Standard encoding.

This method is intended for use by subclasses overriding FlStandardMessageCodec::read_value_of_type.

Returns: TRUE on success.

Definition at line 658 of file fl_standard_message_codec.cc.

662 {
663 uint8_t value8;
664 if (!read_uint8(buffer, offset, &value8, error)) {
665 return FALSE;
666 }
667
668 if (value8 == 255) {
669 if (!read_uint32(buffer, offset, value, error)) {
670 return FALSE;
671 }
672 } else if (value8 == 254) {
673 uint16_t value16;
674 if (!read_uint16(buffer, offset, &value16, error)) {
675 return FALSE;
676 }
677 *value = value16;
678 } else {
679 *value = value8;
680 }
681
682 return TRUE;
683}
static gboolean read_uint32(GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
static gboolean read_uint16(GBytes *buffer, size_t *offset, uint16_t *value, GError **error)
static gboolean read_uint8(GBytes *buffer, size_t *offset, uint8_t *value, GError **error)

References error, read_uint16(), read_uint32(), read_uint8(), TRUE, and value.

Referenced by read_custom_value(), read_custom_value1(), read_float32_list_value(), read_float64_list_value(), read_int32_list_value(), read_int64_list_value(), read_list_value(), read_map_value(), read_string_value(), and read_uint8_list_value().

◆ fl_standard_message_codec_read_value()

G_MODULE_EXPORT FlValue * fl_standard_message_codec_read_value ( FlStandardMessageCodec *  codec,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)

fl_standard_message_codec_read_value: @codec: an #FlStandardMessageCodec. @buffer: buffer to read from. @offset: (inout): read position in @buffer. @value: location to read size. @error: (allow-none): #GError location to store the error occurring, or NULL.

Reads an FlValue in Flutter Standard encoding.

This method is intended for use by subclasses overriding FlStandardMessageCodec::read_value_of_type.

Returns: a new FlValue or NULL on error.

Definition at line 694 of file fl_standard_message_codec.cc.

698 {
699 uint8_t type;
700 if (!read_uint8(buffer, offset, &type, error)) {
701 return nullptr;
702 }
703
704 return FL_STANDARD_MESSAGE_CODEC_GET_CLASS(self)->read_value_of_type(
705 self, buffer, offset, type, error);
706}
GLenum type

References error, read_uint8(), self, and type.

Referenced by fl_standard_message_codec_decode_message(), fl_standard_method_codec_decode_method_call(), fl_standard_method_codec_decode_response(), read_list_value(), and read_map_value().

◆ fl_standard_message_codec_read_value_of_type()

static FlValue * fl_standard_message_codec_read_value_of_type ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
int  type,
GError **  error 
)
static

Definition at line 580 of file fl_standard_message_codec.cc.

585 {
586 g_autoptr(FlValue) value = nullptr;
587 if (type == kValueNull) {
588 return fl_value_new_null();
589 } else if (type == kValueTrue) {
590 return fl_value_new_bool(TRUE);
591 } else if (type == kValueFalse) {
592 return fl_value_new_bool(FALSE);
593 } else if (type == kValueInt32) {
594 value = read_int32_value(buffer, offset, error);
595 } else if (type == kValueInt64) {
596 value = read_int64_value(buffer, offset, error);
597 } else if (type == kValueFloat64) {
598 value = read_float64_value(buffer, offset, error);
599 } else if (type == kValueString) {
600 value = read_string_value(self, buffer, offset, error);
601 } else if (type == kValueUint8List) {
602 value = read_uint8_list_value(self, buffer, offset, error);
603 } else if (type == kValueInt32List) {
604 value = read_int32_list_value(self, buffer, offset, error);
605 } else if (type == kValueInt64List) {
606 value = read_int64_list_value(self, buffer, offset, error);
607 } else if (type == kValueFloat32List) {
608 value = read_float32_list_value(self, buffer, offset, error);
609 } else if (type == kValueFloat64List) {
610 value = read_float64_list_value(self, buffer, offset, error);
611 } else if (type == kValueList) {
612 value = read_list_value(self, buffer, offset, error);
613 } else if (type == kValueMap) {
614 value = read_map_value(self, buffer, offset, error);
615 } else {
616 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
618 "Unexpected standard codec type %02x", type);
619 return nullptr;
620 }
621
622 return value == nullptr ? nullptr : fl_value_ref(value);
623}
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
static FlValue * read_int64_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static FlValue * read_int32_value(GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueNull
static constexpr int kValueString
static FlValue * read_float64_value(GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueTrue
static FlValue * read_float32_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueInt64List
static FlValue * read_int64_value(GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueFloat64List
static constexpr int kValueFloat32List
static constexpr int kValueUint8List
static constexpr int kValueInt32
static constexpr int kValueList
static constexpr int kValueFloat64
static constexpr int kValueMap
static FlValue * read_string_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueInt32List
static FlValue * read_uint8_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static FlValue * read_float64_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueInt64
static FlValue * read_map_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static constexpr int kValueFalse
static FlValue * read_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static FlValue * read_int32_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition fl_value.cc:255

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE, fl_value_new_bool(), fl_value_new_null(), fl_value_ref(), g_autoptr(), kValueFalse, kValueFloat32List, kValueFloat64, kValueFloat64List, kValueInt32, kValueInt32List, kValueInt64, kValueInt64List, kValueList, kValueMap, kValueNull, kValueString, kValueTrue, kValueUint8List, read_float32_list_value(), read_float64_list_value(), read_float64_value(), read_int32_list_value(), read_int32_value(), read_int64_list_value(), read_int64_value(), read_list_value(), read_map_value(), read_string_value(), read_uint8_list_value(), self, TRUE, type, and value.

Referenced by fl_standard_message_codec_class_init().

◆ fl_standard_message_codec_real_write_value()

static gboolean fl_standard_message_codec_real_write_value ( FlStandardMessageCodec *  self,
GByteArray *  buffer,
FlValue value,
GError **  error 
)
static

Definition at line 444 of file fl_standard_message_codec.cc.

448 {
449 if (value == nullptr) {
450 write_uint8(buffer, kValueNull);
451 return TRUE;
452 }
453
454 switch (fl_value_get_type(value)) {
456 write_uint8(buffer, kValueNull);
457 return TRUE;
460 write_uint8(buffer, kValueTrue);
461 } else {
462 write_uint8(buffer, kValueFalse);
463 }
464 return TRUE;
465 case FL_VALUE_TYPE_INT: {
466 int64_t v = fl_value_get_int(value);
467 if (v >= INT32_MIN && v <= INT32_MAX) {
468 write_uint8(buffer, kValueInt32);
469 write_int32(buffer, v);
470 } else {
471 write_uint8(buffer, kValueInt64);
472 write_int64(buffer, v);
473 }
474 return TRUE;
475 }
477 write_uint8(buffer, kValueFloat64);
478 write_align(buffer, 8);
480 return TRUE;
482 write_uint8(buffer, kValueString);
483 const char* text = fl_value_get_string(value);
484 size_t length = strlen(text);
486 g_byte_array_append(buffer, reinterpret_cast<const uint8_t*>(text),
487 length);
488 return TRUE;
489 }
491 write_uint8(buffer, kValueUint8List);
495 sizeof(uint8_t) * length);
496 return TRUE;
497 }
499 write_uint8(buffer, kValueInt32List);
502 write_align(buffer, 4);
504 buffer,
505 reinterpret_cast<const uint8_t*>(fl_value_get_int32_list(value)),
506 sizeof(int32_t) * length);
507 return TRUE;
508 }
510 write_uint8(buffer, kValueInt64List);
513 write_align(buffer, 8);
515 buffer,
516 reinterpret_cast<const uint8_t*>(fl_value_get_int64_list(value)),
517 sizeof(int64_t) * length);
518 return TRUE;
519 }
521 write_uint8(buffer, kValueFloat32List);
524 write_align(buffer, 4);
526 buffer,
527 reinterpret_cast<const uint8_t*>(fl_value_get_float32_list(value)),
528 sizeof(float) * length);
529 return TRUE;
530 }
532 write_uint8(buffer, kValueFloat64List);
535 write_align(buffer, 8);
537 buffer,
538 reinterpret_cast<const uint8_t*>(fl_value_get_float_list(value)),
539 sizeof(double) * length);
540 return TRUE;
541 }
543 write_uint8(buffer, kValueList);
546 for (size_t i = 0; i < fl_value_get_length(value); i++) {
549 return FALSE;
550 }
551 }
552 return TRUE;
554 write_uint8(buffer, kValueMap);
557 for (size_t i = 0; i < fl_value_get_length(value); i++) {
559 self, buffer, fl_value_get_map_key(value, i), error) ||
561 self, buffer, fl_value_get_map_value(value, i), error)) {
562 return FALSE;
563 }
564 }
565 return TRUE;
567 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
569 "Custom value not implemented");
570 return FALSE;
571 }
572
573 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
575 "Unexpected FlValue type %d", fl_value_get_type(value));
576 return FALSE;
577}
#define INT32_MAX
Definition comments.cc:78
#define INT32_MIN
Definition comments.cc:69
G_MODULE_EXPORT void fl_standard_message_codec_write_size(FlStandardMessageCodec *codec, GByteArray *buffer, uint32_t size)
static void write_align(GByteArray *buffer, guint align)
static void write_int64(GByteArray *buffer, int64_t value)
static void write_float64(GByteArray *buffer, double value)
static void write_int32(GByteArray *buffer, int32_t value)
g_byte_array_append(buffer, &type, sizeof(uint8_t))
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition fl_value.cc:717
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition fl_value.cc:668
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition fl_value.cc:466
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition fl_value.cc:784
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition fl_value.cc:682
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition fl_value.cc:689
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition fl_value.cc:776
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
Definition fl_value.cc:661
G_MODULE_EXPORT const float * fl_value_get_float32_list(FlValue *self)
Definition fl_value.cc:710
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition fl_value.cc:792
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition fl_value.cc:675
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition fl_value.cc:724
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition fl_value.cc:696
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition fl_value.cc:703
@ FL_VALUE_TYPE_STRING
Definition fl_value.h:68
@ FL_VALUE_TYPE_NULL
Definition fl_value.h:64
@ FL_VALUE_TYPE_INT
Definition fl_value.h:66
@ FL_VALUE_TYPE_BOOL
Definition fl_value.h:65
@ FL_VALUE_TYPE_FLOAT32_LIST
Definition fl_value.h:75
@ FL_VALUE_TYPE_INT32_LIST
Definition fl_value.h:70
@ FL_VALUE_TYPE_UINT8_LIST
Definition fl_value.h:69
@ FL_VALUE_TYPE_LIST
Definition fl_value.h:73
@ FL_VALUE_TYPE_MAP
Definition fl_value.h:74
@ FL_VALUE_TYPE_INT64_LIST
Definition fl_value.h:71
@ FL_VALUE_TYPE_FLOAT_LIST
Definition fl_value.h:72
@ FL_VALUE_TYPE_CUSTOM
Definition fl_value.h:76
@ FL_VALUE_TYPE_FLOAT
Definition fl_value.h:67
size_t length
std::u16string text

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE, fl_standard_message_codec_write_size(), fl_standard_message_codec_write_value(), fl_value_get_bool(), fl_value_get_float(), fl_value_get_float32_list(), fl_value_get_float_list(), fl_value_get_int(), fl_value_get_int32_list(), fl_value_get_int64_list(), fl_value_get_length(), fl_value_get_list_value(), fl_value_get_map_key(), fl_value_get_map_value(), fl_value_get_string(), fl_value_get_type(), fl_value_get_uint8_list(), FL_VALUE_TYPE_BOOL, FL_VALUE_TYPE_CUSTOM, FL_VALUE_TYPE_FLOAT, FL_VALUE_TYPE_FLOAT32_LIST, FL_VALUE_TYPE_FLOAT_LIST, FL_VALUE_TYPE_INT, FL_VALUE_TYPE_INT32_LIST, FL_VALUE_TYPE_INT64_LIST, FL_VALUE_TYPE_LIST, FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_NULL, FL_VALUE_TYPE_STRING, FL_VALUE_TYPE_UINT8_LIST, g_byte_array_append(), i, INT32_MAX, INT32_MIN, kValueFalse, kValueFloat32List, kValueFloat64, kValueFloat64List, kValueInt32, kValueInt32List, kValueInt64, kValueInt64List, kValueList, kValueMap, kValueNull, kValueString, kValueTrue, kValueUint8List, length, self, text, TRUE, value, write_align(), write_float64(), write_int32(), and write_int64().

Referenced by fl_standard_message_codec_class_init().

◆ fl_standard_message_codec_write_size()

G_MODULE_EXPORT void fl_standard_message_codec_write_size ( FlStandardMessageCodec *  codec,
GByteArray *  buffer,
uint32_t  size 
)

fl_standard_message_codec_write_size: @codec: an #FlStandardMessageCodec. @buffer: buffer to write into. @size: size value to write.

Writes a size field in Flutter Standard encoding.

Definition at line 642 of file fl_standard_message_codec.cc.

645 {
646 if (size < 254) {
647 write_uint8(buffer, size);
648 } else if (size <= 0xffff) {
649 write_uint8(buffer, 254);
650 write_uint16(buffer, size);
651 } else {
652 write_uint8(buffer, 255);
653 write_uint32(buffer, size);
654 }
655}
static void write_uint32(GByteArray *buffer, uint32_t value)
static void write_uint16(GByteArray *buffer, uint16_t value)

References write_uint16(), and write_uint32().

Referenced by fl_standard_message_codec_real_write_value().

◆ fl_standard_message_codec_write_value()

G_MODULE_EXPORT gboolean fl_standard_message_codec_write_value ( FlStandardMessageCodec *  codec,
GByteArray *  buffer,
FlValue value,
GError **  error 
)

fl_standard_message_codec_write_value: @codec: an #FlStandardMessageCodec. @buffer: buffer to write into. @value: (allow-none): value to write. @error: (allow-none): #GError location to store the error occurring, or NULL.

Writes an FlValue in Flutter Standard encoding.

This method is intended for use by subclasses overriding FlStandardMessageCodec::write_value.

Returns: TRUE on success.

Definition at line 686 of file fl_standard_message_codec.cc.

689 {
690 return FL_STANDARD_MESSAGE_CODEC_GET_CLASS(self)->write_value(self, buffer,
691 value, error);
692}

References error, self, and value.

Referenced by fl_standard_message_codec_encode_message(), fl_standard_message_codec_real_write_value(), fl_standard_method_codec_encode_error_envelope(), fl_standard_method_codec_encode_method_call(), and fl_standard_method_codec_encode_success_envelope().

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlStandardMessageCodec  ,
fl_standard_message_codec  ,
fl_message_codec_get_type()   
)

◆ get_data()

static const uint8_t * get_data ( GBytes *  buffer,
size_t *  offset 
)
static

◆ read_align()

static gboolean read_align ( GBytes *  buffer,
size_t *  offset,
size_t  align,
GError **  error 
)
static

Definition at line 86 of file fl_standard_message_codec.cc.

89 {
90 if ((*offset) % align == 0) {
91 return TRUE;
92 }
93
94 size_t required = align - (*offset) % align;
95 if (!check_size(buffer, *offset, required, error)) {
96 return FALSE;
97 }
98
99 (*offset) += required;
100 return TRUE;
101}
static gboolean check_size(GBytes *buffer, size_t offset, size_t required, GError **error)

References check_size(), error, and TRUE.

Referenced by read_float32_list_value(), read_float64_list_value(), read_float64_value(), read_int32_list_value(), and read_int64_list_value().

◆ read_float32_list_value()

static FlValue * read_float32_list_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 297 of file fl_standard_message_codec.cc.

300 {
301 uint32_t length;
302 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
303 error)) {
304 return nullptr;
305 }
306 if (!read_align(buffer, offset, 4, error)) {
307 return nullptr;
308 }
309 if (!check_size(buffer, *offset, sizeof(float) * length, error)) {
310 return nullptr;
311 }
313 reinterpret_cast<const float*>(get_data(buffer, offset)), length);
314 *offset += sizeof(float) * length;
315 return value;
316}
G_MODULE_EXPORT gboolean fl_standard_message_codec_read_size(FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
static gboolean read_align(GBytes *buffer, size_t *offset, size_t align, GError **error)
static const uint8_t * get_data(GBytes *buffer, size_t *offset)
G_MODULE_EXPORT FlValue * fl_value_new_float32_list(const float *data, size_t data_length)
Definition fl_value.cc:329

References check_size(), error, fl_standard_message_codec_read_size(), fl_value_new_float32_list(), get_data(), length, read_align(), self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_float64_list_value()

static FlValue * read_float64_list_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 321 of file fl_standard_message_codec.cc.

324 {
325 uint32_t length;
326 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
327 error)) {
328 return nullptr;
329 }
330 if (!read_align(buffer, offset, 8, error)) {
331 return nullptr;
332 }
333 if (!check_size(buffer, *offset, sizeof(double) * length, error)) {
334 return nullptr;
335 }
337 reinterpret_cast<const double*>(get_data(buffer, offset)), length);
338 *offset += sizeof(double) * length;
339 return value;
340}
G_MODULE_EXPORT FlValue * fl_value_new_float_list(const double *data, size_t data_length)
Definition fl_value.cc:339

References check_size(), error, fl_standard_message_codec_read_size(), fl_value_new_float_list(), get_data(), length, read_align(), self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_float64_value()

static FlValue * read_float64_value ( GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 189 of file fl_standard_message_codec.cc.

191 {
192 if (!read_align(buffer, offset, 8, error)) {
193 return nullptr;
194 }
195 if (!check_size(buffer, *offset, sizeof(double), error)) {
196 return nullptr;
197 }
198
200 reinterpret_cast<const double*>(get_data(buffer, offset))[0]);
201 *offset += sizeof(double);
202 return value;
203}
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
Definition fl_value.cc:269

References check_size(), error, fl_value_new_float(), get_data(), read_align(), and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_int32_list_value()

static FlValue * read_int32_list_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 249 of file fl_standard_message_codec.cc.

252 {
253 uint32_t length;
254 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
255 error)) {
256 return nullptr;
257 }
258 if (!read_align(buffer, offset, 4, error)) {
259 return nullptr;
260 }
261 if (!check_size(buffer, *offset, sizeof(int32_t) * length, error)) {
262 return nullptr;
263 }
265 reinterpret_cast<const int32_t*>(get_data(buffer, offset)), length);
266 *offset += sizeof(int32_t) * length;
267 return value;
268}
G_MODULE_EXPORT FlValue * fl_value_new_int32_list(const int32_t *data, size_t data_length)
Definition fl_value.cc:309

References check_size(), error, fl_standard_message_codec_read_size(), fl_value_new_int32_list(), get_data(), length, read_align(), self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_int32_value()

static FlValue * read_int32_value ( GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 157 of file fl_standard_message_codec.cc.

159 {
160 if (!check_size(buffer, *offset, sizeof(int32_t), error)) {
161 return nullptr;
162 }
163
165 reinterpret_cast<const int32_t*>(get_data(buffer, offset))[0]);
166 *offset += sizeof(int32_t);
167 return value;
168}
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition fl_value.cc:262

References check_size(), error, fl_value_new_int(), get_data(), and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_int64_list_value()

static FlValue * read_int64_list_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 273 of file fl_standard_message_codec.cc.

276 {
277 uint32_t length;
278 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
279 error)) {
280 return nullptr;
281 }
282 if (!read_align(buffer, offset, 8, error)) {
283 return nullptr;
284 }
285 if (!check_size(buffer, *offset, sizeof(int64_t) * length, error)) {
286 return nullptr;
287 }
289 reinterpret_cast<const int64_t*>(get_data(buffer, offset)), length);
290 *offset += sizeof(int64_t) * length;
291 return value;
292}
G_MODULE_EXPORT FlValue * fl_value_new_int64_list(const int64_t *data, size_t data_length)
Definition fl_value.cc:319

References check_size(), error, fl_standard_message_codec_read_size(), fl_value_new_int64_list(), get_data(), length, read_align(), self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_int64_value()

static FlValue * read_int64_value ( GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 173 of file fl_standard_message_codec.cc.

175 {
176 if (!check_size(buffer, *offset, sizeof(int64_t), error)) {
177 return nullptr;
178 }
179
181 reinterpret_cast<const int64_t*>(get_data(buffer, offset))[0]);
182 *offset += sizeof(int64_t);
183 return value;
184}

References check_size(), error, fl_value_new_int(), get_data(), and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_list_value()

static FlValue * read_list_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 345 of file fl_standard_message_codec.cc.

348 {
349 uint32_t length;
350 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
351 error)) {
352 return nullptr;
353 }
354
356 for (size_t i = 0; i < length; i++) {
357 g_autoptr(FlValue) child =
359 if (child == nullptr) {
360 return nullptr;
361 }
362 fl_value_append(list, child);
363 }
364
365 return fl_value_ref(list);
366}
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
Definition fl_value.cc:592
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition fl_value.cc:349

References error, fl_standard_message_codec_read_size(), fl_standard_message_codec_read_value(), fl_value_append(), fl_value_new_list(), fl_value_ref(), g_autoptr(), i, length, and self.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_map_value()

static FlValue * read_map_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 371 of file fl_standard_message_codec.cc.

374 {
375 uint32_t length;
376 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
377 error)) {
378 return nullptr;
379 }
380
382 for (size_t i = 0; i < length; i++) {
385 if (key == nullptr) {
386 return nullptr;
387 }
390 if (value == nullptr) {
391 return nullptr;
392 }
393 fl_value_set(map, key, value);
394 }
395
396 return fl_value_ref(map);
397}
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition fl_value.cc:366
G_MODULE_EXPORT void fl_value_set(FlValue *self, FlValue *key, FlValue *value)
Definition fl_value.cc:609

References error, fl_standard_message_codec_read_size(), fl_standard_message_codec_read_value(), fl_value_new_map(), fl_value_ref(), fl_value_set(), g_autoptr(), i, key, length, self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_string_value()

static FlValue * read_string_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 208 of file fl_standard_message_codec.cc.

211 {
212 uint32_t length;
213 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
214 error)) {
215 return nullptr;
216 }
217 if (!check_size(buffer, *offset, length, error)) {
218 return nullptr;
219 }
221 reinterpret_cast<const gchar*>(get_data(buffer, offset)), length);
222 *offset += length;
223 return value;
224}
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition fl_value.cc:283

References check_size(), error, fl_standard_message_codec_read_size(), fl_value_new_string_sized(), get_data(), length, self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ read_uint16()

static gboolean read_uint16 ( GBytes *  buffer,
size_t *  offset,
uint16_t *  value,
GError **  error 
)
static

Definition at line 126 of file fl_standard_message_codec.cc.

129 {
130 if (!check_size(buffer, *offset, sizeof(uint16_t), error)) {
131 return FALSE;
132 }
133
134 *value = reinterpret_cast<const uint16_t*>(get_data(buffer, offset))[0];
135 *offset += sizeof(uint16_t);
136 return TRUE;
137}

References check_size(), error, get_data(), TRUE, and value.

Referenced by fl_standard_message_codec_read_size().

◆ read_uint32()

static gboolean read_uint32 ( GBytes *  buffer,
size_t *  offset,
uint32_t *  value,
GError **  error 
)
static

Definition at line 141 of file fl_standard_message_codec.cc.

144 {
145 if (!check_size(buffer, *offset, sizeof(uint32_t), error)) {
146 return FALSE;
147 }
148
149 *value = reinterpret_cast<const uint32_t*>(get_data(buffer, offset))[0];
150 *offset += sizeof(uint32_t);
151 return TRUE;
152}

References check_size(), error, get_data(), TRUE, and value.

Referenced by fl_standard_message_codec_read_size().

◆ read_uint8()

static gboolean read_uint8 ( GBytes *  buffer,
size_t *  offset,
uint8_t *  value,
GError **  error 
)
static

Definition at line 111 of file fl_standard_message_codec.cc.

114 {
115 if (!check_size(buffer, *offset, sizeof(uint8_t), error)) {
116 return FALSE;
117 }
118
119 *value = get_data(buffer, offset)[0];
120 (*offset)++;
121 return TRUE;
122}

References check_size(), error, get_data(), TRUE, and value.

Referenced by fl_standard_message_codec_read_size(), and fl_standard_message_codec_read_value().

◆ read_uint8_list_value()

static FlValue * read_uint8_list_value ( FlStandardMessageCodec *  self,
GBytes *  buffer,
size_t *  offset,
GError **  error 
)
static

Definition at line 229 of file fl_standard_message_codec.cc.

232 {
233 uint32_t length;
234 if (!fl_standard_message_codec_read_size(self, buffer, offset, &length,
235 error)) {
236 return nullptr;
237 }
238 if (!check_size(buffer, *offset, sizeof(uint8_t) * length, error)) {
239 return nullptr;
240 }
242 *offset += length;
243 return value;
244}
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition fl_value.cc:292

References check_size(), error, fl_standard_message_codec_read_size(), fl_value_new_uint8_list(), get_data(), length, self, and value.

Referenced by fl_standard_message_codec_read_value_of_type().

◆ write_align()

static void write_align ( GByteArray *  buffer,
guint  align 
)
static

Definition at line 66 of file fl_standard_message_codec.cc.

66 {
67 while (buffer->len % align != 0) {
68 write_uint8(buffer, 0);
69 }
70}

Referenced by fl_standard_message_codec_real_write_value().

◆ write_float64()

static void write_float64 ( GByteArray *  buffer,
double  value 
)
static

Definition at line 60 of file fl_standard_message_codec.cc.

60 {
61 g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
62 sizeof(double));
63}

References g_byte_array_append(), and value.

Referenced by fl_standard_message_codec_real_write_value().

◆ write_int32()

static void write_int32 ( GByteArray *  buffer,
int32_t  value 
)
static

Definition at line 50 of file fl_standard_message_codec.cc.

50 {
51 g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
52 sizeof(int32_t));
53}

References g_byte_array_append(), and value.

Referenced by fl_standard_message_codec_real_write_value().

◆ write_int64()

static void write_int64 ( GByteArray *  buffer,
int64_t  value 
)
static

Definition at line 55 of file fl_standard_message_codec.cc.

55 {
56 g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
57 sizeof(int64_t));
58}

References g_byte_array_append(), and value.

Referenced by fl_standard_message_codec_real_write_value().

◆ write_uint16()

static void write_uint16 ( GByteArray *  buffer,
uint16_t  value 
)
static

Definition at line 40 of file fl_standard_message_codec.cc.

40 {
41 g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
42 sizeof(uint16_t));
43}

References g_byte_array_append(), and value.

Referenced by fl_standard_message_codec_write_size().

◆ write_uint32()

static void write_uint32 ( GByteArray *  buffer,
uint32_t  value 
)
static

Definition at line 45 of file fl_standard_message_codec.cc.

45 {
46 g_byte_array_append(buffer, reinterpret_cast<uint8_t*>(&value),
47 sizeof(uint32_t));
48}

References g_byte_array_append(), and value.

Referenced by fl_standard_message_codec_write_size().

Variable Documentation

◆ kValueFalse

constexpr int kValueFalse = 2
staticconstexpr

◆ kValueFloat32List

constexpr int kValueFloat32List = 14
staticconstexpr

◆ kValueFloat64

constexpr int kValueFloat64 = 6
staticconstexpr

◆ kValueFloat64List

constexpr int kValueFloat64List = 11
staticconstexpr

◆ kValueInt32

constexpr int kValueInt32 = 3
staticconstexpr

◆ kValueInt32List

constexpr int kValueInt32List = 9
staticconstexpr

◆ kValueInt64

constexpr int kValueInt64 = 4
staticconstexpr

◆ kValueInt64List

constexpr int kValueInt64List = 10
staticconstexpr

◆ kValueList

constexpr int kValueList = 12
staticconstexpr

◆ kValueMap

constexpr int kValueMap = 13
staticconstexpr

◆ kValueNull

constexpr int kValueNull = 0
staticconstexpr

◆ kValueString

constexpr int kValueString = 7
staticconstexpr

◆ kValueTrue

constexpr int kValueTrue = 1
staticconstexpr

◆ kValueUint8List

constexpr int kValueUint8List = 8
staticconstexpr

◆ value