diff options
author | Nicolas Noble <nnoble@google.com> | 2015-03-12 17:22:33 -0700 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2015-03-13 02:03:01 +0100 |
commit | d446eb86fae18df3c473c96676da5bcf4f69178c (patch) | |
tree | bd1d84ca73d0694e2eaad96583e67b7a5de3ab01 /src/compiler/cpp_plugin.cc | |
parent | e758ed16aa0fe3ec085f45a4c1ad642b8ddd50fc (diff) |
Adding initial support for alternative protobuf libraries.
Diffstat (limited to 'src/compiler/cpp_plugin.cc')
-rw-r--r-- | src/compiler/cpp_plugin.cc | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc index feb158f89e..5b83aa85cf 100644 --- a/src/compiler/cpp_plugin.cc +++ b/src/compiler/cpp_plugin.cc @@ -35,26 +35,21 @@ // #include <memory> -#include <string> + +#include "src/compiler/config.h" #include "src/compiler/cpp_generator.h" #include "src/compiler/cpp_generator_helpers.h" -#include <google/protobuf/descriptor.h> -#include <google/protobuf/descriptor.pb.h> -#include <google/protobuf/compiler/code_generator.h> -#include <google/protobuf/compiler/plugin.h> -#include <google/protobuf/io/coded_stream.h> -#include <google/protobuf/io/zero_copy_stream.h> -class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator { +class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { public: CppGrpcGenerator() {} virtual ~CppGrpcGenerator() {} - virtual bool Generate(const google::protobuf::FileDescriptor *file, - const std::string ¶meter, - google::protobuf::compiler::GeneratorContext *context, - std::string *error) const { + virtual bool Generate(const grpc::protobuf::FileDescriptor *file, + const grpc::string ¶meter, + grpc::protobuf::compiler::GeneratorContext *context, + grpc::string *error) const { if (file->options().cc_generic_services()) { *error = "cpp grpc proto compiler plugin does not work with generic " @@ -63,7 +58,7 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator { return false; } - std::string file_name = grpc_generator::StripProto(file->name()); + grpc::string file_name = grpc_generator::StripProto(file->name()); // Generate .pb.h Insert(context, file_name + ".pb.h", "includes", @@ -81,17 +76,17 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator { private: // Insert the given code into the given file at the given insertion point. - void Insert(google::protobuf::compiler::GeneratorContext *context, - const std::string &filename, const std::string &insertion_point, - const std::string &code) const { - std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( + void Insert(grpc::protobuf::compiler::GeneratorContext *context, + const grpc::string &filename, const grpc::string &insertion_point, + const grpc::string &code) const { + std::unique_ptr<grpc::protobuf::io::ZeroCopyOutputStream> output( context->OpenForInsert(filename, insertion_point)); - google::protobuf::io::CodedOutputStream coded_out(output.get()); + grpc::protobuf::io::CodedOutputStream coded_out(output.get()); coded_out.WriteRaw(code.data(), code.size()); } }; int main(int argc, char *argv[]) { CppGrpcGenerator generator; - return google::protobuf::compiler::PluginMain(argc, argv, &generator); + return grpc::protobuf::compiler::PluginMain(argc, argv, &generator); } |