| Flutter Linux Embedder |

Classes | Functions | Variables
fl_json_method_codec.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"`
`#include <gmodule.h>`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"`

Go to the source code of this file.

## Classes
struct | _FlJsonMethodCodec

## Functions
| G_DEFINE_TYPE (FlJsonMethodCodec, fl_json_method_codec, fl_method_codec_get_type()) static void fl_json_method_codec_dispose(GObject *object)
static GBytes * | fl_json_method_codec_encode_method_call (FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
static gboolean | fl_json_method_codec_decode_method_call (FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
static GBytes * | fl_json_method_codec_encode_success_envelope (FlMethodCodec *codec, FlValue *result, GError **error)
static GBytes * | fl_json_method_codec_encode_error_envelope (FlMethodCodec *codec, const gchar *code, const gchar *error_message, FlValue *details, GError **error)
static FlMethodResponse * | fl_json_method_codec_decode_response (FlMethodCodec *codec, GBytes *message, GError **error)
static void | fl_json_method_codec_class_init (FlJsonMethodCodecClass *klass)
static void | fl_json_method_codec_init (FlJsonMethodCodec *self)
G_MODULE_EXPORT FlJsonMethodCodec * | fl_json_method_codec_new ()

## Variables
static constexpr char | kMethodKey [] = "method"
static constexpr char | kArgsKey [] = "args"

## Function Documentation

## ◆ fl_json_method_codec_class_init()

static void fl_json_method_codec_class_init | ( | FlJsonMethodCodecClass * | klass | ) |
| static

Definition at line 187 of file fl_json_method_codec.cc.

187 {
188 G_OBJECT_CLASS(klass)->dispose = fl_json_method_codec_dispose;
189 FL_METHOD_CODEC_CLASS(klass)->encode_method_call =
190 fl_json_method_codec_encode_method_call;
191 FL_METHOD_CODEC_CLASS(klass)->decode_method_call =
192 fl_json_method_codec_decode_method_call;
193 FL_METHOD_CODEC_CLASS(klass)->encode_success_envelope =
194 fl_json_method_codec_encode_success_envelope;
195 FL_METHOD_CODEC_CLASS(klass)->encode_error_envelope =
196 fl_json_method_codec_encode_error_envelope;
197 FL_METHOD_CODEC_CLASS(klass)->decode_response =
198 fl_json_method_codec_decode_response;
199 }
fl_json_method_codec_decode_response
static FlMethodResponse * fl_json_method_codec_decode_response(FlMethodCodec *codec, GBytes *message, GError **error)
Definition: fl_json_method_codec.cc:127
fl_json_method_codec_encode_error_envelope
static GBytes * fl_json_method_codec_encode_error_envelope(FlMethodCodec *codec, const gchar *code, const gchar *error_message, FlValue *details, GError **error)
Definition: fl_json_method_codec.cc:106
fl_json_method_codec_decode_method_call
static gboolean fl_json_method_codec_decode_method_call(FlMethodCodec *codec, GBytes *message, gchar **name, FlValue **args, GError **error)
Definition: fl_json_method_codec.cc:50
fl_json_method_codec_encode_method_call
static GBytes * fl_json_method_codec_encode_method_call(FlMethodCodec *codec, const gchar *name, FlValue *args, GError **error)
Definition: fl_json_method_codec.cc:33
fl_json_method_codec_encode_success_envelope
static GBytes * fl_json_method_codec_encode_success_envelope(FlMethodCodec *codec, FlValue *result, GError **error)
Definition: fl_json_method_codec.cc:91

References fl_json_method_codec_decode_method_call(), fl_json_method_codec_decode_response(), fl_json_method_codec_encode_error_envelope(), fl_json_method_codec_encode_method_call(), and fl_json_method_codec_encode_success_envelope().

## ◆ fl_json_method_codec_decode_method_call()

static gboolean fl_json_method_codec_decode_method_call | ( | FlMethodCodec * | codec,
|  | GBytes * | message,
|  | gchar ** | name,
|  | FlValue ** | args,
|  | GError ** | error
| ) |  |
| static

Definition at line 50 of file fl_json_method_codec.cc.

54 {
55 FlJsonMethodCodec* self = FL_JSON_METHOD_CODEC(codec);
56
57 g_autoptr(FlValue) value = fl_message_codec_decode_message(
58 FL_MESSAGE_CODEC(self->codec), message, error);
59 if (value == nullptr) {
60 return FALSE;
61 }
62
63 if (fl_value_get_type(value) != FL_VALUE_TYPE_MAP) {
64 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
65 "Expected JSON map in method response, got %d instead",
66 fl_value_get_type(value));
67 return FALSE;
68 }
69
70 FlValue* method_value = fl_value_lookup_string(value, kMethodKey);
71 if (method_value == nullptr) {
72 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
73 "Missing JSON method field in method response");
74 return FALSE;
75 }
76 if (fl_value_get_type(method_value) != FL_VALUE_TYPE_STRING) {
77 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
78 "Expected JSON string for method name, got %d instead",
79 fl_value_get_type(method_value));
80 return FALSE;
81 }
82 FlValue* args_value = fl_value_lookup_string(value, kArgsKey);
83
84 *name = g_strdup(fl_value_get_string(method_value));
85 *args = args_value != nullptr ? fl_value_ref(args_value) : nullptr;
86
87 return TRUE;
88 }
message
const char * message
Definition: fl_accessibility_handler.cc:21
g_autoptr
g_autoptr(FlEngine) engine
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition: fl_event_channel.h:89
kArgsKey
static constexpr char kArgsKey[]
Definition: fl_json_method_codec.cc:12
kMethodKey
static constexpr char kMethodKey[]
Definition: fl_json_method_codec.cc:11
fl_message_codec_decode_message
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
Definition: fl_message_codec.cc:33
FL_MESSAGE_CODEC_ERROR_FAILED
@ FL_MESSAGE_CODEC_ERROR_FAILED
Definition: fl_message_codec.h:33
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_lookup_string
G_MODULE_EXPORT FlValue * fl_value_lookup_string(FlValue *self, const gchar *key)
Definition: fl_value.cc:811
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_ref
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:394
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
FL_VALUE_TYPE_STRING
@ FL_VALUE_TYPE_STRING
Definition: fl_value.h:68
FL_VALUE_TYPE_MAP
@ FL_VALUE_TYPE_MAP
Definition: fl_value.h:74

