From e27d189f2165e904dbb3d61616edf3c643df71f0 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Thu, 19 May 2016 13:50:16 -0700 Subject: 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. --- test/cpp/qps/parse_json.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/cpp/qps/parse_json.cc') 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 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 -- cgit v1.2.3