Flutter Engine
fl_standard_message_codec_private.h File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"

Go to the source code of this file.

Functions

G_BEGIN_DECLS void fl_standard_message_codec_write_size (FlStandardMessageCodec *codec, GByteArray *buffer, uint32_t size)
 
gboolean fl_standard_message_codec_read_size (FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, uint32_t *value, GError **error)
 
gboolean fl_standard_message_codec_write_value (FlStandardMessageCodec *codec, GByteArray *buffer, FlValue *value, GError **error)
 
FlValuefl_standard_message_codec_read_value (FlStandardMessageCodec *codec, GBytes *buffer, size_t *offset, GError **error)
 

Function Documentation

◆ fl_standard_message_codec_read_size()

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: : an #FlStandardMessageCodec. : buffer to read from. : (inout): read position in . : location to read size. : (allow-none): #GError location to store the error occurring, or NULL.

Reads a size field in Flutter Standard encoding.

Returns: TRUE on success.

Definition at line 473 of file fl_standard_message_codec.cc.

References FALSE, read_uint16(), read_uint32(), read_uint8(), and TRUE.

Referenced by 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().

477  {
478  uint8_t value8;
479  if (!read_uint8(buffer, offset, &value8, error)) {
480  return FALSE;
481  }
482 
483  if (value8 == 255) {
484  if (!read_uint32(buffer, offset, value, error)) {
485  return FALSE;
486  }
487  } else if (value8 == 254) {
488  uint16_t value16;
489  if (!read_uint16(buffer, offset, &value16, error)) {
490  return FALSE;
491  }
492  *value = value16;
493  } else {
494  *value = value8;
495  }
496 
497  return TRUE;
498 }
const uint8_t uint32_t uint32_t 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 gboolean read_uint8(GBytes *buffer, size_t *offset, uint8_t *value, GError **error)
uint8_t value
static const uint8_t buffer[]
return FALSE

◆ fl_standard_message_codec_read_value()

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

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

Reads an FlValue in Flutter Standard encoding.

Returns: a new FlValue or NULL on error.

Definition at line 629 of file fl_standard_message_codec.cc.

References FALSE, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE, fl_value_new_bool(), fl_value_new_null(), fl_value_ref(), 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(), read_uint8_list_value(), TRUE, type, and value.

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().

632  {
633  uint8_t type;
634  if (!read_uint8(buffer, offset, &type, error)) {
635  return nullptr;
636  }
637 
638  g_autoptr(FlValue) value = nullptr;
639  if (type == kValueNull) {
640  return fl_value_new_null();
641  } else if (type == kValueTrue) {
642  return fl_value_new_bool(TRUE);
643  } else if (type == kValueFalse) {
644  return fl_value_new_bool(FALSE);
645  } else if (type == kValueInt32) {
646  value = read_int32_value(buffer, offset, error);
647  } else if (type == kValueInt64) {
648  value = read_int64_value(buffer, offset, error);
649  } else if (type == kValueFloat64) {
650  value = read_float64_value(buffer, offset, error);
651  } else if (type == kValueString) {
652  value = read_string_value(self, buffer, offset, error);
653  } else if (type == kValueUint8List) {
654  value = read_uint8_list_value(self, buffer, offset, error);
655  } else if (type == kValueInt32List) {
656  value = read_int32_list_value(self, buffer, offset, error);
657  } else if (type == kValueInt64List) {
658  value = read_int64_list_value(self, buffer, offset, error);
659  } else if (type == kValueFloat32List) {
660  value = read_float32_list_value(self, buffer, offset, error);
661  } else if (type == kValueFloat64List) {
662  value = read_float64_list_value(self, buffer, offset, error);
663  } else if (type == kValueList) {
664  value = read_list_value(self, buffer, offset, error);
665  } else if (type == kValueMap) {
666  value = read_map_value(self, buffer, offset, error);
667  } else {
668  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
670  "Unexpected standard codec type %02x", type);
671  return nullptr;
672  }
673 
674  return value == nullptr ? nullptr : fl_value_ref(value);
675 }
static constexpr int kValueInt32List
KeyCallType type
static constexpr int kValueFloat64List
static constexpr int kValueFalse
const uint8_t uint32_t uint32_t GError ** error
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:40
static constexpr int kValueTrue
static constexpr int kValueInt64
static constexpr int kValueFloat64
static constexpr int kValueMap
static FlValue * read_float32_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
static FlValue * read_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
#define FL_MESSAGE_CODEC_ERROR
static constexpr int kValueFloat32List
static FlValue * read_float64_value(GBytes *buffer, size_t *offset, GError **error)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
Definition: fl_value.cc:244
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
static constexpr int kValueInt32
static constexpr int kValueNull
static constexpr int kValueInt64List
static FlValue * read_int64_value(GBytes *buffer, size_t *offset, GError **error)
uint8_t value
static FlValue * read_int32_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 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_ref(FlValue *self)
Definition: fl_value.cc:363
static constexpr int kValueList
static const uint8_t buffer[]
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)
return FALSE
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:240

◆ fl_standard_message_codec_write_size()

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

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

Writes a size field in Flutter Standard encoding.

Definition at line 459 of file fl_standard_message_codec.cc.

References write_uint16(), and write_uint32().

Referenced by fl_standard_message_codec_write_value().

