[gnome-network-displays/cc-tmp: 45/80] cc: json helper improvements
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-network-displays/cc-tmp: 45/80] cc: json helper improvements
- Date: Fri, 9 Sep 2022 12:03:50 +0000 (UTC)
commit 9afedd1cea82c43b78bf49964144a4740db6213b
Author: Anupam Kumar <kyteinsky gmail com>
Date: Sat Sep 3 18:20:17 2022 +0530
cc: json helper improvements
src/cc/cc-json-helper.c | 44 ++++++++++++++++----------------------------
src/cc/cc-json-helper.h | 10 +++++-----
2 files changed, 21 insertions(+), 33 deletions(-)
---
diff --git a/src/cc/cc-json-helper.c b/src/cc/cc-json-helper.c
index c19a6d1..9ae0dc9 100644
--- a/src/cc/cc-json-helper.c
+++ b/src/cc/cc-json-helper.c
@@ -89,9 +89,8 @@ cc_json_helper_build_internal (JsonBuilder *builder,
}
}
-void
-cc_json_helper_build_node (JsonNode **output,
- gchar *first_key,
+JsonNode *
+cc_json_helper_build_node (gchar *first_key,
...)
{
va_list var_args;
@@ -103,15 +102,16 @@ cc_json_helper_build_node (JsonNode **output,
cc_json_helper_build_internal (builder, first_key, var_args);
json_builder_end_object (builder);
- *output = json_builder_get_root (builder);
+ JsonNode *node = json_builder_get_root (builder);
va_end (var_args);
g_object_unref (builder);
+
+ return g_steal_pointer (&node);
}
-void
-cc_json_helper_build_string (gchar **output,
- // gboolean pretty_print,
+gchar *
+cc_json_helper_build_string (/* gboolean pretty_print, */
gchar *first_key,
...)
{
@@ -129,21 +129,25 @@ cc_json_helper_build_string (gchar **output,
// json_generator_set_pretty (gen, pretty_print);
json_generator_set_root (gen, root);
- *output = json_generator_to_data (gen, NULL);
+ gchar *output = json_generator_to_data (gen, NULL);
va_end (var_args);
json_node_free (root);
g_object_unref (gen);
g_object_unref (builder);
+
+ return g_steal_pointer (&output);
}
-void
-cc_json_helper_node_to_string (gchar **output, JsonNode *node)
+gchar *
+cc_json_helper_node_to_string (JsonNode *node)
{
JsonGenerator *gen = json_generator_new ();
json_generator_set_root (gen, node);
- *output = json_generator_to_data (gen, NULL);
+ gchar *output = json_generator_to_data (gen, NULL);
g_object_unref (gen);
+
+ return g_steal_pointer (&output);
}
CcReceivedMessageType
@@ -153,21 +157,6 @@ cc_json_helper_get_message_type (Cast__Channel__CastMessage *message,
const gchar *message_type;
g_autoptr (GError) error = NULL;
- // if (reader == NULL)
- // {
- // g_autoptr(JsonParser) parser = NULL;
-
- // parser = json_parser_new ();
- // if (!json_parser_load_from_data (parser, message->payload_utf8, -1, &error))
- // {
- // cc_json_helper_dump_message (message);
- // g_warning ("CcJsonHelper: Error parsing received message JSON: %s", error->message);
- // return -1;
- // }
-
- // reader = json_reader_new (json_parser_get_root (parser));
- // }
-
gboolean typeExists = json_reader_read_member (reader, "type");
if (typeExists)
message_type = json_reader_get_string_value (reader);
@@ -229,8 +218,7 @@ cc_json_helper_dump_message (Cast__Channel__CastMessage *message, gboolean borke
payload_utf8_node = json_parser_get_root (parser);
- gchar *output;
- cc_json_helper_build_string (&output, //TRUE,
+ gchar *output = cc_json_helper_build_string (
"source_id", CC_JSON_TYPE_STRING, message->source_id,
"destination_id", CC_JSON_TYPE_STRING, message->destination_id,
"namespace", CC_JSON_TYPE_STRING, message->namespace_,
diff --git a/src/cc/cc-json-helper.h b/src/cc/cc-json-helper.h
index 02bcd80..354e318 100644
--- a/src/cc/cc-json-helper.h
+++ b/src/cc/cc-json-helper.h
@@ -43,11 +43,11 @@ typedef enum
} CcJsonType;
-// void cc_json_helper_build_node (JsonNode **output, gchar *first_key, ...) G_GNUC_NULL_TERMINATED;
-void cc_json_helper_build_node (JsonNode **output, gchar *first_key, ...);
-void cc_json_helper_build_string (gchar **output, gchar *first_key, ...);
-// void cc_json_helper_build_string (gchar **output, gboolean pretty_print, gchar *first_key, ...);
-void cc_json_helper_node_to_string (gchar **output, JsonNode *node);
+/* G_GNUC_NULL_TERMINATED */
+
+JsonNode * cc_json_helper_build_node (gchar *first_key, ...);
+gchar * cc_json_helper_build_string (/* gboolean pretty_print, */ gchar *first_key, ...);
+gchar * cc_json_helper_node_to_string (JsonNode *node);
CcReceivedMessageType cc_json_helper_get_message_type (Cast__Channel__CastMessage *message,
JsonReader *json_reader);
void cc_json_helper_dump_message (Cast__Channel__CastMessage *message, gboolean borked);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]