References args, error, fl_message_codec_decode_message(), FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_get_string(), fl_value_get_type(), fl_value_lookup_string(), fl_value_ref(), FL_VALUE_TYPE_MAP, FL_VALUE_TYPE_STRING, g_autoptr(), kArgsKey, kMethodKey, message, TRUE, and value.

Referenced by fl_json_method_codec_class_init().

## ◆ fl_json_method_codec_decode_response()

static FlMethodResponse* fl_json_method_codec_decode_response | ( | FlMethodCodec * | codec,
|  | GBytes * | message,
|  | GError ** | error
| ) |  |
| static

Definition at line 127 of file fl_json_method_codec.cc.

130 {
131 FlJsonMethodCodec* self = FL_JSON_METHOD_CODEC(codec);
132
133 g_autoptr(FlValue) value = fl_message_codec_decode_message(
134 FL_MESSAGE_CODEC(self->codec), message, error);
135 if (value == nullptr) {
136 return nullptr;
137 }
138
139 if (fl_value_get_type(value) != FL_VALUE_TYPE_LIST) {
140 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
141 "Expected JSON list in method response, got %d instead",
142 fl_value_get_type(value));
143 return nullptr;
144 }
145
146 size_t length = fl_value_get_length(value);
147 if (length == 1) {
148 return FL_METHOD_RESPONSE(
149 fl_method_success_response_new(fl_value_get_list_value(value, 0)));
150 } else if (length == 3) {
151 FlValue* code_value = fl_value_get_list_value(value, 0);
152 if (fl_value_get_type(code_value) != FL_VALUE_TYPE_STRING) {
153 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
154 "Error code wrong type");
155 return nullptr;
156 }
157 const gchar* code = fl_value_get_string(code_value);
158
159 FlValue* message_value = fl_value_get_list_value(value, 1);
160 if (fl_value_get_type(message_value) != FL_VALUE_TYPE_STRING &&
161 fl_value_get_type(message_value) != FL_VALUE_TYPE_NULL) {
162 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
163 "Error message wrong type");
164 return nullptr;
165 }
166 const gchar* message =
167 fl_value_get_type(message_value) == FL_VALUE_TYPE_STRING
168 ? fl_value_get_string(message_value)
169 : nullptr;
170
171 FlValue* args = fl_value_get_list_value(value, 2);
172 if (fl_value_get_type(args) == FL_VALUE_TYPE_NULL) {
173 args = nullptr;
174 }
175
176 return FL_METHOD_RESPONSE(
177 fl_method_error_response_new(code, message, args));
178 } else {
179 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
180 "Got response envelope of length %zi, expected 1 (success) or "
181 "3 (error)",
182 length);
183 return nullptr;
184 }
185 }
fl_method_error_response_new
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
Definition: fl_method_response.cc:144
fl_method_success_response_new
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
Definition: fl_method_response.cc:126
length
size_t length
Definition: fl_standard_message_codec_test.cc:1115
fl_value_get_list_value
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:776
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
FL_VALUE_TYPE_NULL
@ FL_VALUE_TYPE_NULL
Definition: fl_value.h:64
FL_VALUE_TYPE_LIST
@ FL_VALUE_TYPE_LIST
Definition: fl_value.h:73

