diff options
author | 2016-05-19 13:50:16 -0700 | |
---|---|---|
committer | 2016-06-08 17:11:26 -0700 | |
commit | e27d189f2165e904dbb3d61616edf3c643df71f0 (patch) | |
tree | d400400b9b1ecae740a3e352f2676fffca9744f7 /test/cpp/qps/parse_json.cc | |
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/cpp/qps/parse_json.cc')
-rw-r--r-- | test/cpp/qps/parse_json.cc | 15 |
1 files changed, 15 insertions, 0 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 |