From 935d68589d51fc336ad57ebba6aebb837d7c1593 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 26 Oct 2021 22:23:17 +0000 Subject: [PATCH] nope, go back to non-inlining ExtractJsonType() --- src/core/lib/json/json_util.cc | 30 ++++++++++++++++++++++ src/core/lib/json/json_util.h | 46 +++++++++++++++------------------- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/core/lib/json/json_util.cc b/src/core/lib/json/json_util.cc index ed1de9a6efc..e88708c82b9 100644 --- a/src/core/lib/json/json_util.cc +++ b/src/core/lib/json/json_util.cc @@ -97,6 +97,36 @@ bool ExtractJsonObject(const Json& json, absl::string_view field_name, return true; } +bool ExtractJsonType(const Json& json, absl::string_view field_name, + bool* output, + std::vector* error_list) { + return ExtractJsonBool(json, field_name, output, error_list); +} + +bool ExtractJsonType(const Json& json, absl::string_view field_name, + std::string* output, + std::vector* error_list) { + return ExtractJsonString(json, field_name, output, error_list); +} + +bool ExtractJsonType(const Json& json, absl::string_view field_name, + absl::string_view* output, + std::vector* error_list) { + return ExtractJsonString(json, field_name, output, error_list); +} + +bool ExtractJsonType(const Json& json, absl::string_view field_name, + const Json::Array** output, + std::vector* error_list) { + return ExtractJsonArray(json, field_name, output, error_list); +} + +bool ExtractJsonType(const Json& json, absl::string_view field_name, + const Json::Object** output, + std::vector* error_list) { + return ExtractJsonObject(json, field_name, output, error_list); +} + bool ParseJsonObjectFieldAsDuration(const Json::Object& object, absl::string_view field_name, grpc_millis* output, diff --git a/src/core/lib/json/json_util.h b/src/core/lib/json/json_util.h index 7b9fdddd79d..e9daf717ffe 100644 --- a/src/core/lib/json/json_util.h +++ b/src/core/lib/json/json_util.h @@ -40,6 +40,7 @@ bool ParseDurationFromJson(const Json& field, grpc_millis* duration); // Return true on success, false otherwise. If an error is encountered during // parsing, a descriptive error is appended to \a error_list. // + template bool ExtractJsonNumber(const Json& json, absl::string_view field_name, NumericType* output, @@ -84,39 +85,32 @@ bool ExtractJsonObject(const Json& json, absl::string_view field_name, const Json::Object** output, std::vector* error_list); +// // Wrappers for automatically choosing one of the above functions based // on output parameter type. +// + template -inline bool ExtractJsonType(const Json& json, absl::string_view field_name, +bool ExtractJsonType(const Json& json, absl::string_view field_name, NumericType* output, std::vector* error_list) { return ExtractJsonNumber(json, field_name, output, error_list); } -inline bool ExtractJsonType(const Json& json, absl::string_view field_name, - bool* output, - std::vector* error_list) { - return ExtractJsonBool(json, field_name, output, error_list); -} -inline bool ExtractJsonType(const Json& json, absl::string_view field_name, - std::string* output, - std::vector* error_list) { - return ExtractJsonString(json, field_name, output, error_list); -} -inline bool ExtractJsonType(const Json& json, absl::string_view field_name, - absl::string_view* output, - std::vector* error_list) { - return ExtractJsonString(json, field_name, output, error_list); -} -inline bool ExtractJsonType(const Json& json, absl::string_view field_name, - const Json::Array** output, - std::vector* error_list) { - return ExtractJsonArray(json, field_name, output, error_list); -} -inline bool ExtractJsonType(const Json& json, absl::string_view field_name, - const Json::Object** output, - std::vector* error_list) { - return ExtractJsonObject(json, field_name, output, error_list); -} +bool ExtractJsonType(const Json& json, absl::string_view field_name, + bool* output, + std::vector* error_list); +bool ExtractJsonType(const Json& json, absl::string_view field_name, + std::string* output, + std::vector* error_list); +bool ExtractJsonType(const Json& json, absl::string_view field_name, + absl::string_view* output, + std::vector* error_list); +bool ExtractJsonType(const Json& json, absl::string_view field_name, + const Json::Array** output, + std::vector* error_list); +bool ExtractJsonType(const Json& json, absl::string_view field_name, + const Json::Object** output, + std::vector* error_list); // Extracts a field from a JSON object, automatically selecting the type // of parsing based on the output parameter type.