|
Flutter Linux Embedder
|
|
Go to the documentation of this file.
11 #include "rapidjson/reader.h"
12 #include "rapidjson/writer.h"
21 fl_json_message_codec,
22 fl_message_codec_get_type())
25 static gboolean write_value(rapidjson::Writer<rapidjson::StringBuffer>& writer,
28 if (
value ==
nullptr) {
71 writer.Int64(data[
i]);
80 writer.Double(data[
i]);
102 "Invalid object key type");
130 stack = g_ptr_array_new_with_free_func(
137 g_ptr_array_unref(
stack);
138 if (
key !=
nullptr) {
141 if (
error !=
nullptr) {
148 if (
stack->len == 0) {
164 if (head ==
nullptr) {
173 "Can't add value to non container");
199 if (
i == G_MAXINT64) {
210 "RawNumber not supported");
221 bool Key(
const char* str, rapidjson::SizeType
length,
bool copy) {
222 if (
key !=
nullptr) {
246 rapidjson::StringBuffer
buffer;
247 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
249 if (!write_value(writer, message,
error)) {
253 const gchar* text =
buffer.GetString();
254 return g_bytes_new(text, strlen(text));
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");
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;
281 "Message is not valid JSON");
287 if (
value ==
nullptr) {
290 "Message is not valid JSON");
298 FL_MESSAGE_CODEC_CLASS(klass)->encode_message =
300 FL_MESSAGE_CODEC_CLASS(klass)->decode_message =
307 return static_cast<FlJsonMessageCodec*
>(
308 g_object_new(fl_json_message_codec_get_type(),
nullptr));
314 g_return_val_if_fail(FL_IS_JSON_CODEC(codec),
nullptr);
316 rapidjson::StringBuffer
buffer;
317 rapidjson::Writer<rapidjson::StringBuffer> writer(
buffer);
323 return g_strdup(
buffer.GetString());
329 g_return_val_if_fail(FL_IS_JSON_CODEC(codec),
nullptr);
331 g_autoptr(GBytes) data = g_bytes_new_static(text, strlen(text));
333 FL_MESSAGE_CODEC(codec), data,
error);
334 if (
value ==
nullptr) {
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_UTF8
const G_MODULE_EXPORT int32_t * fl_value_get_int32_list(FlValue *self)
@ FL_VALUE_TYPE_UINT8_LIST
G_MODULE_EXPORT FlValue * fl_value_new_string_sized(const gchar *value, size_t value_length)
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_OBJECT_KEY_TYPE
bool String(const char *str, rapidjson::SizeType length, bool copy)
G_MODULE_EXPORT FlValue * fl_value_new_list()
const G_MODULE_EXPORT double * fl_value_get_float_list(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_bool(bool value)
typedefG_BEGIN_DECLS struct _FlValue FlValue
G_MODULE_EXPORT FlJsonMessageCodec * fl_json_message_codec_new()
G_MODULE_EXPORT void fl_value_set_take(FlValue *self, FlValue *key, FlValue *value)
G_MODULE_EXPORT FlValue * fl_value_new_null()
G_MODULE_EXPORT bool fl_value_get_bool(FlValue *self)
const G_MODULE_EXPORT uint8_t * fl_value_get_uint8_list(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
const G_MODULE_EXPORT gchar * fl_value_get_string(FlValue *self)
bool EndArray(rapidjson::SizeType elementCount)
bool Key(const char *str, rapidjson::SizeType length, bool copy)
G_DEFINE_TYPE(FlJsonMessageCodec, fl_json_message_codec, fl_message_codec_get_type()) static gboolean write_value(rapidjson
FlMessageCodec parent_instance
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
G_MODULE_EXPORT void fl_value_unref(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
G_DEFINE_QUARK(fl_binary_messenger_codec_error_quark, fl_binary_messenger_codec_error) G_DECLARE_FINAL_TYPE(FlBinaryMessengerImpl
G_MODULE_EXPORT FlValue * fl_value_new_map()
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
static void fl_json_message_codec_class_init(FlJsonMessageCodecClass *klass)
G_MODULE_EXPORT gchar * fl_json_message_codec_encode(FlJsonMessageCodec *codec, FlValue *value, GError **error)
bool EndObject(rapidjson::SizeType memberCount)
bool RawNumber(const char *str, rapidjson::SizeType length, bool copy)
static GBytes * fl_json_message_codec_encode_message(FlMessageCodec *codec, FlValue *message, GError **error)
G_MODULE_EXPORT GQuark fl_json_message_codec_error_quark(void) G_GNUC_CONST
@ FL_MESSAGE_CODEC_ERROR_FAILED
G_MODULE_EXPORT double fl_value_get_float(FlValue *self)
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
@ FL_VALUE_TYPE_INT64_LIST
void push(FlValue *value)
static FlValue * fl_json_message_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
const uint8_t uint32_t uint32_t GError ** error
@ FL_VALUE_TYPE_FLOAT_LIST
#define FL_JSON_MESSAGE_CODEC_ERROR
G_MODULE_EXPORT FlValue * fl_json_message_codec_decode(FlJsonMessageCodec *codec, const gchar *text, GError **error)
G_MODULE_EXPORT void fl_value_append(FlValue *self, FlValue *value)
static const uint8_t buffer[]
@ FL_VALUE_TYPE_INT32_LIST
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
G_MODULE_EXPORT FlValue * fl_value_new_float(double value)
@ FL_JSON_MESSAGE_CODEC_ERROR_INVALID_JSON
G_MODULE_EXPORT FlValue * fl_value_get_map_key(FlValue *self, size_t index)
const G_MODULE_EXPORT int64_t * fl_value_get_int64_list(FlValue *self)
static void fl_json_message_codec_init(FlJsonMessageCodec *self)
G_MODULE_EXPORT FlValue * fl_value_get_map_value(FlValue *self, size_t index)
#define FL_MESSAGE_CODEC_ERROR