#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h"
#include <gmodule.h>
#include <cstring>
#include "rapidjson/reader.h"
#include "rapidjson/writer.h"
Go to the source code of this file.
|
| G_DEFINE_TYPE (FlJsonMessageCodec, fl_json_message_codec, fl_message_codec_get_type()) static gboolean write_value(rapidjson |
|
static GBytes * | fl_json_message_codec_encode_message (FlMessageCodec *codec, FlValue *message, GError **error) |
|
static FlValue * | fl_json_message_codec_decode_message (FlMessageCodec *codec, GBytes *message, GError **error) |
|
static void | fl_json_message_codec_class_init (FlJsonMessageCodecClass *klass) |
|
static void | fl_json_message_codec_init (FlJsonMessageCodec *self) |
|
G_MODULE_EXPORT FlJsonMessageCodec * | fl_json_message_codec_new () |
|
G_MODULE_EXPORT gchar * | fl_json_message_codec_encode (FlJsonMessageCodec *codec, FlValue *value, GError **error) |
|
G_MODULE_EXPORT FlValue * | fl_json_message_codec_decode (FlJsonMessageCodec *codec, const gchar *text, GError **error) |
|
◆ fl_json_message_codec_class_init()
static void fl_json_message_codec_class_init |
( |
FlJsonMessageCodecClass * |
klass | ) |
|
|
static |
Definition at line 297 of file fl_json_message_codec.cc.
297 {
298 FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
300 FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
302}
static GBytes * fl_json_message_codec_encode_message(FlMessageCodec *codec, FlValue *message, GError **error)
static FlValue * fl_json_message_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
◆ fl_json_message_codec_decode()
G_MODULE_EXPORT FlValue * fl_json_message_codec_decode |
( |
FlJsonMessageCodec * |
codec, |
|
|
const gchar * |
text, |
|
|
GError ** |
error |
|
) |
| |
fl_json_message_codec_decode: @codec: an #FlJsonMessageCodec. @text: UTF-8 text in JSON format. @error: (allow-none): #GError location to store the error occurring, or NULL.
Decodes a value from a JSON string.
Returns: an FlValue or NULL on error.
Definition at line 326 of file fl_json_message_codec.cc.
328 {
329 g_return_val_if_fail(FL_IS_JSON_CODEC(codec), nullptr);
330
331 g_autoptr(GBytes)
data = g_bytes_new_static(
text, strlen(
text));
334 if (
value ==
nullptr) {
335 return nullptr;
336 }
337
339}
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
typedefG_BEGIN_DECLS struct _FlValue FlValue
std::shared_ptr< const fml::Mapping > data
◆ fl_json_message_codec_decode_message()
static FlValue * fl_json_message_codec_decode_message |
( |
FlMessageCodec * |
codec, |
|
|
GBytes * |
message, |
|
|
GError ** |
error |
|
) |
| |
|
static |
Definition at line 258 of file fl_json_message_codec.cc.
260 {
261 gsize data_length;
263 static_cast<const char*
>(g_bytes_get_data(
message, &data_length));
264 if (!g_utf8_validate(
data, data_length,
nullptr)) {
267 "Message is not valid UTF8");
268 return nullptr;
269 }
270
272 rapidjson::Reader reader;
273 rapidjson::MemoryStream ss(
data, data_length);
274 if (!reader.Parse(ss, handler)) {
275 if (handler.
error !=
nullptr) {
277 handler.
error =
nullptr;
278 } else {
281 "Message is not valid JSON");
282 }
283 return nullptr;
284 }
285
287 if (
value ==
nullptr) {
290 "Message is not valid JSON");
291 return nullptr;
292 }
293
295}
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_UTF8
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON
#define FL_JSON_MESSAGE_CODEC_ERROR
◆ fl_json_message_codec_encode()
G_MODULE_EXPORT gchar * fl_json_message_codec_encode |
( |
FlJsonMessageCodec * |
codec, |
|
|
FlValue * |
value, |
|
|
GError ** |
error |
|
) |
| |
fl_json_message_codec_encode: @codec: an #FlJsonMessageCodec. @value: value to encode. @error: (allow-none): #GError location to store the error occurring, or NULL.
Encodes a value to a JSON string.
Returns: a JSON representation of this value or NULL on error.
Definition at line 311 of file fl_json_message_codec.cc.
313 {
314 g_return_val_if_fail(FL_IS_JSON_CODEC(codec), nullptr);
315
316 rapidjson::StringBuffer
buffer;
317 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
318
320 return nullptr;
321 }
322
323 return g_strdup(
buffer.GetString());
324}
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
◆ fl_json_message_codec_encode_message()
static GBytes * fl_json_message_codec_encode_message |
( |
FlMessageCodec * |
codec, |
|
|
FlValue * |
message, |
|
|
GError ** |
error |
|
) |
| |
|
static |
Definition at line 243 of file fl_json_message_codec.cc.
245 {
246 rapidjson::StringBuffer
buffer;
247 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
248
250 return nullptr;
251 }
252
254 return g_bytes_new(
text, strlen(
text));
255}
◆ fl_json_message_codec_init()
static void fl_json_message_codec_init |
( |
FlJsonMessageCodec * |
self | ) |
|
|
static |
◆ fl_json_message_codec_new()
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new |
( |
| ) |
|
Definition at line 306 of file fl_json_message_codec.cc.
306 {
307 return static_cast<FlJsonMessageCodec*>(
308 g_object_new(fl_json_message_codec_get_type(), nullptr));
309}
◆ G_DEFINE_TYPE()
G_DEFINE_TYPE |
( |
FlJsonMessageCodec |
, |
|
|
fl_json_message_codec |
, |
|
|
fl_message_codec_get_type() |
|
|
) |
| |
Definition at line 20 of file fl_json_message_codec.cc.
27 {
28 if (
value ==
nullptr) {
29 writer.Null();
31 }
32
35 writer.Null();
36 break;
39 break;
42 break;
45 break;
48 break;
50 writer.StartArray();
54 }
55 writer.EndArray();
56 break;
57 }
59 writer.StartArray();
63 }
64 writer.EndArray();
65 break;
66 }
68 writer.StartArray();
71 writer.Int64(
data[
i]);
72 }
73 writer.EndArray();
74 break;
75 }
77 writer.StartArray();
80 writer.Double(
data[
i]);
81 }
82 writer.EndArray();
83 break;
84 }
86 writer.StartArray();
90 }
91 }
92 writer.EndArray();
93 break;
94 }
96 writer.StartObject();
102 "Invalid object key type");
104 }
108 }
109 }
110 writer.EndObject();
111 break;
112 }
113 default:
118 }
119
121}
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_OBJECT_KEY_TYPE
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
#define FL_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT const double * fl_value_get_float_list(FlValue *self)
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
G_MODULE_EXPORT const int32_t * fl_value_get_int32_list(FlValue *self)
G_MODULE_EXPORT const int64_t * fl_value_get_int64_list(FlValue *self)
@ FL_VALUE_TYPE_INT32_LIST
@ FL_VALUE_TYPE_UINT8_LIST
@ FL_VALUE_TYPE_INT64_LIST
@ FL_VALUE_TYPE_FLOAT_LIST