aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/json/json.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/json/json.cc')
-rw-r--r--src/core/lib/json/json.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc
index 2141db4c5b..816241bbf0 100644
--- a/src/core/lib/json/json.cc
+++ b/src/core/lib/json/json.cc
@@ -21,6 +21,7 @@
#include <string.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
#include "src/core/lib/json/json.h"
@@ -46,5 +47,40 @@ void grpc_json_destroy(grpc_json* json) {
json->parent->child = json->next;
}
+ if (json->owns_value) {
+ gpr_free((void*)json->value);
+ }
+
gpr_free(json);
}
+
+grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child,
+ grpc_json* sibling) {
+ // first child case.
+ if (parent->child == nullptr) {
+ GPR_ASSERT(sibling == nullptr);
+ parent->child = child;
+ return child;
+ }
+ if (sibling == nullptr) {
+ sibling = parent->child;
+ }
+ // always find the right most sibling.
+ while (sibling->next != nullptr) {
+ sibling = sibling->next;
+ }
+ sibling->next = child;
+ return child;
+}
+
+grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent,
+ const char* key, const char* value,
+ grpc_json_type type, bool owns_value) {
+ grpc_json* child = grpc_json_create(type);
+ grpc_json_link_child(parent, child, sibling);
+ child->owns_value = owns_value;
+ child->parent = parent;
+ child->value = value;
+ child->key = key;
+ return child;
+}