461  {
462  if (size < 254) {
463  write_uint8(buffer, size);
464  } else if (size <= 0xffff) {
465  write_uint8(buffer, 254);
467  } else {
468  write_uint8(buffer, 255);
470  }
471 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
static void write_uint32(GByteArray *buffer, uint32_t value)
static void write_uint16(GByteArray *buffer, uint16_t value)
static const uint8_t buffer[]

◆ fl_standard_message_codec_write_value()

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

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

Writes an FlValue in Flutter Standard encoding.

Returns: TRUE on success.

Definition at line 500 of file fl_standard_message_codec.cc.

References FALSE, 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_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, kValueFalse, kValueFloat32List, kValueFloat64, kValueFloat64List, kValueInt32, kValueInt32List, kValueInt64, kValueInt64List, kValueList, kValueMap, kValueNull, kValueString, kValueTrue, kValueUint8List, length, text, TRUE, write_align(), write_float64(), write_int32(), and write_int64().

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

503  {
504  if (value == nullptr) {
505  write_uint8(buffer, kValueNull);
506  return TRUE;
507  }
508 
509  switch (fl_value_get_type(value)) {
510  case FL_VALUE_TYPE_NULL:
511  write_uint8(buffer, kValueNull);
512  return TRUE;
513  case FL_VALUE_TYPE_BOOL:
514  if (fl_value_get_bool(value)) {
515  write_uint8(buffer, kValueTrue);
516  } else {
517  write_uint8(buffer, kValueFalse);
518  }
519  return TRUE;
520  case FL_VALUE_TYPE_INT: {
521  int64_t v = fl_value_get_int(value);
522  if (v >= INT32_MIN && v <= INT32_MAX) {
523  write_uint8(buffer, kValueInt32);
524  write_int32(buffer, v);
525  } else {
526  write_uint8(buffer, kValueInt64);
527  write_int64(buffer, v);
528  }
529  return TRUE;
530  }
531  case FL_VALUE_TYPE_FLOAT:
532  write_uint8(buffer, kValueFloat64);
533  write_align(buffer, 8);
535  return TRUE;
536  case FL_VALUE_TYPE_STRING: {
537  write_uint8(buffer, kValueString);
538  const char* text = fl_value_get_string(value);
539  size_t length = strlen(text);
541  g_byte_array_append(buffer, reinterpret_cast<const uint8_t*>(text),
542  length);
543  return TRUE;
544  }
546  write_uint8(buffer, kValueUint8List);
547  size_t length = fl_value_get_length(value);
549  g_byte_array_append(buffer, fl_value_get_uint8_list(value),
550  sizeof(uint8_t) * length);
551  return TRUE;
552  }
554  write_uint8(buffer, kValueInt32List);
555  size_t length = fl_value_get_length(value);
557  write_align(buffer, 4);
558  g_byte_array_append(
559  buffer,
560  reinterpret_cast<const uint8_t*>(fl_value_get_int32_list(value)),
561  sizeof(int32_t) * length);
562  return TRUE;
563  }
565  write_uint8(buffer, kValueInt64List);
566  size_t length = fl_value_get_length(value);
568  write_align(buffer, 8);
569  g_byte_array_append(
570  buffer,
571  reinterpret_cast<const uint8_t*>(fl_value_get_int64_list(value)),
572  sizeof(int64_t) * length);
573  return TRUE;
574  }
576  write_uint8(buffer, kValueFloat32List);
577  size_t length = fl_value_get_length(value);
579  write_align(buffer, 4);
580  g_byte_array_append(
581  buffer,
582  reinterpret_cast<const uint8_t*>(fl_value_get_float32_list(value)),
583  sizeof(float) * length);
584  return TRUE;
585  }
587  write_uint8(buffer, kValueFloat64List);
588  size_t length = fl_value_get_length(value);
590  write_align(buffer, 8);
591  g_byte_array_append(
592  buffer,
593  reinterpret_cast<const uint8_t*>(fl_value_get_float_list(value)),
594  sizeof(double) * length);
595  return TRUE;
596  }
597  case FL_VALUE_TYPE_LIST:
598  write_uint8(buffer, kValueList);
601  for (size_t i = 0; i < fl_value_get_length(value); i++) {
603  self, buffer, fl_value_get_list_value(value, i), error)) {
604  return FALSE;
605  }
606  }
607  return TRUE;
608  case FL_VALUE_TYPE_MAP:
609  write_uint8(buffer, kValueMap);
612  for (size_t i = 0; i < fl_value_get_length(value); i++) {
614  self, buffer, fl_value_get_map_key(value, i), error) ||
616  self, buffer, fl_value_get_map_value(value, i), error)) {
617  return FALSE;
618  }
619  }
620  return TRUE;
621  }
622 
623  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
625  "Unexpected FlValue type %d", fl_value_get_type(value));
626  return FALSE;
627 }
static constexpr int kValueInt32List
static constexpr int kValueFloat64List
G_MODULE_EXPORT const float * fl_value_get_float32_list(FlValue *self)
Definition: fl_value.cc:670
static constexpr int kValueFalse
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:428
static void write_align(GByteArray *buffer, guint align)
static void write_float64(GByteArray *buffer, double value)
static constexpr int kValueTrue
static constexpr int kValueInt64
static constexpr int kValueFloat64
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
Definition: fl_value.cc:677
static constexpr int kValueMap
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:628
void fl_standard_message_codec_write_size(FlStandardMessageCodec *codec, GByteArray *buffer, uint32_t size)
#define FL_MESSAGE_CODEC_ERROR
static void write_int64(GByteArray *buffer, int64_t value)
static constexpr int kValueFloat32List
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:663
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:649
static constexpr int kValueInt32
static constexpr int kValueNull
static constexpr int kValueInt64List
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:635
uint8_t value
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:735
size_t length
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
Definition: fl_value.cc:751
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
Definition: fl_value.cc:743
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
Definition: fl_value.cc:656
static constexpr int kValueList
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:642
std::u16string text
static const uint8_t buffer[]
return FALSE
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:684
static void write_int32(GByteArray *buffer, int32_t value)
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:621