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 448 of file fl_standard_message_codec.cc.

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

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

452  {
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 }
static gboolean read_uint16(GBytes *buffer, size_t *offset, uint16_t *value, GError **error)
FlMethodResponse 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
return TRUE
Definition: fl_view.cc:107

◆ 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 593 of file fl_standard_message_codec.cc.

References FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE, fl_value_new_bool(), fl_value_new_null(), fl_value_ref(), kValueFalse, kValueFloat64, kValueFloat64List, kValueInt32, kValueInt32List, kValueInt64, kValueInt64List, kValueList, kValueMap, kValueNull, kValueString, kValueTrue, kValueUint8List, 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, 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().

596  {
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 }
static constexpr int kValueInt32List
static constexpr int kValueFloat64List
static constexpr int kValueFalse
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static constexpr int kValueTrue
FlMethodResponse GError ** error
static constexpr int kValueInt64
static constexpr int kValueFloat64
static constexpr int kValueMap
static FlValue * read_list_value(FlStandardMessageCodec *self, GBytes *buffer, size_t *offset, GError **error)
#define FL_MESSAGE_CODEC_ERROR
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: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
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:335
static constexpr int kValueList
return TRUE
Definition: fl_view.cc:107
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_null()
Definition: fl_value.cc:222

◆ 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 434 of file fl_standard_message_codec.cc.

References write_uint16(), and write_uint32().

Referenced by fl_standard_message_codec_write_value().

436  {
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 }
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)

◆ 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 475 of file fl_standard_message_codec.cc.

References 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_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_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, kValueFloat64, kValueFloat64List, kValueInt32, kValueInt32List, kValueInt64, kValueInt64List, kValueList, kValueMap, kValueNull, kValueString, kValueTrue, kValueUint8List, length, 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().

478  {
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);
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);
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);
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 }
static constexpr int kValueInt32List
static constexpr int kValueFloat64List
static constexpr int kValueFalse
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
static void write_align(GByteArray *buffer, guint align)
static void write_float64(GByteArray *buffer, double value)
static constexpr int kValueTrue
FlMethodResponse GError ** error
static constexpr int kValueInt64
static constexpr int kValueFloat64
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)
#define FL_MESSAGE_CODEC_ERROR
static void write_int64(GByteArray *buffer, int64_t value)
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
Definition: fl_value.cc:617
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
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
Definition: fl_value.cc:589
uint8_t value
size_t length
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:677
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_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
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)
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