diff options
Diffstat (limited to 'src/core/lib/json/json.cc')
-rw-r--r-- | src/core/lib/json/json.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc index 4ad51f662a..2171e69455 100644 --- a/src/core/lib/json/json.cc +++ b/src/core/lib/json/json.cc @@ -19,6 +19,7 @@ #include <string.h> #include <grpc/support/alloc.h> +#include <grpc/support/log.h> #include "src/core/lib/json/json.h" @@ -44,5 +45,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 == NULL) { + GPR_ASSERT(sibling == NULL); + parent->child = child; + return child; + } + if (sibling == NULL) { + sibling = parent->child; + } + // always find the right most sibling. + while (sibling->next != NULL) { + 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; +} |