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.
pull/6656/head
David Klempner 9 years ago
parent d861b13aff
commit e27d189f21
  1. 6
      Makefile
  2. 5
      build.yaml
  3. 15
      test/cpp/qps/parse_json.cc
  4. 3
      test/cpp/qps/parse_json.h
  5. 18
      test/cpp/qps/report.cc
  6. 9
      tools/run_tests/sources_and_headers.json
  7. 3
      vsprojects/vcxproj/qps/qps.vcxproj
  8. 6
      vsprojects/vcxproj/qps/qps.vcxproj.filters
  9. 5
      vsprojects/vcxproj/test/qps_json_driver/qps_json_driver.vcxproj
  10. 8
      vsprojects/vcxproj/test/qps_json_driver/qps_json_driver.vcxproj.filters

@ -4255,6 +4255,7 @@ LIBQPS_SRC = \
test/cpp/qps/client_sync.cc \
test/cpp/qps/driver.cc \
test/cpp/qps/limit_cores.cc \
test/cpp/qps/parse_json.cc \
test/cpp/qps/qps_worker.cc \
test/cpp/qps/report.cc \
test/cpp/qps/server_async.cc \
@ -4310,6 +4311,7 @@ $(OBJDIR)/$(CONFIG)/test/cpp/qps/client_async.o: $(GENDIR)/src/proto/grpc/testin
$(OBJDIR)/$(CONFIG)/test/cpp/qps/client_sync.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/driver.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/limit_cores.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/parse_json.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_worker.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/report.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/server_async.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc
@ -11331,7 +11333,6 @@ endif
QPS_JSON_DRIVER_SRC = \
test/cpp/qps/parse_json.cc \
test/cpp/qps/qps_json_driver.cc \
QPS_JSON_DRIVER_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(QPS_JSON_DRIVER_SRC))))
@ -11363,8 +11364,6 @@ endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/qps/parse_json.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_json_driver.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a
deps_qps_json_driver: $(QPS_JSON_DRIVER_OBJS:.o=.dep)
@ -14577,6 +14576,7 @@ test/cpp/qps/client_async.cc: $(OPENSSL_DEP)
test/cpp/qps/client_sync.cc: $(OPENSSL_DEP)
test/cpp/qps/driver.cc: $(OPENSSL_DEP)
test/cpp/qps/limit_cores.cc: $(OPENSSL_DEP)
test/cpp/qps/parse_json.cc: $(OPENSSL_DEP)
test/cpp/qps/qps_worker.cc: $(OPENSSL_DEP)
test/cpp/qps/report.cc: $(OPENSSL_DEP)
test/cpp/qps/server_async.cc: $(OPENSSL_DEP)

@ -1120,6 +1120,7 @@ libs:
- test/cpp/qps/histogram.h
- test/cpp/qps/interarrival.h
- test/cpp/qps/limit_cores.h
- test/cpp/qps/parse_json.h
- test/cpp/qps/qps_worker.h
- test/cpp/qps/report.h
- test/cpp/qps/server.h
@ -1136,6 +1137,7 @@ libs:
- test/cpp/qps/client_sync.cc
- test/cpp/qps/driver.cc
- test/cpp/qps/limit_cores.cc
- test/cpp/qps/parse_json.cc
- test/cpp/qps/qps_worker.cc
- test/cpp/qps/report.cc
- test/cpp/qps/server_async.cc
@ -2811,10 +2813,7 @@ targets:
build: test
run: false
language: c++
headers:
- test/cpp/qps/parse_json.h
src:
- test/cpp/qps/parse_json.cc
- test/cpp/qps/qps_json_driver.cc
deps:
- qps

@ -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

@ -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

@ -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();

@ -2361,14 +2361,10 @@
"grpc_test_util",
"qps"
],
"headers": [
"test/cpp/qps/parse_json.h"
],
"headers": [],
"language": "c++",
"name": "qps_json_driver",
"src": [
"test/cpp/qps/parse_json.cc",
"test/cpp/qps/parse_json.h",
"test/cpp/qps/qps_json_driver.cc"
],
"third_party": false,
@ -4546,6 +4542,7 @@
"test/cpp/qps/histogram.h",
"test/cpp/qps/interarrival.h",
"test/cpp/qps/limit_cores.h",
"test/cpp/qps/parse_json.h",
"test/cpp/qps/qps_worker.h",
"test/cpp/qps/report.h",
"test/cpp/qps/server.h",
@ -4565,6 +4562,8 @@
"test/cpp/qps/interarrival.h",
"test/cpp/qps/limit_cores.cc",
"test/cpp/qps/limit_cores.h",
"test/cpp/qps/parse_json.cc",
"test/cpp/qps/parse_json.h",
"test/cpp/qps/qps_worker.cc",
"test/cpp/qps/qps_worker.h",
"test/cpp/qps/report.cc",

@ -152,6 +152,7 @@
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\histogram.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\interarrival.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\limit_cores.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\parse_json.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\qps_worker.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\report.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\server.h" />
@ -208,6 +209,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\limit_cores.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\parse_json.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\qps_worker.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\report.cc">

@ -28,6 +28,9 @@
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\limit_cores.cc">
<Filter>test\cpp\qps</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\parse_json.cc">
<Filter>test\cpp\qps</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\qps_worker.cc">
<Filter>test\cpp\qps</Filter>
</ClCompile>
@ -63,6 +66,9 @@
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\limit_cores.h">
<Filter>test\cpp\qps</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\parse_json.h">
<Filter>test\cpp\qps</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\qps_worker.h">
<Filter>test\cpp\qps</Filter>
</ClInclude>

@ -160,11 +160,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\parse_json.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\parse_json.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\qps_json_driver.cc">
</ClCompile>
</ItemGroup>

@ -1,18 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\parse_json.cc">
<Filter>test\cpp\qps</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\qps\qps_json_driver.cc">
<Filter>test\cpp\qps</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(SolutionDir)\..\test\cpp\qps\parse_json.h">
<Filter>test\cpp\qps</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="test">

Loading…
Cancel
Save