Flutter Engine
fl_string_codec.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"
#include <gmodule.h>
#include <cstring>

Go to the source code of this file.

Classes

struct  _FlStringCodec
 

Functions

static GBytes * fl_string_codec_encode_message (FlMessageCodec *codec, FlValue *value, GError **error)
 
static FlValuefl_string_codec_decode_message (FlMessageCodec *codec, GBytes *message, GError **error)
 
static void fl_string_codec_class_init (FlStringCodecClass *klass)
 
static void fl_string_codec_init (FlStringCodec *self)
 
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new ()
 

Function Documentation

◆ fl_string_codec_class_init()

static void fl_string_codec_class_init ( FlStringCodecClass *  klass)
static

Definition at line 44 of file fl_string_codec.cc.

References fl_string_codec_decode_message(), and fl_string_codec_encode_message().

44  {
45  FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
47  FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
49 }
static GBytes * fl_string_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
static FlValue * fl_string_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)

◆ fl_string_codec_decode_message()

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

Definition at line 35 of file fl_string_codec.cc.

References fl_value_new_string_sized().

Referenced by fl_string_codec_class_init().

37  {
38  gsize data_length;
39  const gchar* data =
40  static_cast<const gchar*>(g_bytes_get_data(message, &data_length));
41  return fl_value_new_string_sized(data, data_length);
42 }
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
Definition: fl_value.cc:254

◆ fl_string_codec_encode_message()

static GBytes* fl_string_codec_encode_message ( FlMessageCodec *  codec,
FlValue value,
GError **  error 
)
static

Definition at line 20 of file fl_string_codec.cc.

References FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE, fl_value_get_string(), fl_value_get_type(), and FL_VALUE_TYPE_STRING.

Referenced by fl_string_codec_class_init().

22  {
24  g_set_error(error, FL_MESSAGE_CODEC_ERROR,
26  "Only string values supported");
27  return nullptr;
28  }
29 
30  const gchar* text = fl_value_get_string(value);
31  return g_bytes_new(text, strlen(text));
32 }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
FlMethodResponse GError ** error
#define FL_MESSAGE_CODEC_ERROR
uint8_t value
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596

◆ fl_string_codec_init()

static void fl_string_codec_init ( FlStringCodec *  self)
static

Definition at line 51 of file fl_string_codec.cc.

51 {}

◆ fl_string_codec_new()

G_MODULE_EXPORT FlStringCodec* fl_string_codec_new ( )

Definition at line 53 of file fl_string_codec.cc.

Referenced by decode_message(), encode_message(), encode_message_error(), and TEST().

53  {
54  return static_cast<FlStringCodec*>(
55  g_object_new(fl_string_codec_get_type(), nullptr));
56 }