aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Nicolas Noble <nnoble@google.com>2015-03-12 17:22:33 -0700
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-03-13 02:03:01 +0100
commitd446eb86fae18df3c473c96676da5bcf4f69178c (patch)
treebd1d84ca73d0694e2eaad96583e67b7a5de3ab01 /src
parente758ed16aa0fe3ec085f45a4c1ad642b8ddd50fc (diff)
Adding initial support for alternative protobuf libraries.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/config.h93
-rw-r--r--src/compiler/cpp_generator.cc103
-rw-r--r--src/compiler/cpp_generator.h16
-rw-r--r--src/compiler/cpp_generator_helpers.h18
-rw-r--r--src/compiler/cpp_plugin.cc33
-rw-r--r--src/compiler/generator_helpers.h15
6 files changed, 178 insertions, 100 deletions
diff --git a/src/compiler/config.h b/src/compiler/config.h
new file mode 100644
index 0000000000..dc8803ceab
--- /dev/null
+++ b/src/compiler/config.h
@@ -0,0 +1,93 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef SRC_COMPILER_CONFIG_H
+#define SRC_COMPILER_CONFIG_H
+
+#include <grpc++/config.h>
+
+#ifndef GRPC_CUSTOM_DESCRIPTOR
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/descriptor.pb.h>
+#define GRPC_CUSTOM_DESCRIPTOR ::google::protobuf::Descriptor
+#define GRPC_CUSTOM_FILEDESCRIPTOR ::google::protobuf::FileDescriptor
+#define GRPC_CUSTOM_METHODDESCRIPTOR ::google::protobuf::MethodDescriptor
+#define GRPC_CUSTOM_SERVICEDESCRIPTOR ::google::protobuf::ServiceDescriptor
+#endif
+
+#ifndef GRPC_CUSTOM_CODEGENERATOR
+#include <google/protobuf/compiler/code_generator.h>
+#define GRPC_CUSTOM_CODEGENERATOR ::google::protobuf::compiler::CodeGenerator
+#define GRPC_CUSTOM_GENERATORCONTEXT ::google::protobuf::compiler::GeneratorContext
+#endif
+
+#ifndef GRPC_CUSTOM_PRINTER
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/printer.h>
+#include <google/protobuf/io/zero_copy_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
+#define GRPC_CUSTOM_PRINTER ::google::protobuf::io::Printer
+#define GRPC_CUSTOM_CODEDOUTPUTSTREAM ::google::protobuf::io::CodedOutputStream
+#define GRPC_CUSTOM_STRINGOUTPUTSTREAM ::google::protobuf::io::StringOutputStream
+#define GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ::google::protobuf::io::ZeroCopyOutputStream
+#endif
+
+#ifndef GRPC_CUSTOM_PLUGINMAIN
+#include <google/protobuf/compiler/plugin.h>
+#define GRPC_CUSTOM_PLUGINMAIN ::google::protobuf::compiler::PluginMain
+#endif
+
+namespace grpc {
+namespace protobuf {
+typedef GRPC_CUSTOM_DESCRIPTOR Descriptor;
+typedef GRPC_CUSTOM_FILEDESCRIPTOR FileDescriptor;
+typedef GRPC_CUSTOM_METHODDESCRIPTOR MethodDescriptor;
+typedef GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor;
+namespace compiler {
+typedef GRPC_CUSTOM_CODEGENERATOR CodeGenerator;
+typedef GRPC_CUSTOM_GENERATORCONTEXT GeneratorContext;
+static inline int PluginMain(int argc, char* argv[],
+ const CodeGenerator* generator) {
+ return GRPC_CUSTOM_PLUGINMAIN(argc, argv, generator);
+}
+} // namespace compiler
+namespace io {
+typedef GRPC_CUSTOM_PRINTER Printer;
+typedef GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream;
+typedef GRPC_CUSTOM_STRINGOUTPUTSTREAM StringOutputStream;
+typedef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream;
+} // namespace io
+} // namespace protobuf
+} // namespace grpc
+
+#endif // SRC_COMPILER_CONFIG_H
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc
index eade70d533..d5004624d4 100644
--- a/src/compiler/cpp_generator.cc
+++ b/src/compiler/cpp_generator.cc
@@ -31,45 +31,42 @@
*
*/
-#include <string>
#include <map>
#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/io/printer.h>
-#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
+
+#include "src/compiler/config.h"
+
#include <sstream>
namespace grpc_cpp_generator {
namespace {
template <class T>
-std::string as_string(T x) {
+grpc::string as_string(T x) {
std::ostringstream out;
out << x;
return out.str();
}
-bool NoStreaming(const google::protobuf::MethodDescriptor *method) {
+bool NoStreaming(const grpc::protobuf::MethodDescriptor *method) {
return !method->client_streaming() && !method->server_streaming();
}
-bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor *method) {
+bool ClientOnlyStreaming(const grpc::protobuf::MethodDescriptor *method) {
return method->client_streaming() && !method->server_streaming();
}
-bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor *method) {
+bool ServerOnlyStreaming(const grpc::protobuf::MethodDescriptor *method) {
return !method->client_streaming() && method->server_streaming();
}
-bool BidiStreaming(const google::protobuf::MethodDescriptor *method) {
+bool BidiStreaming(const grpc::protobuf::MethodDescriptor *method) {
return method->client_streaming() && method->server_streaming();
}
-bool HasUnaryCalls(const google::protobuf::FileDescriptor *file) {
+bool HasUnaryCalls(const grpc::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (NoStreaming(file->service(i)->method(j))) {
@@ -80,7 +77,7 @@ bool HasUnaryCalls(const google::protobuf::FileDescriptor *file) {
return false;
}
-bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor *file) {
+bool HasClientOnlyStreaming(const grpc::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (ClientOnlyStreaming(file->service(i)->method(j))) {
@@ -91,7 +88,7 @@ bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor *file) {
return false;
}
-bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor *file) {
+bool HasServerOnlyStreaming(const grpc::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (ServerOnlyStreaming(file->service(i)->method(j))) {
@@ -102,7 +99,7 @@ bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor *file) {
return false;
}
-bool HasBidiStreaming(const google::protobuf::FileDescriptor *file) {
+bool HasBidiStreaming(const grpc::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (BidiStreaming(file->service(i)->method(j))) {
@@ -114,8 +111,8 @@ bool HasBidiStreaming(const google::protobuf::FileDescriptor *file) {
}
} // namespace
-std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
- std::string temp =
+grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file) {
+ grpc::string temp =
"#include <grpc++/impl/internal_stub.h>\n"
"#include <grpc++/impl/service_type.h>\n"
"#include <grpc++/status.h>\n"
@@ -161,7 +158,7 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
return temp;
}
-std::string GetSourceIncludes() {
+grpc::string GetSourceIncludes() {
return "#include <grpc++/async_unary_call.h>\n"
"#include <grpc++/channel_interface.h>\n"
"#include <grpc++/impl/client_unary_call.h>\n"
@@ -171,9 +168,9 @@ std::string GetSourceIncludes() {
"#include <grpc++/stream.h>\n";
}
-void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
- const google::protobuf::MethodDescriptor *method,
- std::map<std::string, std::string> *vars) {
+void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::MethodDescriptor *method,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@@ -223,9 +220,9 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
}
void PrintHeaderServerMethodSync(
- google::protobuf::io::Printer *printer,
- const google::protobuf::MethodDescriptor *method,
- std::map<std::string, std::string> *vars) {
+ grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::MethodDescriptor *method,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@@ -258,9 +255,9 @@ void PrintHeaderServerMethodSync(
}
void PrintHeaderServerMethodAsync(
- google::protobuf::io::Printer *printer,
- const google::protobuf::MethodDescriptor *method,
- std::map<std::string, std::string> *vars) {
+ grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::MethodDescriptor *method,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@@ -294,9 +291,9 @@ void PrintHeaderServerMethodAsync(
}
}
-void PrintHeaderService(google::protobuf::io::Printer *printer,
- const google::protobuf::ServiceDescriptor *service,
- std::map<std::string, std::string> *vars) {
+void PrintHeaderService(grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::ServiceDescriptor *service,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Service"] = service->name();
printer->Print(*vars,
@@ -356,11 +353,11 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
printer->Print("};\n");
}
-std::string GetHeaderServices(const google::protobuf::FileDescriptor *file) {
- std::string output;
- google::protobuf::io::StringOutputStream output_stream(&output);
- google::protobuf::io::Printer printer(&output_stream, '$');
- std::map<std::string, std::string> vars;
+grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file) {
+ grpc::string output;
+ grpc::protobuf::io::StringOutputStream output_stream(&output);
+ grpc::protobuf::io::Printer printer(&output_stream, '$');
+ std::map<grpc::string, grpc::string> vars;
for (int i = 0; i < file->service_count(); ++i) {
PrintHeaderService(&printer, file->service(i), &vars);
@@ -369,9 +366,9 @@ std::string GetHeaderServices(const google::protobuf::FileDescriptor *file) {
return output;
}
-void PrintSourceClientMethod(google::protobuf::io::Printer *printer,
- const google::protobuf::MethodDescriptor *method,
- std::map<std::string, std::string> *vars) {
+void PrintSourceClientMethod(grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::MethodDescriptor *method,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@@ -485,9 +482,9 @@ void PrintSourceClientMethod(google::protobuf::io::Printer *printer,
}
}
-void PrintSourceServerMethod(google::protobuf::io::Printer *printer,
- const google::protobuf::MethodDescriptor *method,
- std::map<std::string, std::string> *vars) {
+void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::MethodDescriptor *method,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@@ -536,9 +533,9 @@ void PrintSourceServerMethod(google::protobuf::io::Printer *printer,
}
void PrintSourceServerAsyncMethod(
- google::protobuf::io::Printer *printer,
- const google::protobuf::MethodDescriptor *method,
- std::map<std::string, std::string> *vars) {
+ grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::MethodDescriptor *method,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@@ -590,9 +587,9 @@ void PrintSourceServerAsyncMethod(
}
}
-void PrintSourceService(google::protobuf::io::Printer *printer,
- const google::protobuf::ServiceDescriptor *service,
- std::map<std::string, std::string> *vars) {
+void PrintSourceService(grpc::protobuf::io::Printer *printer,
+ const grpc::protobuf::ServiceDescriptor *service,
+ std::map<grpc::string, grpc::string> *vars) {
(*vars)["Service"] = service->name();
printer->Print(*vars, "static const char* $Service$_method_names[] = {\n");
@@ -640,7 +637,7 @@ void PrintSourceService(google::protobuf::io::Printer *printer,
"}\n");
printer->Print("service_ = new ::grpc::RpcService();\n");
for (int i = 0; i < service->method_count(); ++i) {
- const google::protobuf::MethodDescriptor *method = service->method(i);
+ const grpc::protobuf::MethodDescriptor *method = service->method(i);
(*vars)["Idx"] = as_string(i);
(*vars)["Method"] = method->name();
(*vars)["Request"] =
@@ -705,11 +702,11 @@ void PrintSourceService(google::protobuf::io::Printer *printer,
printer->Print("}\n\n");
}
-std::string GetSourceServices(const google::protobuf::FileDescriptor *file) {
- std::string output;
- google::protobuf::io::StringOutputStream output_stream(&output);
- google::protobuf::io::Printer printer(&output_stream, '$');
- std::map<std::string, std::string> vars;
+grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file) {
+ grpc::string output;
+ grpc::protobuf::io::StringOutputStream output_stream(&output);
+ grpc::protobuf::io::Printer printer(&output_stream, '$');
+ std::map<grpc::string, grpc::string> vars;
// Package string is empty or ends with a dot. It is used to fully qualify
// method names.
vars["Package"] = file->package();
diff --git a/src/compiler/cpp_generator.h b/src/compiler/cpp_generator.h
index 1bfe5a8819..2ecdb5c47e 100644
--- a/src/compiler/cpp_generator.h
+++ b/src/compiler/cpp_generator.h
@@ -34,27 +34,21 @@
#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
-#include <string>
-
-namespace google {
-namespace protobuf {
-class FileDescriptor;
-} // namespace protobuf
-} // namespace google
+#include "src/compiler/config.h"
namespace grpc_cpp_generator {
// Return the includes needed for generated header file.
-std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file);
+grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file);
// Return the includes needed for generated source file.
-std::string GetSourceIncludes();
+grpc::string GetSourceIncludes();
// Return the services for generated header file.
-std::string GetHeaderServices(const google::protobuf::FileDescriptor *file);
+grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file);
// Return the services for generated source file.
-std::string GetSourceServices(const google::protobuf::FileDescriptor *file);
+grpc::string GetSourceServices(const grpc::protobuf::FileDescriptor *file);
} // namespace grpc_cpp_generator
diff --git a/src/compiler/cpp_generator_helpers.h b/src/compiler/cpp_generator_helpers.h
index 16abbde8d4..be68cbe695 100644
--- a/src/compiler/cpp_generator_helpers.h
+++ b/src/compiler/cpp_generator_helpers.h
@@ -35,30 +35,28 @@
#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
#include <map>
-#include <string>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/descriptor.pb.h>
+#include "src/compiler/config.h"
#include "src/compiler/generator_helpers.h"
namespace grpc_cpp_generator {
-inline std::string DotsToColons(const std::string &name) {
+inline grpc::string DotsToColons(const grpc::string &name) {
return grpc_generator::StringReplace(name, ".", "::");
}
-inline std::string DotsToUnderscores(const std::string &name) {
+inline grpc::string DotsToUnderscores(const grpc::string &name) {
return grpc_generator::StringReplace(name, ".", "_");
}
-inline std::string ClassName(const google::protobuf::Descriptor *descriptor,
- bool qualified) {
+inline grpc::string ClassName(const grpc::protobuf::Descriptor *descriptor,
+ bool qualified) {
// Find "outer", the descriptor of the top-level message in which
// "descriptor" is embedded.
- const google::protobuf::Descriptor *outer = descriptor;
+ const grpc::protobuf::Descriptor *outer = descriptor;
while (outer->containing_type() != NULL) outer = outer->containing_type();
- const std::string &outer_name = outer->full_name();
- std::string inner_name = descriptor->full_name().substr(outer_name.size());
+ const grpc::string &outer_name = outer->full_name();
+ grpc::string inner_name = descriptor->full_name().substr(outer_name.size());
if (qualified) {
return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);
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 &parameter,
- google::protobuf::compiler::GeneratorContext *context,
- std::string *error) const {
+ virtual bool Generate(const grpc::protobuf::FileDescriptor *file,
+ const grpc::string &parameter,
+ 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);
}
diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h
index 2035820f0d..1e6727dd4c 100644
--- a/src/compiler/generator_helpers.h
+++ b/src/compiler/generator_helpers.h
@@ -35,14 +35,15 @@
#define GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
#include <map>
-#include <string>
+
+#include "src/compiler/config.h"
namespace grpc_generator {
-inline bool StripSuffix(std::string *filename, const std::string &suffix) {
+inline bool StripSuffix(grpc::string *filename, const grpc::string &suffix) {
if (filename->length() >= suffix.length()) {
size_t suffix_pos = filename->length() - suffix.length();
- if (filename->compare(suffix_pos, std::string::npos, suffix) == 0) {
+ if (filename->compare(suffix_pos, grpc::string::npos, suffix) == 0) {
filename->resize(filename->size() - suffix.size());
return true;
}
@@ -51,20 +52,20 @@ inline bool StripSuffix(std::string *filename, const std::string &suffix) {
return false;
}
-inline std::string StripProto(std::string filename) {
+inline grpc::string StripProto(grpc::string filename) {
if (!StripSuffix(&filename, ".protodevel")) {
StripSuffix(&filename, ".proto");
}
return filename;
}
-inline std::string StringReplace(std::string str, const std::string &from,
- const std::string &to) {
+inline grpc::string StringReplace(grpc::string str, const grpc::string &from,
+ const grpc::string &to) {
size_t pos = 0;
for (;;) {
pos = str.find(from, pos);
- if (pos == std::string::npos) {
+ if (pos == grpc::string::npos) {
break;
}
str.replace(pos, from.length(), to);