diff options
author | David Klempner <klempner@google.com> | 2016-05-19 13:50:16 -0700 |
---|---|---|
committer | David Klempner <klempner@google.com> | 2016-06-08 17:11:26 -0700 |
commit | e27d189f2165e904dbb3d61616edf3c643df71f0 (patch) | |
tree | d400400b9b1ecae740a3e352f2676fffca9744f7 /test | |
parent | d861b13aff7481b4901ab012cfd51c5887b11a2e (diff) |
Factor out json seriailzation code and move it into parse_json.
This is for the same reasons as ParseJson, that is so that we can limit
the scope of the proto namespace differences between internal and
external.
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp/qps/parse_json.cc | 15 | ||||
-rw-r--r-- | test/cpp/qps/parse_json.h | 3 | ||||
-rw-r--r-- | test/cpp/qps/report.cc | 18 |
3 files changed, 21 insertions, 15 deletions
diff --git a/test/cpp/qps/parse_json.cc b/test/cpp/qps/parse_json.cc index a90bf6153c..be804281f8 100644 --- a/test/cpp/qps/parse_json.cc +++ b/test/cpp/qps/parse_json.cc @@ -61,5 +61,20 @@ void ParseJson(const grpc::string& json, const grpc::string& type, GPR_ASSERT(msg->ParseFromString(binary)); } +grpc::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg, + const grpc::string& type) { + std::unique_ptr<google::protobuf::util::TypeResolver> type_resolver( + google::protobuf::util::NewTypeResolverForDescriptorPool( + "type.googleapis.com", + google::protobuf::DescriptorPool::generated_pool())); + grpc::string binary; + grpc::string json_string; + msg.SerializeToString(&binary); + auto status = + BinaryToJsonString(type_resolver.get(), type, binary, &json_string); + GPR_ASSERT(status.ok()); + return json_string; +} + } // testing } // grpc diff --git a/test/cpp/qps/parse_json.h b/test/cpp/qps/parse_json.h index 42d7d22c53..ce1821f961 100644 --- a/test/cpp/qps/parse_json.h +++ b/test/cpp/qps/parse_json.h @@ -43,6 +43,9 @@ namespace testing { void ParseJson(const grpc::string& json, const grpc::string& type, GRPC_CUSTOM_MESSAGE* msg); +grpc::string SerializeJson(const GRPC_CUSTOM_MESSAGE& msg, + const grpc::string& type); + } // testing } // grpc diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index 3ae41399cf..2ec7d8676c 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -35,11 +35,9 @@ #include <fstream> -#include <google/protobuf/util/json_util.h> -#include <google/protobuf/util/type_resolver_util.h> - #include <grpc/support/log.h> #include "test/cpp/qps/driver.h" +#include "test/cpp/qps/parse_json.h" #include "test/cpp/qps/stats.h" namespace grpc { @@ -104,18 +102,8 @@ void GprLogReporter::ReportTimes(const ScenarioResult& result) { } void JsonReporter::ReportQPS(const ScenarioResult& result) { - std::unique_ptr<google::protobuf::util::TypeResolver> type_resolver( - google::protobuf::util::NewTypeResolverForDescriptorPool( - "type.googleapis.com", - google::protobuf::DescriptorPool::generated_pool())); - grpc::string binary; - grpc::string json_string; - result.SerializeToString(&binary); - auto status = BinaryToJsonString( - type_resolver.get(), "type.googleapis.com/grpc.testing.ScenarioResult", - binary, &json_string); - GPR_ASSERT(status.ok()); - + grpc::string json_string = + SerializeJson(result, "type.googleapis.com/grpc.testing.ScenarioResult"); std::ofstream output_file(report_file_); output_file << json_string; output_file.close(); |