aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler/cpp_plugin.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/cpp_plugin.cc')
-rw-r--r--src/compiler/cpp_plugin.cc36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc
index acbe128213..88c704948e 100644
--- a/src/compiler/cpp_plugin.cc
+++ b/src/compiler/cpp_plugin.cc
@@ -58,11 +58,6 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
return false;
}
- if (file->service_count() == 0) {
- // No services. Do nothing.
- return true;
- }
-
grpc_cpp_generator::Parameters generator_parameters;
if (!parameter.empty()) {
@@ -84,16 +79,27 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
grpc::string file_name = grpc_generator::StripProto(file->name());
- // Generate .pb.h
- Insert(context, file_name + ".pb.h", "includes",
- grpc_cpp_generator::GetHeaderIncludes(file, generator_parameters));
- Insert(context, file_name + ".pb.h", "namespace_scope",
- grpc_cpp_generator::GetHeaderServices(file, generator_parameters));
- // Generate .pb.cc
- Insert(context, file_name + ".pb.cc", "includes",
- grpc_cpp_generator::GetSourceIncludes(generator_parameters));
- Insert(context, file_name + ".pb.cc", "namespace_scope",
- grpc_cpp_generator::GetSourceServices(file, generator_parameters));
+ grpc::string header_code =
+ grpc_cpp_generator::GetHeaderPrologue(file, generator_parameters) +
+ grpc_cpp_generator::GetHeaderIncludes(file, generator_parameters) +
+ grpc_cpp_generator::GetHeaderServices(file, generator_parameters) +
+ grpc_cpp_generator::GetHeaderEpilogue(file, generator_parameters);
+ std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> header_output(
+ context->Open(file_name + ".grpc.pb.h"));
+ grpc::protobuf::io::CodedOutputStream header_coded_out(
+ header_output.get());
+ header_coded_out.WriteRaw(header_code.data(), header_code.size());
+
+ grpc::string source_code =
+ grpc_cpp_generator::GetSourcePrologue(file, generator_parameters) +
+ grpc_cpp_generator::GetSourceIncludes(file, generator_parameters) +
+ grpc_cpp_generator::GetSourceServices(file, generator_parameters) +
+ grpc_cpp_generator::GetSourceEpilogue(file, generator_parameters);
+ std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> source_output(
+ context->Open(file_name + ".grpc.pb.cc"));
+ grpc::protobuf::io::CodedOutputStream source_coded_out(
+ source_output.get());
+ source_coded_out.WriteRaw(source_code.data(), source_code.size());
return true;
}