References args, error, fl_message_codec_decode_message(), FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_method_error_response_new(), fl_method_success_response_new(), fl_value_get_length(), fl_value_get_list_value(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_LIST, FL_VALUE_TYPE_NULL, FL_VALUE_TYPE_STRING, g_autoptr(), length, message, and value.

Referenced by fl_json_method_codec_class_init().

## ◆ fl_json_method_codec_encode_error_envelope()

static GBytes* fl_json_method_codec_encode_error_envelope | ( | FlMethodCodec * | codec,
|  | const gchar * | code,
|  | const gchar * | error_message,
|  | FlValue * | details,
|  | GError ** | error
| ) |  |
| static

Definition at line 106 of file fl_json_method_codec.cc.

111 {
112 FlJsonMethodCodec* self = FL_JSON_METHOD_CODEC(codec);
113
114 g_autoptr(FlValue) message = fl_value_new_list();
115 fl_value_append_take(message, fl_value_new_string(code));
116 fl_value_append_take(message, error_message != nullptr
117 ? fl_value_new_string(error_message)
118 : fl_value_new_null());
119 fl_value_append_take(message, details != nullptr ? fl_value_ref(details)
120 : fl_value_new_null());
121
122 return fl_message_codec_encode_message(FL_MESSAGE_CODEC(self->codec), message,
123 error);
124 }
fl_message_codec_encode_message
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
Definition: fl_message_codec.cc:17
fl_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_new_list
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:349
fl_value_append_take
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:600
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251

References error, fl_message_codec_encode_message(), fl_value_append_take(), fl_value_new_list(), fl_value_new_null(), fl_value_new_string(), fl_value_ref(), g_autoptr(), and message.

Referenced by fl_json_method_codec_class_init().

## ◆ fl_json_method_codec_encode_method_call()

static GBytes* fl_json_method_codec_encode_method_call | ( | FlMethodCodec * | codec,
|  | const gchar * | name,
|  | FlValue * | args,
|  | GError ** | error
| ) |  |
| static

Definition at line 33 of file fl_json_method_codec.cc.

36 {
37 FlJsonMethodCodec* self = FL_JSON_METHOD_CODEC(codec);
38
39 g_autoptr(FlValue) message = fl_value_new_map();
40 fl_value_set_take(message, fl_value_new_string(kMethodKey),
41 fl_value_new_string(name));
42 fl_value_set_take(message, fl_value_new_string(kArgsKey),
43 args != nullptr ? fl_value_ref(args) : fl_value_new_null());
44
45 return fl_message_codec_encode_message(FL_MESSAGE_CODEC(self->codec), message,
46 error);
47 }
fl_value_set_take
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
Definition: fl_value.cc:618
fl_value_new_map
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366

References args, error, fl_message_codec_encode_message(), fl_value_new_map(), fl_value_new_null(), fl_value_new_string(), fl_value_ref(), fl_value_set_take(), g_autoptr(), kArgsKey, kMethodKey, and message.

Referenced by fl_json_method_codec_class_init().

## ◆ fl_json_method_codec_encode_success_envelope()

static GBytes* fl_json_method_codec_encode_success_envelope | ( | FlMethodCodec * | codec,
|  | FlValue * | result,
|  | GError ** | error
| ) |  |
| static

Definition at line 91 of file fl_json_method_codec.cc.

94 {
95 FlJsonMethodCodec* self = FL_JSON_METHOD_CODEC(codec);
96
97 g_autoptr(FlValue) message = fl_value_new_list();
98 fl_value_append_take(
99 message, result != nullptr ? fl_value_ref(result) : fl_value_new_null());
100
101 return fl_message_codec_encode_message(FL_MESSAGE_CODEC(self->codec), message,
102 error);
103 }

References error, fl_message_codec_encode_message(), fl_value_append_take(), fl_value_new_list(), fl_value_new_null(), fl_value_ref(), g_autoptr(), and message.

Referenced by fl_json_method_codec_class_init().

## ◆ fl_json_method_codec_init()

static void fl_json_method_codec_init | ( | FlJsonMethodCodec * | self | ) |
| static

Definition at line 201 of file fl_json_method_codec.cc.

201 {
202 self->codec = fl_json_message_codec_new();
203 }
fl_json_message_codec_new
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
Definition: fl_json_message_codec.cc:306

References fl_json_message_codec_new().

## ◆ fl_json_method_codec_new()

G_MODULE_EXPORT FlJsonMethodCodec* fl_json_method_codec_new | ( |  | ) |

Definition at line 205 of file fl_json_method_codec.cc.

205 {
206 return static_cast<FlJsonMethodCodec*>(
207 g_object_new(fl_json_method_codec_get_type(), nullptr));
208 }

Referenced by decode_error_method_call(), decode_error_response(), decode_method_call(), decode_response_with_error(), decode_response_with_success(), encode_error_envelope(), encode_method_call(), encode_success_envelope(), fl_platform_channel_new(), and fl_text_input_channel_new().

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlJsonMethodCodec | ,
|  | fl_json_method_codec | ,
|  | fl_method_codec_get_type() |
| ) |  |

Definition at line 20 of file fl_json_method_codec.cc.

24 {
25 FlJsonMethodCodec* self = FL_JSON_METHOD_CODEC(object);
26
27 g_clear_object(&self->codec);
28
29 G_OBJECT_CLASS(fl_json_method_codec_parent_class)->dispose(object);
30 }

## Variable Documentation

## ◆ kArgsKey

constexpr char kArgsKey[] = "args"
| static constexpr

Definition at line 12 of file fl_json_method_codec.cc.

Referenced by fl_json_method_codec_decode_method_call(), and fl_json_method_codec_encode_method_call().

## ◆ kMethodKey

constexpr char kMethodKey[] = "method"
| static constexpr

Definition at line 11 of file fl_json_method_codec.cc.

Referenced by fl_json_method_codec_decode_method_call(), and fl_json_method_codec_encode_method_call().