diff options
Diffstat (limited to 'src/core/lib/json')
-rw-r--r-- | src/core/lib/json/json.cc | 13 | ||||
-rw-r--r-- | src/core/lib/json/json.h | 5 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/core/lib/json/json.cc b/src/core/lib/json/json.cc index 816241bbf0..e78b73cefd 100644 --- a/src/core/lib/json/json.cc +++ b/src/core/lib/json/json.cc @@ -18,10 +18,12 @@ #include <grpc/support/port_platform.h> +#include <inttypes.h> #include <string.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/string_util.h> #include "src/core/lib/json/json.h" @@ -56,6 +58,8 @@ void grpc_json_destroy(grpc_json* json) { grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child, grpc_json* sibling) { + // link child up to parent + child->parent = parent; // first child case. if (parent->child == nullptr) { GPR_ASSERT(sibling == nullptr); @@ -79,8 +83,15 @@ grpc_json* grpc_json_create_child(grpc_json* sibling, grpc_json* parent, 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; } + +grpc_json* grpc_json_add_number_string_child(grpc_json* parent, grpc_json* it, + const char* name, int64_t num) { + char* num_str; + gpr_asprintf(&num_str, "%" PRId64, num); + return grpc_json_create_child(it, parent, name, num_str, GRPC_JSON_STRING, + true); +} diff --git a/src/core/lib/json/json.h b/src/core/lib/json/json.h index f93b43048b..8173845c72 100644 --- a/src/core/lib/json/json.h +++ b/src/core/lib/json/json.h @@ -91,4 +91,9 @@ 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); +/* Creates a child json string object from the integer num, then links the + json object into the parent's json tree */ +grpc_json* grpc_json_add_number_string_child(grpc_json* parent, grpc_json* it, + const char* name, int64_t num); + #endif /* GRPC_CORE_LIB_JSON_JSON_H */ |