summaryrefslogtreecommitdiffstats
path: root/contrib/libs/grpc/src/compiler
diff options
context:
space:
mode:
authorakastornov <[email protected]>2022-02-10 16:46:03 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:46:03 +0300
commit3a2de774d91ca8d7325aaf81c200b1d2047725e6 (patch)
tree5674a780ce03a8bbd794733a19c7a70d587e4a14 /contrib/libs/grpc/src/compiler
parent7bd11ff35e97544d119e43447e3e865f2588ee7f (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/grpc/src/compiler')
-rw-r--r--contrib/libs/grpc/src/compiler/README.md6
-rw-r--r--contrib/libs/grpc/src/compiler/config.h82
-rw-r--r--contrib/libs/grpc/src/compiler/cpp_generator.cc1822
-rw-r--r--contrib/libs/grpc/src/compiler/cpp_generator.h112
-rw-r--r--contrib/libs/grpc/src/compiler/cpp_generator_helpers.h88
-rw-r--r--contrib/libs/grpc/src/compiler/cpp_plugin.cc28
-rw-r--r--contrib/libs/grpc/src/compiler/csharp_generator.cc1122
-rw-r--r--contrib/libs/grpc/src/compiler/csharp_generator.h40
-rw-r--r--contrib/libs/grpc/src/compiler/csharp_generator_helpers.h58
-rw-r--r--contrib/libs/grpc/src/compiler/generator_helpers.h454
-rw-r--r--contrib/libs/grpc/src/compiler/node_generator.cc420
-rw-r--r--contrib/libs/grpc/src/compiler/node_generator.h38
-rw-r--r--contrib/libs/grpc/src/compiler/node_generator_helpers.h58
-rw-r--r--contrib/libs/grpc/src/compiler/objective_c_generator.cc352
-rw-r--r--contrib/libs/grpc/src/compiler/objective_c_generator.h48
-rw-r--r--contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h54
-rw-r--r--contrib/libs/grpc/src/compiler/php_generator.cc220
-rw-r--r--contrib/libs/grpc/src/compiler/php_generator_helpers.h54
-rw-r--r--contrib/libs/grpc/src/compiler/python_generator.cc934
-rw-r--r--contrib/libs/grpc/src/compiler/python_generator.h76
-rw-r--r--contrib/libs/grpc/src/compiler/python_plugin.cc36
-rw-r--r--contrib/libs/grpc/src/compiler/ruby_generator.cc332
-rw-r--r--contrib/libs/grpc/src/compiler/ruby_generator.h38
-rw-r--r--contrib/libs/grpc/src/compiler/ruby_generator_helpers-inl.h84
-rw-r--r--contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h84
-rw-r--r--contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h168
26 files changed, 3404 insertions, 3404 deletions
diff --git a/contrib/libs/grpc/src/compiler/README.md b/contrib/libs/grpc/src/compiler/README.md
index d5684af7ff2..20f2585af71 100644
--- a/contrib/libs/grpc/src/compiler/README.md
+++ b/contrib/libs/grpc/src/compiler/README.md
@@ -1,4 +1,4 @@
# Overview
-
-This directory contains source code for gRPC protocol buffer compiler (*protoc*) plugins. Along with `protoc`,
-these plugins are used to generate gRPC client and server stubs from `.proto` files.
+
+This directory contains source code for gRPC protocol buffer compiler (*protoc*) plugins. Along with `protoc`,
+these plugins are used to generate gRPC client and server stubs from `.proto` files.
diff --git a/contrib/libs/grpc/src/compiler/config.h b/contrib/libs/grpc/src/compiler/config.h
index 95213b0f045..fe09deed059 100644
--- a/contrib/libs/grpc/src/compiler/config.h
+++ b/contrib/libs/grpc/src/compiler/config.h
@@ -1,62 +1,62 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef SRC_COMPILER_CONFIG_H
-#define SRC_COMPILER_CONFIG_H
-
+ *
+ */
+
+#ifndef SRC_COMPILER_CONFIG_H
+#define SRC_COMPILER_CONFIG_H
+
#include "src/compiler/config_protobuf.h"
-
+
#include <util/generic/string.h>
#ifdef GRPC_CUSTOM_STRING
#warning GRPC_CUSTOM_STRING is no longer supported. Please use TString.
-#endif
-
-namespace grpc {
-
+#endif
+
+namespace grpc {
+
// Using grpc::string and grpc::to_string is discouraged in favor of
// TString and ToString. This is only for legacy code using
// them explictly.
typedef TString string; // deprecated
-
-namespace protobuf {
-
-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);
-}
-static inline void ParseGeneratorParameter(
- const string& parameter, std::vector<std::pair<string, string> >* options) {
- GRPC_CUSTOM_PARSEGENERATORPARAMETER(parameter, options);
-}
-
-} // namespace compiler
-namespace io {
-typedef GRPC_CUSTOM_PRINTER Printer;
-typedef GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream;
-typedef GRPC_CUSTOM_STRINGOUTPUTSTREAM StringOutputStream;
-} // namespace io
-} // namespace protobuf
-} // namespace grpc
-
+
+namespace protobuf {
+
+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);
+}
+static inline void ParseGeneratorParameter(
+ const string& parameter, std::vector<std::pair<string, string> >* options) {
+ GRPC_CUSTOM_PARSEGENERATORPARAMETER(parameter, options);
+}
+
+} // namespace compiler
+namespace io {
+typedef GRPC_CUSTOM_PRINTER Printer;
+typedef GRPC_CUSTOM_CODEDOUTPUTSTREAM CodedOutputStream;
+typedef GRPC_CUSTOM_STRINGOUTPUTSTREAM StringOutputStream;
+} // namespace io
+} // namespace protobuf
+} // namespace grpc
+
namespace grpc_cpp_generator {
static const char* const kCppGeneratorMessageHeaderExt = ".pb.h";
@@ -64,4 +64,4 @@ static const char* const kCppGeneratorServiceHeaderExt = ".grpc.pb.h";
} // namespace grpc_cpp_generator
-#endif // SRC_COMPILER_CONFIG_H
+#endif // SRC_COMPILER_CONFIG_H
diff --git a/contrib/libs/grpc/src/compiler/cpp_generator.cc b/contrib/libs/grpc/src/compiler/cpp_generator.cc
index 57591774745..e431614c0f7 100644
--- a/contrib/libs/grpc/src/compiler/cpp_generator.cc
+++ b/contrib/libs/grpc/src/compiler/cpp_generator.cc
@@ -1,39 +1,39 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <map>
-
-#include "src/compiler/cpp_generator.h"
-
-#include <sstream>
-
+ *
+ */
+
+#include <map>
+
+#include "src/compiler/cpp_generator.h"
+
+#include <sstream>
+
#include <util/string/cast.h>
-namespace grpc_cpp_generator {
-namespace {
-
-template <class T>
+namespace grpc_cpp_generator {
+namespace {
+
+template <class T>
TString as_string(T x) {
- std::ostringstream out;
- out << x;
+ std::ostringstream out;
+ out << x;
return out.str();
-}
-
+}
+
inline bool ClientOnlyStreaming(const grpc_generator::Method* method) {
return method->ClientStreaming() && !method->ServerStreaming();
}
@@ -44,85 +44,85 @@ inline bool ServerOnlyStreaming(const grpc_generator::Method* method) {
TString FilenameIdentifier(const TString& filename) {
TString result;
- for (unsigned i = 0; i < filename.size(); i++) {
- char c = filename[i];
- if (isalnum(c)) {
- result.push_back(c);
- } else {
- static char hex[] = "0123456789abcdef";
- result.push_back('_');
- result.push_back(hex[(c >> 4) & 0xf]);
- result.push_back(hex[c & 0xf]);
- }
- }
- return result;
-}
-} // namespace
-
-template <class T, size_t N>
+ for (unsigned i = 0; i < filename.size(); i++) {
+ char c = filename[i];
+ if (isalnum(c)) {
+ result.push_back(c);
+ } else {
+ static char hex[] = "0123456789abcdef";
+ result.push_back('_');
+ result.push_back(hex[(c >> 4) & 0xf]);
+ result.push_back(hex[c & 0xf]);
+ }
+ }
+ return result;
+}
+} // namespace
+
+template <class T, size_t N>
T* array_end(T (&array)[N]) {
- return array + N;
-}
-
+ return array + N;
+}
+
void PrintIncludes(grpc_generator::Printer* printer,
const std::vector<TString>& headers,
bool use_system_headers, const TString& search_path) {
std::map<TString, TString> vars;
-
+
vars["l"] = use_system_headers ? '<' : '"';
vars["r"] = use_system_headers ? '>' : '"';
-
+
if (!search_path.empty()) {
vars["l"] += search_path;
if (search_path[search_path.size() - 1] != '/') {
- vars["l"] += '/';
- }
- }
-
- for (auto i = headers.begin(); i != headers.end(); i++) {
- vars["h"] = *i;
- printer->Print(vars, "#include $l$$h$$r$\n");
- }
-}
-
+ vars["l"] += '/';
+ }
+ }
+
+ for (auto i = headers.begin(); i != headers.end(); i++) {
+ vars["h"] = *i;
+ printer->Print(vars, "#include $l$$h$$r$\n");
+ }
+}
+
TString GetHeaderPrologue(grpc_generator::File* file,
const Parameters& params) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
-
- vars["filename"] = file->filename();
- vars["filename_identifier"] = FilenameIdentifier(file->filename());
- vars["filename_base"] = file->filename_without_ext();
+
+ vars["filename"] = file->filename();
+ vars["filename_identifier"] = FilenameIdentifier(file->filename());
+ vars["filename_base"] = file->filename_without_ext();
vars["message_header_ext"] = params.message_header_extension.empty()
? kCppGeneratorMessageHeaderExt
: params.message_header_extension;
-
+
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
- printer->Print(vars,
- "// If you make any local change, they will be lost.\n");
- printer->Print(vars, "// source: $filename$\n");
+ printer->Print(vars,
+ "// If you make any local change, they will be lost.\n");
+ printer->Print(vars, "// source: $filename$\n");
TString leading_comments = file->GetLeadingComments("//");
- if (!leading_comments.empty()) {
- printer->Print(vars, "// Original file comments:\n");
+ if (!leading_comments.empty()) {
+ printer->Print(vars, "// Original file comments:\n");
printer->PrintRaw(leading_comments.c_str());
- }
- printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n");
- printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n");
- printer->Print(vars, "\n");
- printer->Print(vars, "#if defined(__GNUC__)\n");
- printer->Print(vars, "#pragma GCC system_header\n");
- printer->Print(vars, "#endif\n");
- printer->Print(vars, "\n");
- printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
+ }
+ printer->Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n");
+ printer->Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n");
+ printer->Print(vars, "\n");
+ printer->Print(vars, "#if defined(__GNUC__)\n");
+ printer->Print(vars, "#pragma GCC system_header\n");
+ printer->Print(vars, "#endif\n");
+ printer->Print(vars, "\n");
+ printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
printer->Print(vars, file->additional_headers().c_str());
- printer->Print(vars, "\n");
- }
- return output;
-}
-
+ printer->Print(vars, "\n");
+ }
+ return output;
+}
+
// Convert from "a/b/c.proto" to "#include \"a/b/c$message_header_ext$\"\n"
TString ImportInludeFromProtoName(const TString& proto_name) {
return TString("#include \"") +
@@ -133,11 +133,11 @@ TString ImportInludeFromProtoName(const TString& proto_name) {
TString GetHeaderIncludes(grpc_generator::File* file,
const Parameters& params) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
-
+
if (!params.additional_header_includes.empty()) {
PrintIncludes(printer.get(), params.additional_header_includes, false,
"");
@@ -169,8 +169,8 @@ TString GetHeaderIncludes(grpc_generator::File* file,
std::vector<TString> headers(headers_strs, array_end(headers_strs));
PrintIncludes(printer.get(), headers, params.use_system_headers,
params.grpc_search_path);
- printer->Print(vars, "\n");
-
+ printer->Print(vars, "\n");
+
vars["message_header_ext"] = params.message_header_extension.empty()
? kCppGeneratorMessageHeaderExt
: params.message_header_extension;
@@ -184,27 +184,27 @@ TString GetHeaderIncludes(grpc_generator::File* file,
printer->PrintRaw("\n");
}
- if (!file->package().empty()) {
+ if (!file->package().empty()) {
std::vector<TString> parts = file->package_parts();
-
- for (auto part = parts.begin(); part != parts.end(); part++) {
- vars["part"] = *part;
- printer->Print(vars, "namespace $part$ {\n");
- }
- printer->Print(vars, "\n");
- }
- }
- return output;
-}
-
+
+ for (auto part = parts.begin(); part != parts.end(); part++) {
+ vars["part"] = *part;
+ printer->Print(vars, "namespace $part$ {\n");
+ }
+ printer->Print(vars, "\n");
+ }
+ }
+ return output;
+}
+
void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars,
bool is_public) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
-
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
+
struct {
TString prefix;
TString method_params; // extra arguments to method
@@ -212,12 +212,12 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
} async_prefixes[] = {{"Async", ", void* tag", ", tag"},
{"PrepareAsync", "", ""}};
- if (is_public) {
- if (method->NoStreaming()) {
- printer->Print(
- *vars,
- "virtual ::grpc::Status $Method$(::grpc::ClientContext* context, "
- "const $Request$& request, $Response$* response) = 0;\n");
+ if (is_public) {
+ if (method->NoStreaming()) {
+ printer->Print(
+ *vars,
+ "virtual ::grpc::Status $Method$(::grpc::ClientContext* context, "
+ "const $Request$& request, $Response$* response) = 0;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
printer->Print(
@@ -237,18 +237,18 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
printer->Print("}\n");
}
} else if (ClientOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>"
- " $Method$("
- "::grpc::ClientContext* context, $Response$* response) {\n");
- printer->Indent();
- printer->Print(
- *vars,
- "return std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>"
- "($Method$Raw(context, response));\n");
- printer->Outdent();
- printer->Print("}\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>"
+ " $Method$("
+ "::grpc::ClientContext* context, $Response$* response) {\n");
+ printer->Indent();
+ printer->Print(
+ *vars,
+ "return std::unique_ptr< ::grpc::ClientWriterInterface< $Request$>>"
+ "($Method$Raw(context, response));\n");
+ printer->Outdent();
+ printer->Print("}\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -270,18 +270,18 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
printer->Print("}\n");
}
} else if (ServerOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>"
- " $Method$(::grpc::ClientContext* context, const $Request$& request)"
- " {\n");
- printer->Indent();
- printer->Print(
- *vars,
- "return std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>"
- "($Method$Raw(context, request));\n");
- printer->Outdent();
- printer->Print("}\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>"
+ " $Method$(::grpc::ClientContext* context, const $Request$& request)"
+ " {\n");
+ printer->Indent();
+ printer->Print(
+ *vars,
+ "return std::unique_ptr< ::grpc::ClientReaderInterface< $Response$>>"
+ "($Method$Raw(context, request));\n");
+ printer->Outdent();
+ printer->Print("}\n");
for (auto& async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -301,19 +301,19 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
printer->Outdent();
printer->Print("}\n");
}
- } else if (method->BidiStreaming()) {
- printer->Print(*vars,
- "std::unique_ptr< ::grpc::ClientReaderWriterInterface< "
- "$Request$, $Response$>> "
- "$Method$(::grpc::ClientContext* context) {\n");
- printer->Indent();
- printer->Print(
- *vars,
- "return std::unique_ptr< "
- "::grpc::ClientReaderWriterInterface< $Request$, $Response$>>("
- "$Method$Raw(context));\n");
- printer->Outdent();
- printer->Print("}\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(*vars,
+ "std::unique_ptr< ::grpc::ClientReaderWriterInterface< "
+ "$Request$, $Response$>> "
+ "$Method$(::grpc::ClientContext* context) {\n");
+ printer->Indent();
+ printer->Print(
+ *vars,
+ "return std::unique_ptr< "
+ "::grpc::ClientReaderWriterInterface< $Request$, $Response$>>("
+ "$Method$Raw(context));\n");
+ printer->Outdent();
+ printer->Print("}\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -333,9 +333,9 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
printer->Outdent();
printer->Print("}\n");
}
- }
- } else {
- if (method->NoStreaming()) {
+ }
+ } else {
+ if (method->NoStreaming()) {
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
printer->Print(
@@ -346,11 +346,11 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
"::grpc::CompletionQueue* cq) = 0;\n");
}
} else if (ClientOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "virtual ::grpc::ClientWriterInterface< $Request$>*"
- " $Method$Raw("
- "::grpc::ClientContext* context, $Response$* response) = 0;\n");
+ printer->Print(
+ *vars,
+ "virtual ::grpc::ClientWriterInterface< $Request$>*"
+ " $Method$Raw("
+ "::grpc::ClientContext* context, $Response$* response) = 0;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -362,11 +362,11 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
"::grpc::CompletionQueue* cq$AsyncMethodParams$) = 0;\n");
}
} else if (ServerOnlyStreaming(method)) {
- printer->Print(
- *vars,
+ printer->Print(
+ *vars,
"virtual ::grpc::ClientReaderInterface< $Response$>* "
"$Method$Raw("
- "::grpc::ClientContext* context, const $Request$& request) = 0;\n");
+ "::grpc::ClientContext* context, const $Request$& request) = 0;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -377,11 +377,11 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
"::grpc::ClientContext* context, const $Request$& request, "
"::grpc::CompletionQueue* cq$AsyncMethodParams$) = 0;\n");
}
- } else if (method->BidiStreaming()) {
- printer->Print(*vars,
- "virtual ::grpc::ClientReaderWriterInterface< $Request$, "
- "$Response$>* "
- "$Method$Raw(::grpc::ClientContext* context) = 0;\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(*vars,
+ "virtual ::grpc::ClientReaderWriterInterface< $Request$, "
+ "$Response$>* "
+ "$Method$Raw(::grpc::ClientContext* context) = 0;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -392,17 +392,17 @@ void PrintHeaderClientMethodInterfaces(grpc_generator::Printer* printer,
"$AsyncPrefix$$Method$Raw(::grpc::ClientContext* context, "
"::grpc::CompletionQueue* cq$AsyncMethodParams$) = 0;\n");
}
- }
- }
-}
-
+ }
+ }
+}
+
void PrintHeaderClientMethod(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars,
- bool is_public) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
+ bool is_public) {
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
struct {
TString prefix;
TString method_params; // extra arguments to method
@@ -410,12 +410,12 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
} async_prefixes[] = {{"Async", ", void* tag", ", tag"},
{"PrepareAsync", "", ""}};
- if (is_public) {
- if (method->NoStreaming()) {
- printer->Print(
- *vars,
- "::grpc::Status $Method$(::grpc::ClientContext* context, "
- "const $Request$& request, $Response$* response) override;\n");
+ if (is_public) {
+ if (method->NoStreaming()) {
+ printer->Print(
+ *vars,
+ "::grpc::Status $Method$(::grpc::ClientContext* context, "
+ "const $Request$& request, $Response$* response) override;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
printer->Print(
@@ -433,17 +433,17 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
printer->Print("}\n");
}
} else if (ClientOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "std::unique_ptr< ::grpc::ClientWriter< $Request$>>"
- " $Method$("
- "::grpc::ClientContext* context, $Response$* response) {\n");
- printer->Indent();
- printer->Print(*vars,
- "return std::unique_ptr< ::grpc::ClientWriter< $Request$>>"
- "($Method$Raw(context, response));\n");
- printer->Outdent();
- printer->Print("}\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientWriter< $Request$>>"
+ " $Method$("
+ "::grpc::ClientContext* context, $Response$* response) {\n");
+ printer->Indent();
+ printer->Print(*vars,
+ "return std::unique_ptr< ::grpc::ClientWriter< $Request$>>"
+ "($Method$Raw(context, response));\n");
+ printer->Outdent();
+ printer->Print("}\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -463,18 +463,18 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
printer->Print("}\n");
}
} else if (ServerOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "std::unique_ptr< ::grpc::ClientReader< $Response$>>"
- " $Method$(::grpc::ClientContext* context, const $Request$& request)"
- " {\n");
- printer->Indent();
- printer->Print(
- *vars,
- "return std::unique_ptr< ::grpc::ClientReader< $Response$>>"
- "($Method$Raw(context, request));\n");
- printer->Outdent();
- printer->Print("}\n");
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientReader< $Response$>>"
+ " $Method$(::grpc::ClientContext* context, const $Request$& request)"
+ " {\n");
+ printer->Indent();
+ printer->Print(
+ *vars,
+ "return std::unique_ptr< ::grpc::ClientReader< $Response$>>"
+ "($Method$Raw(context, request));\n");
+ printer->Outdent();
+ printer->Print("}\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -493,18 +493,18 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
printer->Outdent();
printer->Print("}\n");
}
- } else if (method->BidiStreaming()) {
- printer->Print(
- *vars,
- "std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>>"
- " $Method$(::grpc::ClientContext* context) {\n");
- printer->Indent();
- printer->Print(*vars,
- "return std::unique_ptr< "
- "::grpc::ClientReaderWriter< $Request$, $Response$>>("
- "$Method$Raw(context));\n");
- printer->Outdent();
- printer->Print("}\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(
+ *vars,
+ "std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>>"
+ " $Method$(::grpc::ClientContext* context) {\n");
+ printer->Indent();
+ printer->Print(*vars,
+ "return std::unique_ptr< "
+ "::grpc::ClientReaderWriter< $Request$, $Response$>>("
+ "$Method$Raw(context));\n");
+ printer->Outdent();
+ printer->Print("}\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -523,9 +523,9 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
printer->Outdent();
printer->Print("}\n");
}
- }
- } else {
- if (method->NoStreaming()) {
+ }
+ } else {
+ if (method->NoStreaming()) {
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
printer->Print(
@@ -536,10 +536,10 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
"::grpc::CompletionQueue* cq) override;\n");
}
} else if (ClientOnlyStreaming(method)) {
- printer->Print(*vars,
- "::grpc::ClientWriter< $Request$>* $Method$Raw("
- "::grpc::ClientContext* context, $Response$* response) "
- "override;\n");
+ printer->Print(*vars,
+ "::grpc::ClientWriter< $Request$>* $Method$Raw("
+ "::grpc::ClientContext* context, $Response$* response) "
+ "override;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -551,10 +551,10 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
"::grpc::CompletionQueue* cq$AsyncMethodParams$) override;\n");
}
} else if (ServerOnlyStreaming(method)) {
- printer->Print(*vars,
- "::grpc::ClientReader< $Response$>* $Method$Raw("
- "::grpc::ClientContext* context, const $Request$& request)"
- " override;\n");
+ printer->Print(*vars,
+ "::grpc::ClientReader< $Response$>* $Method$Raw("
+ "::grpc::ClientContext* context, const $Request$& request)"
+ " override;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -565,10 +565,10 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
"::grpc::ClientContext* context, const $Request$& request, "
"::grpc::CompletionQueue* cq$AsyncMethodParams$) override;\n");
}
- } else if (method->BidiStreaming()) {
- printer->Print(*vars,
- "::grpc::ClientReaderWriter< $Request$, $Response$>* "
- "$Method$Raw(::grpc::ClientContext* context) override;\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(*vars,
+ "::grpc::ClientReaderWriter< $Request$, $Response$>* "
+ "$Method$Raw(::grpc::ClientContext* context) override;\n");
for (auto async_prefix : async_prefixes) {
(*vars)["AsyncPrefix"] = async_prefix.prefix;
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
@@ -579,10 +579,10 @@ void PrintHeaderClientMethod(grpc_generator::Printer* printer,
"$AsyncPrefix$$Method$Raw(::grpc::ClientContext* context, "
"::grpc::CompletionQueue* cq$AsyncMethodParams$) override;\n");
}
- }
- }
-}
-
+ }
+ }
+}
+
void PrintHeaderClientMethodCallbackInterfacesStart(
grpc_generator::Printer* printer,
std::map<TString, TString>* /*vars*/) {
@@ -783,141 +783,141 @@ void PrintHeaderClientMethodCallbackEnd(
void PrintHeaderClientMethodData(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
+ (*vars)["Method"] = method->name();
printer->Print(*vars,
"const ::grpc::internal::RpcMethod rpcmethod_$Method$_;\n");
-}
-
+}
+
void PrintHeaderServerMethodSync(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
printer->Print(method->GetLeadingComments("//").c_str());
- if (method->NoStreaming()) {
- printer->Print(*vars,
- "virtual ::grpc::Status $Method$("
- "::grpc::ServerContext* context, const $Request$* request, "
- "$Response$* response);\n");
+ if (method->NoStreaming()) {
+ printer->Print(*vars,
+ "virtual ::grpc::Status $Method$("
+ "::grpc::ServerContext* context, const $Request$* request, "
+ "$Response$* response);\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(*vars,
- "virtual ::grpc::Status $Method$("
- "::grpc::ServerContext* context, "
- "::grpc::ServerReader< $Request$>* reader, "
- "$Response$* response);\n");
+ printer->Print(*vars,
+ "virtual ::grpc::Status $Method$("
+ "::grpc::ServerContext* context, "
+ "::grpc::ServerReader< $Request$>* reader, "
+ "$Response$* response);\n");
} else if (ServerOnlyStreaming(method)) {
- printer->Print(*vars,
- "virtual ::grpc::Status $Method$("
- "::grpc::ServerContext* context, const $Request$* request, "
- "::grpc::ServerWriter< $Response$>* writer);\n");
- } else if (method->BidiStreaming()) {
- printer->Print(
- *vars,
- "virtual ::grpc::Status $Method$("
- "::grpc::ServerContext* context, "
- "::grpc::ServerReaderWriter< $Response$, $Request$>* stream);"
- "\n");
- }
+ printer->Print(*vars,
+ "virtual ::grpc::Status $Method$("
+ "::grpc::ServerContext* context, const $Request$* request, "
+ "::grpc::ServerWriter< $Response$>* writer);\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(
+ *vars,
+ "virtual ::grpc::Status $Method$("
+ "::grpc::ServerContext* context, "
+ "::grpc::ServerReaderWriter< $Response$, $Request$>* stream);"
+ "\n");
+ }
printer->Print(method->GetTrailingComments("//").c_str());
-}
-
+}
+
// Helper generator. Disables the sync API for Request and Response, then adds
// in an async API for RealRequest and RealResponse types. This is to be used
// to generate async and raw async APIs.
void PrintHeaderServerAsyncMethodsHelper(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- if (method->NoStreaming()) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ if (method->NoStreaming()) {
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, const $Request$* /*request*/, "
"$Response$* /*response*/) override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- printer->Print(
- *vars,
- "void Request$Method$("
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ printer->Print(
+ *vars,
+ "void Request$Method$("
"::grpc::ServerContext* context, $RealRequest$* request, "
"::grpc::ServerAsyncResponseWriter< $RealResponse$>* response, "
- "::grpc::CompletionQueue* new_call_cq, "
- "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
- printer->Print(*vars,
- " ::grpc::Service::RequestAsyncUnary($Idx$, context, "
- "request, response, new_call_cq, notification_cq, tag);\n");
- printer->Print("}\n");
+ "::grpc::CompletionQueue* new_call_cq, "
+ "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
+ printer->Print(*vars,
+ " ::grpc::Service::RequestAsyncUnary($Idx$, context, "
+ "request, response, new_call_cq, notification_cq, tag);\n");
+ printer->Print("}\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, "
"::grpc::ServerReader< $Request$>* /*reader*/, "
"$Response$* /*response*/) override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- printer->Print(
- *vars,
- "void Request$Method$("
- "::grpc::ServerContext* context, "
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ printer->Print(
+ *vars,
+ "void Request$Method$("
+ "::grpc::ServerContext* context, "
"::grpc::ServerAsyncReader< $RealResponse$, $RealRequest$>* reader, "
- "::grpc::CompletionQueue* new_call_cq, "
- "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
- printer->Print(*vars,
- " ::grpc::Service::RequestAsyncClientStreaming($Idx$, "
- "context, reader, new_call_cq, notification_cq, tag);\n");
- printer->Print("}\n");
+ "::grpc::CompletionQueue* new_call_cq, "
+ "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
+ printer->Print(*vars,
+ " ::grpc::Service::RequestAsyncClientStreaming($Idx$, "
+ "context, reader, new_call_cq, notification_cq, tag);\n");
+ printer->Print("}\n");
} else if (ServerOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, const $Request$* /*request*/, "
"::grpc::ServerWriter< $Response$>* /*writer*/) override "
- "{\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- printer->Print(
- *vars,
- "void Request$Method$("
+ "{\n"
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ printer->Print(
+ *vars,
+ "void Request$Method$("
"::grpc::ServerContext* context, $RealRequest$* request, "
"::grpc::ServerAsyncWriter< $RealResponse$>* writer, "
- "::grpc::CompletionQueue* new_call_cq, "
- "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
- printer->Print(
- *vars,
- " ::grpc::Service::RequestAsyncServerStreaming($Idx$, "
- "context, request, writer, new_call_cq, notification_cq, tag);\n");
- printer->Print("}\n");
- } else if (method->BidiStreaming()) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ "::grpc::CompletionQueue* new_call_cq, "
+ "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
+ printer->Print(
+ *vars,
+ " ::grpc::Service::RequestAsyncServerStreaming($Idx$, "
+ "context, request, writer, new_call_cq, notification_cq, tag);\n");
+ printer->Print("}\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, "
"::grpc::ServerReaderWriter< $Response$, $Request$>* /*stream*/) "
" override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- printer->Print(
- *vars,
- "void Request$Method$("
- "::grpc::ServerContext* context, "
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ printer->Print(
+ *vars,
+ "void Request$Method$("
+ "::grpc::ServerContext* context, "
"::grpc::ServerAsyncReaderWriter< $RealResponse$, $RealRequest$>* "
"stream, "
- "::grpc::CompletionQueue* new_call_cq, "
- "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
- printer->Print(*vars,
- " ::grpc::Service::RequestAsyncBidiStreaming($Idx$, "
- "context, stream, new_call_cq, notification_cq, tag);\n");
- printer->Print("}\n");
- }
+ "::grpc::CompletionQueue* new_call_cq, "
+ "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n");
+ printer->Print(*vars,
+ " ::grpc::Service::RequestAsyncBidiStreaming($Idx$, "
+ "context, stream, new_call_cq, notification_cq, tag);\n");
+ printer->Print("}\n");
+ }
}
void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer,
@@ -948,10 +948,10 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer,
" BaseClassMustBeDerivedFromService(this);\n"
"}\n");
PrintHeaderServerAsyncMethodsHelper(printer, method, vars);
- printer->Outdent();
- printer->Print(*vars, "};\n");
-}
-
+ printer->Outdent();
+ printer->Print(*vars, "};\n");
+}
+
// Helper generator. Disables the sync API for Request and Response, then adds
// in a callback API for RealRequest and RealResponse types. This is to be used
// to generate callback and raw callback APIs.
@@ -1300,26 +1300,26 @@ void PrintHeaderServerMethodRawCallback(
printer->Print(*vars, "};\n");
}
-void PrintHeaderServerMethodStreamedUnary(
+void PrintHeaderServerMethodStreamedUnary(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
- if (method->NoStreaming()) {
- printer->Print(*vars, "template <class BaseClass>\n");
- printer->Print(*vars,
- "class WithStreamedUnaryMethod_$Method$ : "
- "public BaseClass {\n");
- printer->Print(
- " private:\n"
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
+ if (method->NoStreaming()) {
+ printer->Print(*vars, "template <class BaseClass>\n");
+ printer->Print(*vars,
+ "class WithStreamedUnaryMethod_$Method$ : "
+ "public BaseClass {\n");
+ printer->Print(
+ " private:\n"
" void BaseClassMustBeDerivedFromService(const Service* /*service*/) "
- "{}\n");
- printer->Print(" public:\n");
- printer->Indent();
- printer->Print(*vars,
- "WithStreamedUnaryMethod_$Method$() {\n"
- " ::grpc::Service::MarkMethodStreamed($Idx$,\n"
+ "{}\n");
+ printer->Print(" public:\n");
+ printer->Indent();
+ printer->Print(*vars,
+ "WithStreamedUnaryMethod_$Method$() {\n"
+ " ::grpc::Service::MarkMethodStreamed($Idx$,\n"
" new ::grpc::internal::StreamedUnaryHandler<\n"
" $Request$, $Response$>(\n"
" [this](::grpc::ServerContext* context,\n"
@@ -1328,50 +1328,50 @@ void PrintHeaderServerMethodStreamedUnary(
" return this->Streamed$Method$(context,\n"
" streamer);\n"
" }));\n"
- "}\n");
- printer->Print(*vars,
- "~WithStreamedUnaryMethod_$Method$() override {\n"
- " BaseClassMustBeDerivedFromService(this);\n"
- "}\n");
- printer->Print(
- *vars,
- "// disable regular version of this method\n"
- "::grpc::Status $Method$("
+ "}\n");
+ printer->Print(*vars,
+ "~WithStreamedUnaryMethod_$Method$() override {\n"
+ " BaseClassMustBeDerivedFromService(this);\n"
+ "}\n");
+ printer->Print(
+ *vars,
+ "// disable regular version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, const $Request$* /*request*/, "
"$Response$* /*response*/) override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- printer->Print(*vars,
- "// replace default version of method with streamed unary\n"
- "virtual ::grpc::Status Streamed$Method$("
- "::grpc::ServerContext* context, "
- "::grpc::ServerUnaryStreamer< "
- "$Request$,$Response$>* server_unary_streamer)"
- " = 0;\n");
- printer->Outdent();
- printer->Print(*vars, "};\n");
- }
-}
-
-void PrintHeaderServerMethodSplitStreaming(
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ printer->Print(*vars,
+ "// replace default version of method with streamed unary\n"
+ "virtual ::grpc::Status Streamed$Method$("
+ "::grpc::ServerContext* context, "
+ "::grpc::ServerUnaryStreamer< "
+ "$Request$,$Response$>* server_unary_streamer)"
+ " = 0;\n");
+ printer->Outdent();
+ printer->Print(*vars, "};\n");
+ }
+}
+
+void PrintHeaderServerMethodSplitStreaming(
grpc_generator::Printer* printer, const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
if (ServerOnlyStreaming(method)) {
- printer->Print(*vars, "template <class BaseClass>\n");
- printer->Print(*vars,
- "class WithSplitStreamingMethod_$Method$ : "
- "public BaseClass {\n");
- printer->Print(
- " private:\n"
+ printer->Print(*vars, "template <class BaseClass>\n");
+ printer->Print(*vars,
+ "class WithSplitStreamingMethod_$Method$ : "
+ "public BaseClass {\n");
+ printer->Print(
+ " private:\n"
" void BaseClassMustBeDerivedFromService(const Service* /*service*/) "
- "{}\n");
- printer->Print(" public:\n");
- printer->Indent();
- printer->Print(*vars,
+ "{}\n");
+ printer->Print(" public:\n");
+ printer->Indent();
+ printer->Print(*vars,
"WithSplitStreamingMethod_$Method$() {\n"
" ::grpc::Service::MarkMethodStreamed($Idx$,\n"
" new ::grpc::internal::SplitServerStreamingHandler<\n"
@@ -1384,102 +1384,102 @@ void PrintHeaderServerMethodSplitStreaming(
" }));\n"
"}\n");
printer->Print(*vars,
- "~WithSplitStreamingMethod_$Method$() override {\n"
- " BaseClassMustBeDerivedFromService(this);\n"
- "}\n");
- printer->Print(
- *vars,
- "// disable regular version of this method\n"
- "::grpc::Status $Method$("
+ "~WithSplitStreamingMethod_$Method$() override {\n"
+ " BaseClassMustBeDerivedFromService(this);\n"
+ "}\n");
+ printer->Print(
+ *vars,
+ "// disable regular version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, const $Request$* /*request*/, "
"::grpc::ServerWriter< $Response$>* /*writer*/) override "
- "{\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- printer->Print(*vars,
- "// replace default version of method with split streamed\n"
- "virtual ::grpc::Status Streamed$Method$("
- "::grpc::ServerContext* context, "
- "::grpc::ServerSplitStreamer< "
- "$Request$,$Response$>* server_split_streamer)"
- " = 0;\n");
- printer->Outdent();
- printer->Print(*vars, "};\n");
- }
-}
-
+ "{\n"
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ printer->Print(*vars,
+ "// replace default version of method with split streamed\n"
+ "virtual ::grpc::Status Streamed$Method$("
+ "::grpc::ServerContext* context, "
+ "::grpc::ServerSplitStreamer< "
+ "$Request$,$Response$>* server_split_streamer)"
+ " = 0;\n");
+ printer->Outdent();
+ printer->Print(*vars, "};\n");
+ }
+}
+
void PrintHeaderServerMethodGeneric(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
- printer->Print(*vars, "template <class BaseClass>\n");
- printer->Print(*vars,
- "class WithGenericMethod_$Method$ : public BaseClass {\n");
- printer->Print(
- " private:\n"
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
+ printer->Print(*vars, "template <class BaseClass>\n");
+ printer->Print(*vars,
+ "class WithGenericMethod_$Method$ : public BaseClass {\n");
+ printer->Print(
+ " private:\n"
" void BaseClassMustBeDerivedFromService(const Service* /*service*/) "
"{}\n");
- printer->Print(" public:\n");
- printer->Indent();
- printer->Print(*vars,
- "WithGenericMethod_$Method$() {\n"
- " ::grpc::Service::MarkMethodGeneric($Idx$);\n"
- "}\n");
- printer->Print(*vars,
- "~WithGenericMethod_$Method$() override {\n"
- " BaseClassMustBeDerivedFromService(this);\n"
- "}\n");
- if (method->NoStreaming()) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ printer->Print(" public:\n");
+ printer->Indent();
+ printer->Print(*vars,
+ "WithGenericMethod_$Method$() {\n"
+ " ::grpc::Service::MarkMethodGeneric($Idx$);\n"
+ "}\n");
+ printer->Print(*vars,
+ "~WithGenericMethod_$Method$() override {\n"
+ " BaseClassMustBeDerivedFromService(this);\n"
+ "}\n");
+ if (method->NoStreaming()) {
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, const $Request$* /*request*/, "
"$Response$* /*response*/) override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, "
"::grpc::ServerReader< $Request$>* /*reader*/, "
"$Response$* /*response*/) override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
} else if (ServerOnlyStreaming(method)) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, const $Request$* /*request*/, "
"::grpc::ServerWriter< $Response$>* /*writer*/) override "
- "{\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- } else if (method->BidiStreaming()) {
- printer->Print(
- *vars,
- "// disable synchronous version of this method\n"
- "::grpc::Status $Method$("
+ "{\n"
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(
+ *vars,
+ "// disable synchronous version of this method\n"
+ "::grpc::Status $Method$("
"::grpc::ServerContext* /*context*/, "
"::grpc::ServerReaderWriter< $Response$, $Request$>* /*stream*/) "
" override {\n"
- " abort();\n"
- " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
- "}\n");
- }
- printer->Outdent();
- printer->Print(*vars, "};\n");
-}
-
+ " abort();\n"
+ " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
+ "}\n");
+ }
+ printer->Outdent();
+ printer->Print(*vars, "};\n");
+}
+
void PrintHeaderServerMethodRaw(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
@@ -1514,32 +1514,32 @@ void PrintHeaderServerMethodRaw(grpc_generator::Printer* printer,
void PrintHeaderService(grpc_generator::Printer* printer,
const grpc_generator::Service* service,
std::map<TString, TString>* vars) {
- (*vars)["Service"] = service->name();
-
+ (*vars)["Service"] = service->name();
+
printer->Print(service->GetLeadingComments("//").c_str());
- printer->Print(*vars,
- "class $Service$ final {\n"
- " public:\n");
- printer->Indent();
-
+ printer->Print(*vars,
+ "class $Service$ final {\n"
+ " public:\n");
+ printer->Indent();
+
// Service metadata
printer->Print(*vars,
"static constexpr char const* service_full_name() {\n"
" return \"$Package$$Service$\";\n"
"}\n");
- // Client side
- printer->Print(
- "class StubInterface {\n"
- " public:\n");
- printer->Indent();
- printer->Print("virtual ~StubInterface() {}\n");
- for (int i = 0; i < service->method_count(); ++i) {
+ // Client side
+ printer->Print(
+ "class StubInterface {\n"
+ " public:\n");
+ printer->Indent();
+ printer->Print("virtual ~StubInterface() {}\n");
+ for (int i = 0; i < service->method_count(); ++i) {
printer->Print(service->method(i)->GetLeadingComments("//").c_str());
- PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars,
- true);
+ PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars,
+ true);
printer->Print(service->method(i)->GetTrailingComments("//").c_str());
- }
+ }
PrintHeaderClientMethodCallbackInterfacesStart(printer, vars);
for (int i = 0; i < service->method_count(); ++i) {
printer->Print(service->method(i)->GetLeadingComments("//").c_str());
@@ -1548,81 +1548,81 @@ void PrintHeaderService(grpc_generator::Printer* printer,
printer->Print(service->method(i)->GetTrailingComments("//").c_str());
}
PrintHeaderClientMethodCallbackInterfacesEnd(printer, vars);
- printer->Outdent();
- printer->Print("private:\n");
- printer->Indent();
- for (int i = 0; i < service->method_count(); ++i) {
- PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars,
- false);
- }
- printer->Outdent();
- printer->Print("};\n");
- printer->Print(
- "class Stub final : public StubInterface"
- " {\n public:\n");
- printer->Indent();
- printer->Print(
+ printer->Outdent();
+ printer->Print("private:\n");
+ printer->Indent();
+ for (int i = 0; i < service->method_count(); ++i) {
+ PrintHeaderClientMethodInterfaces(printer, service->method(i).get(), vars,
+ false);
+ }
+ printer->Outdent();
+ printer->Print("};\n");
+ printer->Print(
+ "class Stub final : public StubInterface"
+ " {\n public:\n");
+ printer->Indent();
+ printer->Print(
"Stub(const std::shared_ptr< ::grpc::ChannelInterface>& "
"channel);\n");
- for (int i = 0; i < service->method_count(); ++i) {
- PrintHeaderClientMethod(printer, service->method(i).get(), vars, true);
- }
+ for (int i = 0; i < service->method_count(); ++i) {
+ PrintHeaderClientMethod(printer, service->method(i).get(), vars, true);
+ }
PrintHeaderClientMethodCallbackStart(printer, vars);
for (int i = 0; i < service->method_count(); ++i) {
PrintHeaderClientMethodCallback(printer, service->method(i).get(), vars);
}
PrintHeaderClientMethodCallbackEnd(printer, vars);
- printer->Outdent();
- printer->Print("\n private:\n");
- printer->Indent();
- printer->Print("std::shared_ptr< ::grpc::ChannelInterface> channel_;\n");
+ printer->Outdent();
+ printer->Print("\n private:\n");
+ printer->Indent();
+ printer->Print("std::shared_ptr< ::grpc::ChannelInterface> channel_;\n");
printer->Print("class experimental_async async_stub_{this};\n");
- for (int i = 0; i < service->method_count(); ++i) {
- PrintHeaderClientMethod(printer, service->method(i).get(), vars, false);
- }
- for (int i = 0; i < service->method_count(); ++i) {
- PrintHeaderClientMethodData(printer, service->method(i).get(), vars);
- }
- printer->Outdent();
- printer->Print("};\n");
- printer->Print(
- "static std::unique_ptr<Stub> NewStub(const std::shared_ptr< "
- "::grpc::ChannelInterface>& channel, "
- "const ::grpc::StubOptions& options = ::grpc::StubOptions());\n");
-
- printer->Print("\n");
-
- // Server side - base
- printer->Print(
- "class Service : public ::grpc::Service {\n"
- " public:\n");
- printer->Indent();
- printer->Print("Service();\n");
- printer->Print("virtual ~Service();\n");
- for (int i = 0; i < service->method_count(); ++i) {
- PrintHeaderServerMethodSync(printer, service->method(i).get(), vars);
- }
- printer->Outdent();
- printer->Print("};\n");
-
- // Server side - Asynchronous
- for (int i = 0; i < service->method_count(); ++i) {
- (*vars)["Idx"] = as_string(i);
- PrintHeaderServerMethodAsync(printer, service->method(i).get(), vars);
- }
-
- printer->Print("typedef ");
-
- for (int i = 0; i < service->method_count(); ++i) {
+ for (int i = 0; i < service->method_count(); ++i) {
+ PrintHeaderClientMethod(printer, service->method(i).get(), vars, false);
+ }
+ for (int i = 0; i < service->method_count(); ++i) {
+ PrintHeaderClientMethodData(printer, service->method(i).get(), vars);
+ }
+ printer->Outdent();
+ printer->Print("};\n");
+ printer->Print(
+ "static std::unique_ptr<Stub> NewStub(const std::shared_ptr< "
+ "::grpc::ChannelInterface>& channel, "
+ "const ::grpc::StubOptions& options = ::grpc::StubOptions());\n");
+
+ printer->Print("\n");
+
+ // Server side - base
+ printer->Print(
+ "class Service : public ::grpc::Service {\n"
+ " public:\n");
+ printer->Indent();
+ printer->Print("Service();\n");
+ printer->Print("virtual ~Service();\n");
+ for (int i = 0; i < service->method_count(); ++i) {
+ PrintHeaderServerMethodSync(printer, service->method(i).get(), vars);
+ }
+ printer->Outdent();
+ printer->Print("};\n");
+
+ // Server side - Asynchronous
+ for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Idx"] = as_string(i);
+ PrintHeaderServerMethodAsync(printer, service->method(i).get(), vars);
+ }
+
+ printer->Print("typedef ");
+
+ for (int i = 0; i < service->method_count(); ++i) {
(*vars)["method_name"] = service->method(i)->name();
- printer->Print(*vars, "WithAsyncMethod_$method_name$<");
- }
- printer->Print("Service");
- for (int i = 0; i < service->method_count(); ++i) {
- printer->Print(" >");
- }
- printer->Print(" AsyncService;\n");
-
+ printer->Print(*vars, "WithAsyncMethod_$method_name$<");
+ }
+ printer->Print("Service");
+ for (int i = 0; i < service->method_count(); ++i) {
+ printer->Print(" >");
+ }
+ printer->Print(" AsyncService;\n");
+
// Server side - Callback
for (int i = 0; i < service->method_count(); ++i) {
(*vars)["Idx"] = as_string(i);
@@ -1655,12 +1655,12 @@ void PrintHeaderService(grpc_generator::Printer* printer,
}
printer->Print(" ExperimentalCallbackService;\n");
- // Server side - Generic
- for (int i = 0; i < service->method_count(); ++i) {
- (*vars)["Idx"] = as_string(i);
- PrintHeaderServerMethodGeneric(printer, service->method(i).get(), vars);
- }
-
+ // Server side - Generic
+ for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Idx"] = as_string(i);
+ PrintHeaderServerMethodGeneric(printer, service->method(i).get(), vars);
+ }
+
// Server side - Raw
for (int i = 0; i < service->method_count(); ++i) {
(*vars)["Idx"] = as_string(i);
@@ -1673,172 +1673,172 @@ void PrintHeaderService(grpc_generator::Printer* printer,
PrintHeaderServerMethodRawCallback(printer, service->method(i).get(), vars);
}
- // Server side - Streamed Unary
- for (int i = 0; i < service->method_count(); ++i) {
- (*vars)["Idx"] = as_string(i);
- PrintHeaderServerMethodStreamedUnary(printer, service->method(i).get(),
- vars);
- }
-
- printer->Print("typedef ");
- for (int i = 0; i < service->method_count(); ++i) {
+ // Server side - Streamed Unary
+ for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Idx"] = as_string(i);
+ PrintHeaderServerMethodStreamedUnary(printer, service->method(i).get(),
+ vars);
+ }
+
+ printer->Print("typedef ");
+ for (int i = 0; i < service->method_count(); ++i) {
(*vars)["method_name"] = service->method(i)->name();
- if (service->method(i)->NoStreaming()) {
- printer->Print(*vars, "WithStreamedUnaryMethod_$method_name$<");
- }
- }
- printer->Print("Service");
- for (int i = 0; i < service->method_count(); ++i) {
- if (service->method(i)->NoStreaming()) {
- printer->Print(" >");
- }
- }
- printer->Print(" StreamedUnaryService;\n");
-
- // Server side - controlled server-side streaming
- for (int i = 0; i < service->method_count(); ++i) {
- (*vars)["Idx"] = as_string(i);
- PrintHeaderServerMethodSplitStreaming(printer, service->method(i).get(),
- vars);
- }
-
- printer->Print("typedef ");
- for (int i = 0; i < service->method_count(); ++i) {
+ if (service->method(i)->NoStreaming()) {
+ printer->Print(*vars, "WithStreamedUnaryMethod_$method_name$<");
+ }
+ }
+ printer->Print("Service");
+ for (int i = 0; i < service->method_count(); ++i) {
+ if (service->method(i)->NoStreaming()) {
+ printer->Print(" >");
+ }
+ }
+ printer->Print(" StreamedUnaryService;\n");
+
+ // Server side - controlled server-side streaming
+ for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Idx"] = as_string(i);
+ PrintHeaderServerMethodSplitStreaming(printer, service->method(i).get(),
+ vars);
+ }
+
+ printer->Print("typedef ");
+ for (int i = 0; i < service->method_count(); ++i) {
(*vars)["method_name"] = service->method(i)->name();
auto method = service->method(i);
if (ServerOnlyStreaming(method.get())) {
- printer->Print(*vars, "WithSplitStreamingMethod_$method_name$<");
- }
- }
- printer->Print("Service");
- for (int i = 0; i < service->method_count(); ++i) {
+ printer->Print(*vars, "WithSplitStreamingMethod_$method_name$<");
+ }
+ }
+ printer->Print("Service");
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
if (ServerOnlyStreaming(method.get())) {
- printer->Print(" >");
- }
- }
- printer->Print(" SplitStreamedService;\n");
-
- // Server side - typedef for controlled both unary and server-side streaming
- printer->Print("typedef ");
- for (int i = 0; i < service->method_count(); ++i) {
+ printer->Print(" >");
+ }
+ }
+ printer->Print(" SplitStreamedService;\n");
+
+ // Server side - typedef for controlled both unary and server-side streaming
+ printer->Print("typedef ");
+ for (int i = 0; i < service->method_count(); ++i) {
(*vars)["method_name"] = service->method(i)->name();
auto method = service->method(i);
if (ServerOnlyStreaming(method.get())) {
- printer->Print(*vars, "WithSplitStreamingMethod_$method_name$<");
- }
- if (service->method(i)->NoStreaming()) {
- printer->Print(*vars, "WithStreamedUnaryMethod_$method_name$<");
- }
- }
- printer->Print("Service");
- for (int i = 0; i < service->method_count(); ++i) {
+ printer->Print(*vars, "WithSplitStreamingMethod_$method_name$<");
+ }
+ if (service->method(i)->NoStreaming()) {
+ printer->Print(*vars, "WithStreamedUnaryMethod_$method_name$<");
+ }
+ }
+ printer->Print("Service");
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
- if (service->method(i)->NoStreaming() ||
+ if (service->method(i)->NoStreaming() ||
ServerOnlyStreaming(method.get())) {
- printer->Print(" >");
- }
- }
- printer->Print(" StreamedService;\n");
-
- printer->Outdent();
- printer->Print("};\n");
+ printer->Print(" >");
+ }
+ }
+ printer->Print(" StreamedService;\n");
+
+ printer->Outdent();
+ printer->Print("};\n");
printer->Print(service->GetTrailingComments("//").c_str());
-}
-
+}
+
TString GetHeaderServices(grpc_generator::File* file,
const Parameters& params) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
- // Package string is empty or ends with a dot. It is used to fully qualify
- // method names.
- vars["Package"] = file->package();
- if (!file->package().empty()) {
- vars["Package"].append(".");
- }
-
- if (!params.services_namespace.empty()) {
- vars["services_namespace"] = params.services_namespace;
- printer->Print(vars, "\nnamespace $services_namespace$ {\n\n");
- }
-
- for (int i = 0; i < file->service_count(); ++i) {
- PrintHeaderService(printer.get(), file->service(i).get(), &vars);
- printer->Print("\n");
- }
-
- if (!params.services_namespace.empty()) {
- printer->Print(vars, "} // namespace $services_namespace$\n\n");
- }
- }
- return output;
-}
-
+ // Package string is empty or ends with a dot. It is used to fully qualify
+ // method names.
+ vars["Package"] = file->package();
+ if (!file->package().empty()) {
+ vars["Package"].append(".");
+ }
+
+ if (!params.services_namespace.empty()) {
+ vars["services_namespace"] = params.services_namespace;
+ printer->Print(vars, "\nnamespace $services_namespace$ {\n\n");
+ }
+
+ for (int i = 0; i < file->service_count(); ++i) {
+ PrintHeaderService(printer.get(), file->service(i).get(), &vars);
+ printer->Print("\n");
+ }
+
+ if (!params.services_namespace.empty()) {
+ printer->Print(vars, "} // namespace $services_namespace$\n\n");
+ }
+ }
+ return output;
+}
+
TString GetHeaderEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
-
- vars["filename"] = file->filename();
- vars["filename_identifier"] = FilenameIdentifier(file->filename());
-
- if (!file->package().empty()) {
+
+ vars["filename"] = file->filename();
+ vars["filename_identifier"] = FilenameIdentifier(file->filename());
+
+ if (!file->package().empty()) {
std::vector<TString> parts = file->package_parts();
-
- for (auto part = parts.rbegin(); part != parts.rend(); part++) {
- vars["part"] = *part;
- printer->Print(vars, "} // namespace $part$\n");
- }
- printer->Print(vars, "\n");
- }
-
- printer->Print(vars, "\n");
- printer->Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n");
-
+
+ for (auto part = parts.rbegin(); part != parts.rend(); part++) {
+ vars["part"] = *part;
+ printer->Print(vars, "} // namespace $part$\n");
+ }
+ printer->Print(vars, "\n");
+ }
+
+ printer->Print(vars, "\n");
+ printer->Print(vars, "#endif // GRPC_$filename_identifier$__INCLUDED\n");
+
printer->Print(file->GetTrailingComments("//").c_str());
- }
- return output;
-}
-
+ }
+ return output;
+}
+
TString GetSourcePrologue(grpc_generator::File* file,
const Parameters& params) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
-
- vars["filename"] = file->filename();
- vars["filename_base"] = file->filename_without_ext();
+
+ vars["filename"] = file->filename();
+ vars["filename_base"] = file->filename_without_ext();
vars["message_header_ext"] = params.message_header_extension.empty()
? kCppGeneratorMessageHeaderExt
: params.message_header_extension;
vars["service_header_ext"] = kCppGeneratorServiceHeaderExt;
-
+
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
- printer->Print(vars,
- "// If you make any local change, they will be lost.\n");
- printer->Print(vars, "// source: $filename$\n\n");
-
- printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
- printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
- printer->Print(vars, "\n");
- }
- return output;
-}
-
+ printer->Print(vars,
+ "// If you make any local change, they will be lost.\n");
+ printer->Print(vars, "// source: $filename$\n\n");
+
+ printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
+ printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
+ printer->Print(vars, "\n");
+ }
+ return output;
+}
+
TString GetSourceIncludes(grpc_generator::File* file,
const Parameters& params) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
static const char* headers_strs[] = {
"functional",
@@ -1858,27 +1858,27 @@ TString GetSourceIncludes(grpc_generator::File* file,
std::vector<TString> headers(headers_strs, array_end(headers_strs));
PrintIncludes(printer.get(), headers, params.use_system_headers,
params.grpc_search_path);
-
- if (!file->package().empty()) {
+
+ if (!file->package().empty()) {
std::vector<TString> parts = file->package_parts();
-
- for (auto part = parts.begin(); part != parts.end(); part++) {
- vars["part"] = *part;
- printer->Print(vars, "namespace $part$ {\n");
- }
- }
-
- printer->Print(vars, "\n");
- }
- return output;
-}
-
+
+ for (auto part = parts.begin(); part != parts.end(); part++) {
+ vars["part"] = *part;
+ printer->Print(vars, "namespace $part$ {\n");
+ }
+ }
+
+ printer->Print(vars, "\n");
+ }
+ return output;
+}
+
void PrintSourceClientMethod(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
struct {
TString prefix;
TString start; // bool literal expressed as string
@@ -1886,12 +1886,12 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
TString create_args; // extra arguments to creator
} async_prefixes[] = {{"Async", "true", ", void* tag", ", tag"},
{"PrepareAsync", "false", "", ", nullptr"}};
- if (method->NoStreaming()) {
- printer->Print(*vars,
- "::grpc::Status $ns$$Service$::Stub::$Method$("
- "::grpc::ClientContext* context, "
- "const $Request$& request, $Response$* response) {\n");
- printer->Print(*vars,
+ if (method->NoStreaming()) {
+ printer->Print(*vars,
+ "::grpc::Status $ns$$Service$::Stub::$Method$("
+ "::grpc::ClientContext* context, "
+ "const $Request$& request, $Response$* response) {\n");
+ printer->Print(*vars,
" return ::grpc::internal::BlockingUnaryCall"
"(channel_.get(), rpcmethod_$Method$_, "
"context, request, response);\n}\n\n");
@@ -1942,10 +1942,10 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
" return result;\n"
"}\n\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(*vars,
- "::grpc::ClientWriter< $Request$>* "
- "$ns$$Service$::Stub::$Method$Raw("
- "::grpc::ClientContext* context, $Response$* response) {\n");
+ printer->Print(*vars,
+ "::grpc::ClientWriter< $Request$>* "
+ "$ns$$Service$::Stub::$Method$Raw("
+ "::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars,
" return ::grpc::internal::ClientWriterFactory< "
"$Request$>::Create("
@@ -1989,9 +1989,9 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
- "::grpc::ClientReader< $Response$>* "
- "$ns$$Service$::Stub::$Method$Raw("
- "::grpc::ClientContext* context, const $Request$& request) {\n");
+ "::grpc::ClientReader< $Response$>* "
+ "$ns$$Service$::Stub::$Method$Raw("
+ "::grpc::ClientContext* context, const $Request$& request) {\n");
printer->Print(*vars,
" return ::grpc::internal::ClientReaderFactory< "
"$Response$>::Create("
@@ -2033,18 +2033,18 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
"context, request, $AsyncStart$$AsyncCreateArgs$);\n"
"}\n\n");
}
- } else if (method->BidiStreaming()) {
- printer->Print(
- *vars,
- "::grpc::ClientReaderWriter< $Request$, $Response$>* "
- "$ns$$Service$::Stub::$Method$Raw(::grpc::ClientContext* context) {\n");
- printer->Print(*vars,
+ } else if (method->BidiStreaming()) {
+ printer->Print(
+ *vars,
+ "::grpc::ClientReaderWriter< $Request$, $Response$>* "
+ "$ns$$Service$::Stub::$Method$Raw(::grpc::ClientContext* context) {\n");
+ printer->Print(*vars,
" return ::grpc::internal::ClientReaderWriterFactory< "
"$Request$, $Response$>::Create("
- "channel_.get(), "
- "rpcmethod_$Method$_, "
- "context);\n"
- "}\n\n");
+ "channel_.get(), "
+ "rpcmethod_$Method$_, "
+ "context);\n"
+ "}\n\n");
printer->Print(
*vars,
@@ -2079,145 +2079,145 @@ void PrintSourceClientMethod(grpc_generator::Printer* printer,
"context, $AsyncStart$$AsyncCreateArgs$);\n"
"}\n\n");
}
- }
-}
-
+ }
+}
+
void PrintSourceServerMethod(grpc_generator::Printer* printer,
const grpc_generator::Method* method,
std::map<TString, TString>* vars) {
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
- if (method->NoStreaming()) {
- printer->Print(*vars,
- "::grpc::Status $ns$$Service$::Service::$Method$("
- "::grpc::ServerContext* context, "
- "const $Request$* request, $Response$* response) {\n");
- printer->Print(" (void) context;\n");
- printer->Print(" (void) request;\n");
- printer->Print(" (void) response;\n");
- printer->Print(
- " return ::grpc::Status("
- "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
- printer->Print("}\n\n");
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
+ if (method->NoStreaming()) {
+ printer->Print(*vars,
+ "::grpc::Status $ns$$Service$::Service::$Method$("
+ "::grpc::ServerContext* context, "
+ "const $Request$* request, $Response$* response) {\n");
+ printer->Print(" (void) context;\n");
+ printer->Print(" (void) request;\n");
+ printer->Print(" (void) response;\n");
+ printer->Print(
+ " return ::grpc::Status("
+ "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
+ printer->Print("}\n\n");
} else if (ClientOnlyStreaming(method)) {
- printer->Print(*vars,
- "::grpc::Status $ns$$Service$::Service::$Method$("
- "::grpc::ServerContext* context, "
- "::grpc::ServerReader< $Request$>* reader, "
- "$Response$* response) {\n");
- printer->Print(" (void) context;\n");
- printer->Print(" (void) reader;\n");
- printer->Print(" (void) response;\n");
- printer->Print(
- " return ::grpc::Status("
- "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
- printer->Print("}\n\n");
+ printer->Print(*vars,
+ "::grpc::Status $ns$$Service$::Service::$Method$("
+ "::grpc::ServerContext* context, "
+ "::grpc::ServerReader< $Request$>* reader, "
+ "$Response$* response) {\n");
+ printer->Print(" (void) context;\n");
+ printer->Print(" (void) reader;\n");
+ printer->Print(" (void) response;\n");
+ printer->Print(
+ " return ::grpc::Status("
+ "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
+ printer->Print("}\n\n");
} else if (ServerOnlyStreaming(method)) {
- printer->Print(*vars,
- "::grpc::Status $ns$$Service$::Service::$Method$("
- "::grpc::ServerContext* context, "
- "const $Request$* request, "
- "::grpc::ServerWriter< $Response$>* writer) {\n");
- printer->Print(" (void) context;\n");
- printer->Print(" (void) request;\n");
- printer->Print(" (void) writer;\n");
- printer->Print(
- " return ::grpc::Status("
- "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
- printer->Print("}\n\n");
- } else if (method->BidiStreaming()) {
- printer->Print(*vars,
- "::grpc::Status $ns$$Service$::Service::$Method$("
- "::grpc::ServerContext* context, "
- "::grpc::ServerReaderWriter< $Response$, $Request$>* "
- "stream) {\n");
- printer->Print(" (void) context;\n");
- printer->Print(" (void) stream;\n");
- printer->Print(
- " return ::grpc::Status("
- "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
- printer->Print("}\n\n");
- }
-}
-
+ printer->Print(*vars,
+ "::grpc::Status $ns$$Service$::Service::$Method$("
+ "::grpc::ServerContext* context, "
+ "const $Request$* request, "
+ "::grpc::ServerWriter< $Response$>* writer) {\n");
+ printer->Print(" (void) context;\n");
+ printer->Print(" (void) request;\n");
+ printer->Print(" (void) writer;\n");
+ printer->Print(
+ " return ::grpc::Status("
+ "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
+ printer->Print("}\n\n");
+ } else if (method->BidiStreaming()) {
+ printer->Print(*vars,
+ "::grpc::Status $ns$$Service$::Service::$Method$("
+ "::grpc::ServerContext* context, "
+ "::grpc::ServerReaderWriter< $Response$, $Request$>* "
+ "stream) {\n");
+ printer->Print(" (void) context;\n");
+ printer->Print(" (void) stream;\n");
+ printer->Print(
+ " return ::grpc::Status("
+ "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n");
+ printer->Print("}\n\n");
+ }
+}
+
void PrintSourceService(grpc_generator::Printer* printer,
const grpc_generator::Service* service,
std::map<TString, TString>* vars) {
- (*vars)["Service"] = service->name();
-
- if (service->method_count() > 0) {
- printer->Print(*vars,
- "static const char* $prefix$$Service$_method_names[] = {\n");
- for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Service"] = service->name();
+
+ if (service->method_count() > 0) {
+ printer->Print(*vars,
+ "static const char* $prefix$$Service$_method_names[] = {\n");
+ for (int i = 0; i < service->method_count(); ++i) {
(*vars)["Method"] = service->method(i)->name();
- printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n");
- }
- printer->Print(*vars, "};\n\n");
- }
-
- printer->Print(*vars,
- "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub("
- "const std::shared_ptr< ::grpc::ChannelInterface>& channel, "
+ printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n");
+ }
+ printer->Print(*vars, "};\n\n");
+ }
+
+ printer->Print(*vars,
+ "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub("
+ "const std::shared_ptr< ::grpc::ChannelInterface>& channel, "
"const ::grpc::StubOptions& options) {\n"
" (void)options;\n"
- " std::unique_ptr< $ns$$Service$::Stub> stub(new "
- "$ns$$Service$::Stub(channel));\n"
- " return stub;\n"
- "}\n\n");
- printer->Print(*vars,
- "$ns$$Service$::Stub::Stub(const std::shared_ptr< "
- "::grpc::ChannelInterface>& channel)\n");
- printer->Indent();
- printer->Print(": channel_(channel)");
- for (int i = 0; i < service->method_count(); ++i) {
- auto method = service->method(i);
- (*vars)["Method"] = method->name();
- (*vars)["Idx"] = as_string(i);
- if (method->NoStreaming()) {
- (*vars)["StreamingType"] = "NORMAL_RPC";
- // NOTE: There is no reason to consider streamed-unary as a separate
- // category here since this part is setting up the client-side stub
- // and this appears as a NORMAL_RPC from the client-side.
+ " std::unique_ptr< $ns$$Service$::Stub> stub(new "
+ "$ns$$Service$::Stub(channel));\n"
+ " return stub;\n"
+ "}\n\n");
+ printer->Print(*vars,
+ "$ns$$Service$::Stub::Stub(const std::shared_ptr< "
+ "::grpc::ChannelInterface>& channel)\n");
+ printer->Indent();
+ printer->Print(": channel_(channel)");
+ for (int i = 0; i < service->method_count(); ++i) {
+ auto method = service->method(i);
+ (*vars)["Method"] = method->name();
+ (*vars)["Idx"] = as_string(i);
+ if (method->NoStreaming()) {
+ (*vars)["StreamingType"] = "NORMAL_RPC";
+ // NOTE: There is no reason to consider streamed-unary as a separate
+ // category here since this part is setting up the client-side stub
+ // and this appears as a NORMAL_RPC from the client-side.
} else if (ClientOnlyStreaming(method.get())) {
- (*vars)["StreamingType"] = "CLIENT_STREAMING";
+ (*vars)["StreamingType"] = "CLIENT_STREAMING";
} else if (ServerOnlyStreaming(method.get())) {
- (*vars)["StreamingType"] = "SERVER_STREAMING";
- } else {
- (*vars)["StreamingType"] = "BIDI_STREAMING";
- }
- printer->Print(*vars,
- ", rpcmethod_$Method$_("
- "$prefix$$Service$_method_names[$Idx$], "
+ (*vars)["StreamingType"] = "SERVER_STREAMING";
+ } else {
+ (*vars)["StreamingType"] = "BIDI_STREAMING";
+ }
+ printer->Print(*vars,
+ ", rpcmethod_$Method$_("
+ "$prefix$$Service$_method_names[$Idx$], "
"::grpc::internal::RpcMethod::$StreamingType$, "
- "channel"
- ")\n");
- }
- printer->Print("{}\n\n");
- printer->Outdent();
-
- for (int i = 0; i < service->method_count(); ++i) {
- (*vars)["Idx"] = as_string(i);
- PrintSourceClientMethod(printer, service->method(i).get(), vars);
- }
-
- printer->Print(*vars, "$ns$$Service$::Service::Service() {\n");
- printer->Indent();
- for (int i = 0; i < service->method_count(); ++i) {
- auto method = service->method(i);
- (*vars)["Idx"] = as_string(i);
- (*vars)["Method"] = method->name();
- (*vars)["Request"] = method->input_type_name();
- (*vars)["Response"] = method->output_type_name();
- if (method->NoStreaming()) {
- printer->Print(
- *vars,
+ "channel"
+ ")\n");
+ }
+ printer->Print("{}\n\n");
+ printer->Outdent();
+
+ for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Idx"] = as_string(i);
+ PrintSourceClientMethod(printer, service->method(i).get(), vars);
+ }
+
+ printer->Print(*vars, "$ns$$Service$::Service::Service() {\n");
+ printer->Indent();
+ for (int i = 0; i < service->method_count(); ++i) {
+ auto method = service->method(i);
+ (*vars)["Idx"] = as_string(i);
+ (*vars)["Method"] = method->name();
+ (*vars)["Request"] = method->input_type_name();
+ (*vars)["Response"] = method->output_type_name();
+ if (method->NoStreaming()) {
+ printer->Print(
+ *vars,
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
- " $prefix$$Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::internal::RpcMethod::NORMAL_RPC,\n"
" new ::grpc::internal::RpcMethodHandler< $ns$$Service$::Service, "
- "$Request$, "
- "$Response$>(\n"
+ "$Request$, "
+ "$Response$>(\n"
" []($ns$$Service$::Service* service,\n"
" ::grpc::ServerContext* ctx,\n"
" const $Request$* req,\n"
@@ -2225,13 +2225,13 @@ void PrintSourceService(grpc_generator::Printer* printer,
" return service->$Method$(ctx, req, resp);\n"
" }, this)));\n");
} else if (ClientOnlyStreaming(method.get())) {
- printer->Print(
- *vars,
+ printer->Print(
+ *vars,
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
- " $prefix$$Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::internal::RpcMethod::CLIENT_STREAMING,\n"
" new ::grpc::internal::ClientStreamingHandler< "
- "$ns$$Service$::Service, $Request$, $Response$>(\n"
+ "$ns$$Service$::Service, $Request$, $Response$>(\n"
" []($ns$$Service$::Service* service,\n"
" ::grpc::ServerContext* ctx,\n"
" ::grpc::ServerReader<$Request$>* reader,\n"
@@ -2239,20 +2239,20 @@ void PrintSourceService(grpc_generator::Printer* printer,
" return service->$Method$(ctx, reader, resp);\n"
" }, this)));\n");
} else if (ServerOnlyStreaming(method.get())) {
- printer->Print(
- *vars,
+ printer->Print(
+ *vars,
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
- " $prefix$$Service$_method_names[$Idx$],\n"
+ " $prefix$$Service$_method_names[$Idx$],\n"
" ::grpc::internal::RpcMethod::SERVER_STREAMING,\n"
" new ::grpc::internal::ServerStreamingHandler< "
- "$ns$$Service$::Service, $Request$, $Response$>(\n"
+ "$ns$$Service$::Service, $Request$, $Response$>(\n"
" []($ns$$Service$::Service* service,\n"
" ::grpc::ServerContext* ctx,\n"
" const $Request$* req,\n"
" ::grpc::ServerWriter<$Response$>* writer) {\n"
" return service->$Method$(ctx, req, writer);\n"
" }, this)));\n");
- } else if (method->BidiStreaming()) {
+ } else if (method->BidiStreaming()) {
printer->Print(*vars,
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
" $prefix$$Service$_method_names[$Idx$],\n"
@@ -2265,66 +2265,66 @@ void PrintSourceService(grpc_generator::Printer* printer,
" $Request$>* stream) {\n"
" return service->$Method$(ctx, stream);\n"
" }, this)));\n");
- }
- }
- printer->Outdent();
- printer->Print(*vars, "}\n\n");
- printer->Print(*vars,
- "$ns$$Service$::Service::~Service() {\n"
- "}\n\n");
- for (int i = 0; i < service->method_count(); ++i) {
- (*vars)["Idx"] = as_string(i);
- PrintSourceServerMethod(printer, service->method(i).get(), vars);
- }
-}
-
+ }
+ }
+ printer->Outdent();
+ printer->Print(*vars, "}\n\n");
+ printer->Print(*vars,
+ "$ns$$Service$::Service::~Service() {\n"
+ "}\n\n");
+ for (int i = 0; i < service->method_count(); ++i) {
+ (*vars)["Idx"] = as_string(i);
+ PrintSourceServerMethod(printer, service->method(i).get(), vars);
+ }
+}
+
TString GetSourceServices(grpc_generator::File* file,
const Parameters& params) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- auto printer = file->CreatePrinter(&output);
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ auto printer = file->CreatePrinter(&output);
std::map<TString, TString> vars;
- // Package string is empty or ends with a dot. It is used to fully qualify
- // method names.
- vars["Package"] = file->package();
- if (!file->package().empty()) {
- vars["Package"].append(".");
- }
- if (!params.services_namespace.empty()) {
- vars["ns"] = params.services_namespace + "::";
- vars["prefix"] = params.services_namespace;
- } else {
- vars["ns"] = "";
- vars["prefix"] = "";
- }
-
- for (int i = 0; i < file->service_count(); ++i) {
- PrintSourceService(printer.get(), file->service(i).get(), &vars);
- printer->Print("\n");
- }
- }
- return output;
-}
-
+ // Package string is empty or ends with a dot. It is used to fully qualify
+ // method names.
+ vars["Package"] = file->package();
+ if (!file->package().empty()) {
+ vars["Package"].append(".");
+ }
+ if (!params.services_namespace.empty()) {
+ vars["ns"] = params.services_namespace + "::";
+ vars["prefix"] = params.services_namespace;
+ } else {
+ vars["ns"] = "";
+ vars["prefix"] = "";
+ }
+
+ for (int i = 0; i < file->service_count(); ++i) {
+ PrintSourceService(printer.get(), file->service(i).get(), &vars);
+ printer->Print("\n");
+ }
+ }
+ return output;
+}
+
TString GetSourceEpilogue(grpc_generator::File* file,
const Parameters& /*params*/) {
TString temp;
-
- if (!file->package().empty()) {
+
+ if (!file->package().empty()) {
std::vector<TString> parts = file->package_parts();
-
- for (auto part = parts.begin(); part != parts.end(); part++) {
- temp.append("} // namespace ");
- temp.append(*part);
- temp.append("\n");
- }
- temp.append("\n");
- }
-
- return temp;
-}
-
+
+ for (auto part = parts.begin(); part != parts.end(); part++) {
+ temp.append("} // namespace ");
+ temp.append(*part);
+ temp.append("\n");
+ }
+ temp.append("\n");
+ }
+
+ return temp;
+}
+
// TODO(mmukhi): Make sure we need parameters or not.
TString GetMockPrologue(grpc_generator::File* file,
const Parameters& params) {
@@ -2554,4 +2554,4 @@ TString GetMockEpilogue(grpc_generator::File* file,
return temp;
}
-} // namespace grpc_cpp_generator
+} // namespace grpc_cpp_generator
diff --git a/contrib/libs/grpc/src/compiler/cpp_generator.h b/contrib/libs/grpc/src/compiler/cpp_generator.h
index 606b850a874..ead928ce412 100644
--- a/contrib/libs/grpc/src/compiler/cpp_generator.h
+++ b/contrib/libs/grpc/src/compiler/cpp_generator.h
@@ -1,57 +1,57 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
-#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
-
-// cpp_generator.h/.cc do not directly depend on GRPC/ProtoBuf, such that they
-// can be used to generate code for other serialization systems, such as
-// FlatBuffers.
-
-#include <memory>
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
+#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
+
+// cpp_generator.h/.cc do not directly depend on GRPC/ProtoBuf, such that they
+// can be used to generate code for other serialization systems, such as
+// FlatBuffers.
+
+#include <memory>
#include <util/generic/string.h>
-#include <vector>
-
-#include "src/compiler/config.h"
+#include <vector>
+
+#include "src/compiler/config.h"
#include "src/compiler/schema_interface.h"
-
+
#ifdef GRPC_CUSTOM_STRING
#warning GRPC_CUSTOM_STRING is no longer supported. Please use TString.
-#endif
-
-namespace grpc {
-
+#endif
+
+namespace grpc {
+
// Using grpc::string and grpc::to_string is discouraged in favor of
// TString and ToString. This is only for legacy code using
// them explictly.
typedef TString string; // deprecated
-
-} // namespace grpc
-
-namespace grpc_cpp_generator {
-
-// Contains all the parameters that are parsed from the command line.
-struct Parameters {
- // Puts the service into a namespace
+
+} // namespace grpc
+
+namespace grpc_cpp_generator {
+
+// Contains all the parameters that are parsed from the command line.
+struct Parameters {
+ // Puts the service into a namespace
TString services_namespace;
- // Use system includes (<>) or local includes ("")
- bool use_system_headers;
- // Prefix to any grpc include
+ // Use system includes (<>) or local includes ("")
+ bool use_system_headers;
+ // Prefix to any grpc include
TString grpc_search_path;
// Generate Google Mock code to facilitate unit testing.
bool generate_mock_code;
@@ -63,72 +63,72 @@ struct Parameters {
TString message_header_extension;
// Whether to include headers corresponding to imports in source file.
bool include_import_headers;
-};
-
+};
+
// Return the prologue of the generated header file.
TString GetHeaderPrologue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the includes needed for generated header file.
TString GetHeaderIncludes(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the includes needed for generated source file.
TString GetSourceIncludes(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the epilogue of the generated header file.
TString GetHeaderEpilogue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the prologue of the generated source file.
TString GetSourcePrologue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the services for generated header file.
TString GetHeaderServices(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the services for generated source file.
TString GetSourceServices(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the epilogue of the generated source file.
TString GetSourceEpilogue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the prologue of the generated mock file.
TString GetMockPrologue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the includes needed for generated mock file.
TString GetMockIncludes(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the services for generated mock file.
TString GetMockServices(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the epilogue of generated mock file.
TString GetMockEpilogue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the prologue of the generated mock file.
TString GetMockPrologue(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the includes needed for generated mock file.
TString GetMockIncludes(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the services for generated mock file.
TString GetMockServices(grpc_generator::File* file,
const Parameters& params);
-
+
// Return the epilogue of generated mock file.
TString GetMockEpilogue(grpc_generator::File* file,
const Parameters& params);
-
-} // namespace grpc_cpp_generator
-
-#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
+
+} // namespace grpc_cpp_generator
+
+#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
diff --git a/contrib/libs/grpc/src/compiler/cpp_generator_helpers.h b/contrib/libs/grpc/src/compiler/cpp_generator_helpers.h
index 2e34d53a65d..98aa1c38052 100644
--- a/contrib/libs/grpc/src/compiler/cpp_generator_helpers.h
+++ b/contrib/libs/grpc/src/compiler/cpp_generator_helpers.h
@@ -1,63 +1,63 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
-#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
-
-#include <map>
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-
-namespace grpc_cpp_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
+#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
+
+#include <map>
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+
+namespace grpc_cpp_generator {
+
inline TString DotsToColons(const TString& name) {
- return grpc_generator::StringReplace(name, ".", "::");
-}
-
+ return grpc_generator::StringReplace(name, ".", "::");
+}
+
inline TString DotsToUnderscores(const TString& name) {
- return grpc_generator::StringReplace(name, ".", "_");
-}
-
+ return grpc_generator::StringReplace(name, ".", "_");
+}
+
inline TString ClassName(const grpc::protobuf::Descriptor* descriptor,
bool qualified) {
- // Find "outer", the descriptor of the top-level message in which
- // "descriptor" is embedded.
+ // Find "outer", the descriptor of the top-level message in which
+ // "descriptor" is embedded.
const grpc::protobuf::Descriptor* outer = descriptor;
- while (outer->containing_type() != NULL) outer = outer->containing_type();
-
+ while (outer->containing_type() != NULL) outer = outer->containing_type();
+
const TString& outer_name = outer->full_name();
TString inner_name = descriptor->full_name().substr(outer_name.size());
-
- if (qualified) {
- return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);
- } else {
- return outer->name() + DotsToUnderscores(inner_name);
- }
-}
-
-// Get leading or trailing comments in a string. Comment lines start with "// ".
+
+ if (qualified) {
+ return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);
+ } else {
+ return outer->name() + DotsToUnderscores(inner_name);
+ }
+}
+
+// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
-template <typename DescriptorType>
+template <typename DescriptorType>
inline TString GetCppComments(const DescriptorType* desc, bool leading) {
- return grpc_generator::GetPrefixedComments(desc, leading, "//");
-}
-
-} // namespace grpc_cpp_generator
-
-#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
+ return grpc_generator::GetPrefixedComments(desc, leading, "//");
+}
+
+} // namespace grpc_cpp_generator
+
+#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
diff --git a/contrib/libs/grpc/src/compiler/cpp_plugin.cc b/contrib/libs/grpc/src/compiler/cpp_plugin.cc
index 2de2745445f..a35607ab797 100644
--- a/contrib/libs/grpc/src/compiler/cpp_plugin.cc
+++ b/contrib/libs/grpc/src/compiler/cpp_plugin.cc
@@ -1,26 +1,26 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-// Generates cpp gRPC service interface out of Protobuf IDL.
-//
+ *
+ */
+
+// Generates cpp gRPC service interface out of Protobuf IDL.
+//
#include "src/compiler/cpp_plugin.h"
-
+
int main(int argc, char* argv[]) {
- CppGrpcGenerator generator;
- return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
-}
+ CppGrpcGenerator generator;
+ return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
+}
diff --git a/contrib/libs/grpc/src/compiler/csharp_generator.cc b/contrib/libs/grpc/src/compiler/csharp_generator.cc
index 3b7107c4c48..3a2797a8461 100644
--- a/contrib/libs/grpc/src/compiler/csharp_generator.cc
+++ b/contrib/libs/grpc/src/compiler/csharp_generator.cc
@@ -1,204 +1,204 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <cctype>
-#include <map>
-#include <sstream>
-#include <vector>
-
-#include "src/compiler/config.h"
-#include "src/compiler/csharp_generator.h"
-#include "src/compiler/csharp_generator_helpers.h"
-
+ *
+ */
+
+#include <cctype>
+#include <map>
+#include <sstream>
+#include <vector>
+
+#include "src/compiler/config.h"
+#include "src/compiler/csharp_generator.h"
+#include "src/compiler/csharp_generator_helpers.h"
+
using google::protobuf::compiler::csharp::GetClassName;
-using google::protobuf::compiler::csharp::GetFileNamespace;
-using google::protobuf::compiler::csharp::GetReflectionClassName;
+using google::protobuf::compiler::csharp::GetFileNamespace;
+using google::protobuf::compiler::csharp::GetReflectionClassName;
using grpc::protobuf::Descriptor;
-using grpc::protobuf::FileDescriptor;
+using grpc::protobuf::FileDescriptor;
using grpc::protobuf::MethodDescriptor;
-using grpc::protobuf::ServiceDescriptor;
-using grpc::protobuf::io::Printer;
-using grpc::protobuf::io::StringOutputStream;
-using grpc_generator::GetMethodType;
+using grpc::protobuf::ServiceDescriptor;
+using grpc::protobuf::io::Printer;
+using grpc::protobuf::io::StringOutputStream;
+using grpc_generator::GetMethodType;
using grpc_generator::MethodType;
using grpc_generator::METHODTYPE_BIDI_STREAMING;
using grpc_generator::METHODTYPE_CLIENT_STREAMING;
-using grpc_generator::METHODTYPE_NO_STREAMING;
-using grpc_generator::METHODTYPE_SERVER_STREAMING;
-using grpc_generator::StringReplace;
-using std::map;
-using std::vector;
-
-namespace grpc_csharp_generator {
-namespace {
-
-// This function is a massaged version of
-// https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
-// Currently, we cannot easily reuse the functionality as
-// google/protobuf/compiler/csharp/csharp_doc_comment.h is not a public header.
-// TODO(jtattermusch): reuse the functionality from google/protobuf.
+using grpc_generator::METHODTYPE_NO_STREAMING;
+using grpc_generator::METHODTYPE_SERVER_STREAMING;
+using grpc_generator::StringReplace;
+using std::map;
+using std::vector;
+
+namespace grpc_csharp_generator {
+namespace {
+
+// This function is a massaged version of
+// https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
+// Currently, we cannot easily reuse the functionality as
+// google/protobuf/compiler/csharp/csharp_doc_comment.h is not a public header.
+// TODO(jtattermusch): reuse the functionality from google/protobuf.
bool GenerateDocCommentBodyImpl(grpc::protobuf::io::Printer* printer,
- grpc::protobuf::SourceLocation location) {
+ grpc::protobuf::SourceLocation location) {
TString comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
- if (comments.empty()) {
- return false;
- }
- // XML escaping... no need for apostrophes etc as the whole text is going to
- // be a child
- // node of a summary element, not part of an attribute.
- comments = grpc_generator::StringReplace(comments, "&", "&amp;", true);
- comments = grpc_generator::StringReplace(comments, "<", "&lt;", true);
-
+ if (comments.empty()) {
+ return false;
+ }
+ // XML escaping... no need for apostrophes etc as the whole text is going to
+ // be a child
+ // node of a summary element, not part of an attribute.
+ comments = grpc_generator::StringReplace(comments, "&", "&amp;", true);
+ comments = grpc_generator::StringReplace(comments, "<", "&lt;", true);
+
std::vector<TString> lines;
- grpc_generator::Split(comments, '\n', &lines);
- // TODO: We really should work out which part to put in the summary and which
- // to put in the remarks...
- // but that needs to be part of a bigger effort to understand the markdown
- // better anyway.
- printer->Print("/// <summary>\n");
- bool last_was_empty = false;
- // We squash multiple blank lines down to one, and remove any trailing blank
- // lines. We need
- // to preserve the blank lines themselves, as this is relevant in the
- // markdown.
- // Note that we can't remove leading or trailing whitespace as *that's*
- // relevant in markdown too.
- // (We don't skip "just whitespace" lines, either.)
+ grpc_generator::Split(comments, '\n', &lines);
+ // TODO: We really should work out which part to put in the summary and which
+ // to put in the remarks...
+ // but that needs to be part of a bigger effort to understand the markdown
+ // better anyway.
+ printer->Print("/// <summary>\n");
+ bool last_was_empty = false;
+ // We squash multiple blank lines down to one, and remove any trailing blank
+ // lines. We need
+ // to preserve the blank lines themselves, as this is relevant in the
+ // markdown.
+ // Note that we can't remove leading or trailing whitespace as *that's*
+ // relevant in markdown too.
+ // (We don't skip "just whitespace" lines, either.)
for (std::vector<TString>::iterator it = lines.begin(); it != lines.end();
++it) {
TString line = *it;
- if (line.empty()) {
- last_was_empty = true;
- } else {
- if (last_was_empty) {
- printer->Print("///\n");
- }
- last_was_empty = false;
- printer->Print("///$line$\n", "line", *it);
- }
- }
- printer->Print("/// </summary>\n");
- return true;
-}
-
-template <typename DescriptorType>
+ if (line.empty()) {
+ last_was_empty = true;
+ } else {
+ if (last_was_empty) {
+ printer->Print("///\n");
+ }
+ last_was_empty = false;
+ printer->Print("///$line$\n", "line", *it);
+ }
+ }
+ printer->Print("/// </summary>\n");
+ return true;
+}
+
+template <typename DescriptorType>
bool GenerateDocCommentBody(grpc::protobuf::io::Printer* printer,
const DescriptorType* descriptor) {
- grpc::protobuf::SourceLocation location;
- if (!descriptor->GetSourceLocation(&location)) {
- return false;
- }
- return GenerateDocCommentBodyImpl(printer, location);
-}
-
+ grpc::protobuf::SourceLocation location;
+ if (!descriptor->GetSourceLocation(&location)) {
+ return false;
+ }
+ return GenerateDocCommentBodyImpl(printer, location);
+}
+
void GenerateDocCommentServerMethod(grpc::protobuf::io::Printer* printer,
const MethodDescriptor* method) {
- if (GenerateDocCommentBody(printer, method)) {
- if (method->client_streaming()) {
- printer->Print(
- "/// <param name=\"requestStream\">Used for reading requests from "
- "the client.</param>\n");
- } else {
- printer->Print(
- "/// <param name=\"request\">The request received from the "
- "client.</param>\n");
- }
- if (method->server_streaming()) {
- printer->Print(
- "/// <param name=\"responseStream\">Used for sending responses back "
- "to the client.</param>\n");
- }
- printer->Print(
- "/// <param name=\"context\">The context of the server-side call "
- "handler being invoked.</param>\n");
- if (method->server_streaming()) {
- printer->Print(
- "/// <returns>A task indicating completion of the "
- "handler.</returns>\n");
- } else {
- printer->Print(
- "/// <returns>The response to send back to the client (wrapped by a "
- "task).</returns>\n");
- }
- }
-}
-
+ if (GenerateDocCommentBody(printer, method)) {
+ if (method->client_streaming()) {
+ printer->Print(
+ "/// <param name=\"requestStream\">Used for reading requests from "
+ "the client.</param>\n");
+ } else {
+ printer->Print(
+ "/// <param name=\"request\">The request received from the "
+ "client.</param>\n");
+ }
+ if (method->server_streaming()) {
+ printer->Print(
+ "/// <param name=\"responseStream\">Used for sending responses back "
+ "to the client.</param>\n");
+ }
+ printer->Print(
+ "/// <param name=\"context\">The context of the server-side call "
+ "handler being invoked.</param>\n");
+ if (method->server_streaming()) {
+ printer->Print(
+ "/// <returns>A task indicating completion of the "
+ "handler.</returns>\n");
+ } else {
+ printer->Print(
+ "/// <returns>The response to send back to the client (wrapped by a "
+ "task).</returns>\n");
+ }
+ }
+}
+
void GenerateDocCommentClientMethod(grpc::protobuf::io::Printer* printer,
const MethodDescriptor* method,
- bool is_sync, bool use_call_options) {
- if (GenerateDocCommentBody(printer, method)) {
- if (!method->client_streaming()) {
- printer->Print(
- "/// <param name=\"request\">The request to send to the "
- "server.</param>\n");
- }
- if (!use_call_options) {
- printer->Print(
- "/// <param name=\"headers\">The initial metadata to send with the "
- "call. This parameter is optional.</param>\n");
- printer->Print(
- "/// <param name=\"deadline\">An optional deadline for the call. The "
- "call will be cancelled if deadline is hit.</param>\n");
- printer->Print(
- "/// <param name=\"cancellationToken\">An optional token for "
- "canceling the call.</param>\n");
- } else {
- printer->Print(
- "/// <param name=\"options\">The options for the call.</param>\n");
- }
- if (is_sync) {
- printer->Print(
- "/// <returns>The response received from the server.</returns>\n");
- } else {
- printer->Print("/// <returns>The call object.</returns>\n");
- }
- }
-}
-
+ bool is_sync, bool use_call_options) {
+ if (GenerateDocCommentBody(printer, method)) {
+ if (!method->client_streaming()) {
+ printer->Print(
+ "/// <param name=\"request\">The request to send to the "
+ "server.</param>\n");
+ }
+ if (!use_call_options) {
+ printer->Print(
+ "/// <param name=\"headers\">The initial metadata to send with the "
+ "call. This parameter is optional.</param>\n");
+ printer->Print(
+ "/// <param name=\"deadline\">An optional deadline for the call. The "
+ "call will be cancelled if deadline is hit.</param>\n");
+ printer->Print(
+ "/// <param name=\"cancellationToken\">An optional token for "
+ "canceling the call.</param>\n");
+ } else {
+ printer->Print(
+ "/// <param name=\"options\">The options for the call.</param>\n");
+ }
+ if (is_sync) {
+ printer->Print(
+ "/// <returns>The response received from the server.</returns>\n");
+ } else {
+ printer->Print("/// <returns>The call object.</returns>\n");
+ }
+ }
+}
+
TString GetServiceClassName(const ServiceDescriptor* service) {
- return service->name();
-}
-
+ return service->name();
+}
+
TString GetClientClassName(const ServiceDescriptor* service) {
- return service->name() + "Client";
-}
-
+ return service->name() + "Client";
+}
+
TString GetServerClassName(const ServiceDescriptor* service) {
- return service->name() + "Base";
-}
-
+ return service->name() + "Base";
+}
+
TString GetCSharpMethodType(MethodType method_type) {
- switch (method_type) {
- case METHODTYPE_NO_STREAMING:
+ switch (method_type) {
+ case METHODTYPE_NO_STREAMING:
return "grpc::MethodType.Unary";
- case METHODTYPE_CLIENT_STREAMING:
+ case METHODTYPE_CLIENT_STREAMING:
return "grpc::MethodType.ClientStreaming";
- case METHODTYPE_SERVER_STREAMING:
+ case METHODTYPE_SERVER_STREAMING:
return "grpc::MethodType.ServerStreaming";
- case METHODTYPE_BIDI_STREAMING:
+ case METHODTYPE_BIDI_STREAMING:
return "grpc::MethodType.DuplexStreaming";
- }
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return "";
-}
-
+ }
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "";
+}
+
TString GetCSharpServerMethodType(MethodType method_type) {
switch (method_type) {
case METHODTYPE_NO_STREAMING:
@@ -215,114 +215,114 @@ TString GetCSharpServerMethodType(MethodType method_type) {
}
TString GetServiceNameFieldName() { return "__ServiceName"; }
-
+
TString GetMarshallerFieldName(const Descriptor* message) {
return "__Marshaller_" +
grpc_generator::StringReplace(message->full_name(), ".", "_", true);
-}
-
+}
+
TString GetMethodFieldName(const MethodDescriptor* method) {
- return "__Method_" + method->name();
-}
-
+ return "__Method_" + method->name();
+}
+
TString GetMethodRequestParamMaybe(const MethodDescriptor* method,
- bool invocation_param = false) {
- if (method->client_streaming()) {
- return "";
- }
- if (invocation_param) {
- return "request, ";
- }
- return GetClassName(method->input_type()) + " request, ";
-}
-
+ bool invocation_param = false) {
+ if (method->client_streaming()) {
+ return "";
+ }
+ if (invocation_param) {
+ return "request, ";
+ }
+ return GetClassName(method->input_type()) + " request, ";
+}
+
TString GetAccessLevel(bool internal_access) {
- return internal_access ? "internal" : "public";
-}
-
+ return internal_access ? "internal" : "public";
+}
+
TString GetMethodReturnTypeClient(const MethodDescriptor* method) {
- switch (GetMethodType(method)) {
- case METHODTYPE_NO_STREAMING:
+ switch (GetMethodType(method)) {
+ case METHODTYPE_NO_STREAMING:
return "grpc::AsyncUnaryCall<" + GetClassName(method->output_type()) +
">";
- case METHODTYPE_CLIENT_STREAMING:
+ case METHODTYPE_CLIENT_STREAMING:
return "grpc::AsyncClientStreamingCall<" +
GetClassName(method->input_type()) + ", " +
GetClassName(method->output_type()) + ">";
- case METHODTYPE_SERVER_STREAMING:
+ case METHODTYPE_SERVER_STREAMING:
return "grpc::AsyncServerStreamingCall<" +
GetClassName(method->output_type()) + ">";
- case METHODTYPE_BIDI_STREAMING:
+ case METHODTYPE_BIDI_STREAMING:
return "grpc::AsyncDuplexStreamingCall<" +
GetClassName(method->input_type()) + ", " +
GetClassName(method->output_type()) + ">";
- }
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return "";
-}
-
+ }
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "";
+}
+
TString GetMethodRequestParamServer(const MethodDescriptor* method) {
- switch (GetMethodType(method)) {
- case METHODTYPE_NO_STREAMING:
- case METHODTYPE_SERVER_STREAMING:
- return GetClassName(method->input_type()) + " request";
- case METHODTYPE_CLIENT_STREAMING:
- case METHODTYPE_BIDI_STREAMING:
+ switch (GetMethodType(method)) {
+ case METHODTYPE_NO_STREAMING:
+ case METHODTYPE_SERVER_STREAMING:
+ return GetClassName(method->input_type()) + " request";
+ case METHODTYPE_CLIENT_STREAMING:
+ case METHODTYPE_BIDI_STREAMING:
return "grpc::IAsyncStreamReader<" + GetClassName(method->input_type()) +
- "> requestStream";
- }
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return "";
-}
-
+ "> requestStream";
+ }
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "";
+}
+
TString GetMethodReturnTypeServer(const MethodDescriptor* method) {
- switch (GetMethodType(method)) {
- case METHODTYPE_NO_STREAMING:
- case METHODTYPE_CLIENT_STREAMING:
- return "global::System.Threading.Tasks.Task<" +
- GetClassName(method->output_type()) + ">";
- case METHODTYPE_SERVER_STREAMING:
- case METHODTYPE_BIDI_STREAMING:
- return "global::System.Threading.Tasks.Task";
- }
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return "";
-}
-
+ switch (GetMethodType(method)) {
+ case METHODTYPE_NO_STREAMING:
+ case METHODTYPE_CLIENT_STREAMING:
+ return "global::System.Threading.Tasks.Task<" +
+ GetClassName(method->output_type()) + ">";
+ case METHODTYPE_SERVER_STREAMING:
+ case METHODTYPE_BIDI_STREAMING:
+ return "global::System.Threading.Tasks.Task";
+ }
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "";
+}
+
TString GetMethodResponseStreamMaybe(const MethodDescriptor* method) {
- switch (GetMethodType(method)) {
- case METHODTYPE_NO_STREAMING:
- case METHODTYPE_CLIENT_STREAMING:
- return "";
- case METHODTYPE_SERVER_STREAMING:
- case METHODTYPE_BIDI_STREAMING:
+ switch (GetMethodType(method)) {
+ case METHODTYPE_NO_STREAMING:
+ case METHODTYPE_CLIENT_STREAMING:
+ return "";
+ case METHODTYPE_SERVER_STREAMING:
+ case METHODTYPE_BIDI_STREAMING:
return ", grpc::IServerStreamWriter<" +
GetClassName(method->output_type()) + "> responseStream";
- }
- GOOGLE_LOG(FATAL) << "Can't get here.";
- return "";
-}
-
-// Gets vector of all messages used as input or output types.
+ }
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "";
+}
+
+// Gets vector of all messages used as input or output types.
std::vector<const Descriptor*> GetUsedMessages(
const ServiceDescriptor* service) {
std::set<const Descriptor*> descriptor_set;
std::vector<const Descriptor*>
- result; // vector is to maintain stable ordering
- for (int i = 0; i < service->method_count(); i++) {
+ result; // vector is to maintain stable ordering
+ for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
- if (descriptor_set.find(method->input_type()) == descriptor_set.end()) {
- descriptor_set.insert(method->input_type());
- result.push_back(method->input_type());
- }
- if (descriptor_set.find(method->output_type()) == descriptor_set.end()) {
- descriptor_set.insert(method->output_type());
- result.push_back(method->output_type());
- }
- }
- return result;
-}
-
+ if (descriptor_set.find(method->input_type()) == descriptor_set.end()) {
+ descriptor_set.insert(method->input_type());
+ result.push_back(method->input_type());
+ }
+ if (descriptor_set.find(method->output_type()) == descriptor_set.end()) {
+ descriptor_set.insert(method->output_type());
+ result.push_back(method->output_type());
+ }
+ }
+ return result;
+}
+
void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) {
std::vector<const Descriptor*> used_messages = GetUsedMessages(service);
if (used_messages.size() != 0) {
@@ -389,308 +389,308 @@ void GenerateMarshallerFields(Printer* out, const ServiceDescriptor* service) {
out->Print("}\n\n");
}
- for (size_t i = 0; i < used_messages.size(); i++) {
+ for (size_t i = 0; i < used_messages.size(); i++) {
const Descriptor* message = used_messages[i];
- out->Print(
+ out->Print(
"static readonly grpc::Marshaller<$type$> $fieldname$ = "
"grpc::Marshallers.Create(__Helper_SerializeMessage, "
"context => __Helper_DeserializeMessage(context, $type$.Parser));\n",
- "fieldname", GetMarshallerFieldName(message), "type",
- GetClassName(message));
- }
- out->Print("\n");
-}
-
+ "fieldname", GetMarshallerFieldName(message), "type",
+ GetClassName(message));
+ }
+ out->Print("\n");
+}
+
void GenerateStaticMethodField(Printer* out, const MethodDescriptor* method) {
- out->Print(
+ out->Print(
"static readonly grpc::Method<$request$, $response$> $fieldname$ = new "
"grpc::Method<$request$, $response$>(\n",
- "fieldname", GetMethodFieldName(method), "request",
- GetClassName(method->input_type()), "response",
- GetClassName(method->output_type()));
- out->Indent();
- out->Indent();
- out->Print("$methodtype$,\n", "methodtype",
- GetCSharpMethodType(GetMethodType(method)));
- out->Print("$servicenamefield$,\n", "servicenamefield",
- GetServiceNameFieldName());
- out->Print("\"$methodname$\",\n", "methodname", method->name());
- out->Print("$requestmarshaller$,\n", "requestmarshaller",
- GetMarshallerFieldName(method->input_type()));
- out->Print("$responsemarshaller$);\n", "responsemarshaller",
- GetMarshallerFieldName(method->output_type()));
- out->Print("\n");
- out->Outdent();
- out->Outdent();
-}
-
+ "fieldname", GetMethodFieldName(method), "request",
+ GetClassName(method->input_type()), "response",
+ GetClassName(method->output_type()));
+ out->Indent();
+ out->Indent();
+ out->Print("$methodtype$,\n", "methodtype",
+ GetCSharpMethodType(GetMethodType(method)));
+ out->Print("$servicenamefield$,\n", "servicenamefield",
+ GetServiceNameFieldName());
+ out->Print("\"$methodname$\",\n", "methodname", method->name());
+ out->Print("$requestmarshaller$,\n", "requestmarshaller",
+ GetMarshallerFieldName(method->input_type()));
+ out->Print("$responsemarshaller$);\n", "responsemarshaller",
+ GetMarshallerFieldName(method->output_type()));
+ out->Print("\n");
+ out->Outdent();
+ out->Outdent();
+}
+
void GenerateServiceDescriptorProperty(Printer* out,
const ServiceDescriptor* service) {
- std::ostringstream index;
- index << service->index();
- out->Print("/// <summary>Service descriptor</summary>\n");
- out->Print(
- "public static global::Google.Protobuf.Reflection.ServiceDescriptor "
- "Descriptor\n");
- out->Print("{\n");
- out->Print(" get { return $umbrella$.Descriptor.Services[$index$]; }\n",
- "umbrella", GetReflectionClassName(service->file()), "index",
- index.str());
- out->Print("}\n");
- out->Print("\n");
-}
-
+ std::ostringstream index;
+ index << service->index();
+ out->Print("/// <summary>Service descriptor</summary>\n");
+ out->Print(
+ "public static global::Google.Protobuf.Reflection.ServiceDescriptor "
+ "Descriptor\n");
+ out->Print("{\n");
+ out->Print(" get { return $umbrella$.Descriptor.Services[$index$]; }\n",
+ "umbrella", GetReflectionClassName(service->file()), "index",
+ index.str());
+ out->Print("}\n");
+ out->Print("\n");
+}
+
void GenerateServerClass(Printer* out, const ServiceDescriptor* service) {
- out->Print(
- "/// <summary>Base class for server-side implementations of "
- "$servicename$</summary>\n",
- "servicename", GetServiceClassName(service));
+ out->Print(
+ "/// <summary>Base class for server-side implementations of "
+ "$servicename$</summary>\n",
+ "servicename", GetServiceClassName(service));
out->Print(
"[grpc::BindServiceMethod(typeof($classname$), "
"\"BindService\")]\n",
"classname", GetServiceClassName(service));
- out->Print("public abstract partial class $name$\n", "name",
- GetServerClassName(service));
- out->Print("{\n");
- out->Indent();
- for (int i = 0; i < service->method_count(); i++) {
+ out->Print("public abstract partial class $name$\n", "name",
+ GetServerClassName(service));
+ out->Print("{\n");
+ out->Indent();
+ for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
- GenerateDocCommentServerMethod(out, method);
- out->Print(
- "public virtual $returntype$ "
- "$methodname$($request$$response_stream_maybe$, "
+ GenerateDocCommentServerMethod(out, method);
+ out->Print(
+ "public virtual $returntype$ "
+ "$methodname$($request$$response_stream_maybe$, "
"grpc::ServerCallContext context)\n",
- "methodname", method->name(), "returntype",
- GetMethodReturnTypeServer(method), "request",
- GetMethodRequestParamServer(method), "response_stream_maybe",
- GetMethodResponseStreamMaybe(method));
- out->Print("{\n");
- out->Indent();
- out->Print(
+ "methodname", method->name(), "returntype",
+ GetMethodReturnTypeServer(method), "request",
+ GetMethodRequestParamServer(method), "response_stream_maybe",
+ GetMethodResponseStreamMaybe(method));
+ out->Print("{\n");
+ out->Indent();
+ out->Print(
"throw new grpc::RpcException("
"new grpc::Status(grpc::StatusCode.Unimplemented, \"\"));\n");
- out->Outdent();
- out->Print("}\n\n");
- }
- out->Outdent();
- out->Print("}\n");
- out->Print("\n");
-}
-
+ out->Outdent();
+ out->Print("}\n\n");
+ }
+ out->Outdent();
+ out->Print("}\n");
+ out->Print("\n");
+}
+
void GenerateClientStub(Printer* out, const ServiceDescriptor* service) {
- out->Print("/// <summary>Client for $servicename$</summary>\n", "servicename",
- GetServiceClassName(service));
+ out->Print("/// <summary>Client for $servicename$</summary>\n", "servicename",
+ GetServiceClassName(service));
out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n", "name",
- GetClientClassName(service));
- out->Print("{\n");
- out->Indent();
-
- // constructors
- out->Print(
- "/// <summary>Creates a new client for $servicename$</summary>\n"
- "/// <param name=\"channel\">The channel to use to make remote "
- "calls.</param>\n",
- "servicename", GetServiceClassName(service));
+ GetClientClassName(service));
+ out->Print("{\n");
+ out->Indent();
+
+ // constructors
+ out->Print(
+ "/// <summary>Creates a new client for $servicename$</summary>\n"
+ "/// <param name=\"channel\">The channel to use to make remote "
+ "calls.</param>\n",
+ "servicename", GetServiceClassName(service));
out->Print("public $name$(grpc::ChannelBase channel) : base(channel)\n",
"name", GetClientClassName(service));
- out->Print("{\n");
- out->Print("}\n");
- out->Print(
- "/// <summary>Creates a new client for $servicename$ that uses a custom "
- "<c>CallInvoker</c>.</summary>\n"
- "/// <param name=\"callInvoker\">The callInvoker to use to make remote "
- "calls.</param>\n",
- "servicename", GetServiceClassName(service));
+ out->Print("{\n");
+ out->Print("}\n");
+ out->Print(
+ "/// <summary>Creates a new client for $servicename$ that uses a custom "
+ "<c>CallInvoker</c>.</summary>\n"
+ "/// <param name=\"callInvoker\">The callInvoker to use to make remote "
+ "calls.</param>\n",
+ "servicename", GetServiceClassName(service));
out->Print(
"public $name$(grpc::CallInvoker callInvoker) : base(callInvoker)\n",
"name", GetClientClassName(service));
- out->Print("{\n");
- out->Print("}\n");
- out->Print(
- "/// <summary>Protected parameterless constructor to allow creation"
- " of test doubles.</summary>\n");
- out->Print("protected $name$() : base()\n", "name",
- GetClientClassName(service));
- out->Print("{\n");
- out->Print("}\n");
- out->Print(
- "/// <summary>Protected constructor to allow creation of configured "
- "clients.</summary>\n"
- "/// <param name=\"configuration\">The client configuration.</param>\n");
- out->Print(
- "protected $name$(ClientBaseConfiguration configuration)"
- " : base(configuration)\n",
- "name", GetClientClassName(service));
- out->Print("{\n");
- out->Print("}\n\n");
-
- for (int i = 0; i < service->method_count(); i++) {
+ out->Print("{\n");
+ out->Print("}\n");
+ out->Print(
+ "/// <summary>Protected parameterless constructor to allow creation"
+ " of test doubles.</summary>\n");
+ out->Print("protected $name$() : base()\n", "name",
+ GetClientClassName(service));
+ out->Print("{\n");
+ out->Print("}\n");
+ out->Print(
+ "/// <summary>Protected constructor to allow creation of configured "
+ "clients.</summary>\n"
+ "/// <param name=\"configuration\">The client configuration.</param>\n");
+ out->Print(
+ "protected $name$(ClientBaseConfiguration configuration)"
+ " : base(configuration)\n",
+ "name", GetClientClassName(service));
+ out->Print("{\n");
+ out->Print("}\n\n");
+
+ for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
- MethodType method_type = GetMethodType(method);
-
- if (method_type == METHODTYPE_NO_STREAMING) {
- // unary calls have an extra synchronous stub method
- GenerateDocCommentClientMethod(out, method, true, false);
- out->Print(
+ MethodType method_type = GetMethodType(method);
+
+ if (method_type == METHODTYPE_NO_STREAMING) {
+ // unary calls have an extra synchronous stub method
+ GenerateDocCommentClientMethod(out, method, true, false);
+ out->Print(
"public virtual $response$ $methodname$($request$ request, "
"grpc::Metadata "
"headers = null, global::System.DateTime? deadline = null, "
"global::System.Threading.CancellationToken "
"cancellationToken = "
"default(global::System.Threading.CancellationToken))\n",
- "methodname", method->name(), "request",
- GetClassName(method->input_type()), "response",
- GetClassName(method->output_type()));
- out->Print("{\n");
- out->Indent();
- out->Print(
+ "methodname", method->name(), "request",
+ GetClassName(method->input_type()), "response",
+ GetClassName(method->output_type()));
+ out->Print("{\n");
+ out->Indent();
+ out->Print(
"return $methodname$(request, new grpc::CallOptions(headers, "
"deadline, "
- "cancellationToken));\n",
- "methodname", method->name());
- out->Outdent();
- out->Print("}\n");
-
- // overload taking CallOptions as a param
- GenerateDocCommentClientMethod(out, method, true, true);
- out->Print(
- "public virtual $response$ $methodname$($request$ request, "
+ "cancellationToken));\n",
+ "methodname", method->name());
+ out->Outdent();
+ out->Print("}\n");
+
+ // overload taking CallOptions as a param
+ GenerateDocCommentClientMethod(out, method, true, true);
+ out->Print(
+ "public virtual $response$ $methodname$($request$ request, "
"grpc::CallOptions options)\n",
- "methodname", method->name(), "request",
- GetClassName(method->input_type()), "response",
- GetClassName(method->output_type()));
- out->Print("{\n");
- out->Indent();
- out->Print(
- "return CallInvoker.BlockingUnaryCall($methodfield$, null, options, "
- "request);\n",
- "methodfield", GetMethodFieldName(method));
- out->Outdent();
- out->Print("}\n");
- }
-
+ "methodname", method->name(), "request",
+ GetClassName(method->input_type()), "response",
+ GetClassName(method->output_type()));
+ out->Print("{\n");
+ out->Indent();
+ out->Print(
+ "return CallInvoker.BlockingUnaryCall($methodfield$, null, options, "
+ "request);\n",
+ "methodfield", GetMethodFieldName(method));
+ out->Outdent();
+ out->Print("}\n");
+ }
+
TString method_name = method->name();
- if (method_type == METHODTYPE_NO_STREAMING) {
- method_name += "Async"; // prevent name clash with synchronous method.
- }
- GenerateDocCommentClientMethod(out, method, false, false);
- out->Print(
+ if (method_type == METHODTYPE_NO_STREAMING) {
+ method_name += "Async"; // prevent name clash with synchronous method.
+ }
+ GenerateDocCommentClientMethod(out, method, false, false);
+ out->Print(
"public virtual $returntype$ "
"$methodname$($request_maybe$grpc::Metadata "
"headers = null, global::System.DateTime? deadline = null, "
"global::System.Threading.CancellationToken "
"cancellationToken = "
"default(global::System.Threading.CancellationToken))\n",
- "methodname", method_name, "request_maybe",
- GetMethodRequestParamMaybe(method), "returntype",
- GetMethodReturnTypeClient(method));
- out->Print("{\n");
- out->Indent();
-
- out->Print(
+ "methodname", method_name, "request_maybe",
+ GetMethodRequestParamMaybe(method), "returntype",
+ GetMethodReturnTypeClient(method));
+ out->Print("{\n");
+ out->Indent();
+
+ out->Print(
"return $methodname$($request_maybe$new grpc::CallOptions(headers, "
"deadline, "
- "cancellationToken));\n",
- "methodname", method_name, "request_maybe",
- GetMethodRequestParamMaybe(method, true));
- out->Outdent();
- out->Print("}\n");
-
- // overload taking CallOptions as a param
- GenerateDocCommentClientMethod(out, method, false, true);
- out->Print(
+ "cancellationToken));\n",
+ "methodname", method_name, "request_maybe",
+ GetMethodRequestParamMaybe(method, true));
+ out->Outdent();
+ out->Print("}\n");
+
+ // overload taking CallOptions as a param
+ GenerateDocCommentClientMethod(out, method, false, true);
+ out->Print(
"public virtual $returntype$ "
"$methodname$($request_maybe$grpc::CallOptions "
- "options)\n",
- "methodname", method_name, "request_maybe",
- GetMethodRequestParamMaybe(method), "returntype",
- GetMethodReturnTypeClient(method));
- out->Print("{\n");
- out->Indent();
- switch (GetMethodType(method)) {
- case METHODTYPE_NO_STREAMING:
- out->Print(
- "return CallInvoker.AsyncUnaryCall($methodfield$, null, options, "
- "request);\n",
- "methodfield", GetMethodFieldName(method));
- break;
- case METHODTYPE_CLIENT_STREAMING:
- out->Print(
- "return CallInvoker.AsyncClientStreamingCall($methodfield$, null, "
- "options);\n",
- "methodfield", GetMethodFieldName(method));
- break;
- case METHODTYPE_SERVER_STREAMING:
- out->Print(
- "return CallInvoker.AsyncServerStreamingCall($methodfield$, null, "
- "options, request);\n",
- "methodfield", GetMethodFieldName(method));
- break;
- case METHODTYPE_BIDI_STREAMING:
- out->Print(
- "return CallInvoker.AsyncDuplexStreamingCall($methodfield$, null, "
- "options);\n",
- "methodfield", GetMethodFieldName(method));
- break;
- default:
- GOOGLE_LOG(FATAL) << "Can't get here.";
- }
- out->Outdent();
- out->Print("}\n");
- }
-
- // override NewInstance method
- out->Print(
- "/// <summary>Creates a new instance of client from given "
- "<c>ClientBaseConfiguration</c>.</summary>\n");
- out->Print(
- "protected override $name$ NewInstance(ClientBaseConfiguration "
- "configuration)\n",
- "name", GetClientClassName(service));
- out->Print("{\n");
- out->Indent();
- out->Print("return new $name$(configuration);\n", "name",
- GetClientClassName(service));
- out->Outdent();
- out->Print("}\n");
-
- out->Outdent();
- out->Print("}\n");
- out->Print("\n");
-}
-
+ "options)\n",
+ "methodname", method_name, "request_maybe",
+ GetMethodRequestParamMaybe(method), "returntype",
+ GetMethodReturnTypeClient(method));
+ out->Print("{\n");
+ out->Indent();
+ switch (GetMethodType(method)) {
+ case METHODTYPE_NO_STREAMING:
+ out->Print(
+ "return CallInvoker.AsyncUnaryCall($methodfield$, null, options, "
+ "request);\n",
+ "methodfield", GetMethodFieldName(method));
+ break;
+ case METHODTYPE_CLIENT_STREAMING:
+ out->Print(
+ "return CallInvoker.AsyncClientStreamingCall($methodfield$, null, "
+ "options);\n",
+ "methodfield", GetMethodFieldName(method));
+ break;
+ case METHODTYPE_SERVER_STREAMING:
+ out->Print(
+ "return CallInvoker.AsyncServerStreamingCall($methodfield$, null, "
+ "options, request);\n",
+ "methodfield", GetMethodFieldName(method));
+ break;
+ case METHODTYPE_BIDI_STREAMING:
+ out->Print(
+ "return CallInvoker.AsyncDuplexStreamingCall($methodfield$, null, "
+ "options);\n",
+ "methodfield", GetMethodFieldName(method));
+ break;
+ default:
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ }
+ out->Outdent();
+ out->Print("}\n");
+ }
+
+ // override NewInstance method
+ out->Print(
+ "/// <summary>Creates a new instance of client from given "
+ "<c>ClientBaseConfiguration</c>.</summary>\n");
+ out->Print(
+ "protected override $name$ NewInstance(ClientBaseConfiguration "
+ "configuration)\n",
+ "name", GetClientClassName(service));
+ out->Print("{\n");
+ out->Indent();
+ out->Print("return new $name$(configuration);\n", "name",
+ GetClientClassName(service));
+ out->Outdent();
+ out->Print("}\n");
+
+ out->Outdent();
+ out->Print("}\n");
+ out->Print("\n");
+}
+
void GenerateBindServiceMethod(Printer* out, const ServiceDescriptor* service) {
- out->Print(
- "/// <summary>Creates service definition that can be registered with a "
- "server</summary>\n");
- out->Print(
- "/// <param name=\"serviceImpl\">An object implementing the server-side"
- " handling logic.</param>\n");
- out->Print(
+ out->Print(
+ "/// <summary>Creates service definition that can be registered with a "
+ "server</summary>\n");
+ out->Print(
+ "/// <param name=\"serviceImpl\">An object implementing the server-side"
+ " handling logic.</param>\n");
+ out->Print(
"public static grpc::ServerServiceDefinition BindService($implclass$ "
- "serviceImpl)\n",
- "implclass", GetServerClassName(service));
- out->Print("{\n");
- out->Indent();
-
+ "serviceImpl)\n",
+ "implclass", GetServerClassName(service));
+ out->Print("{\n");
+ out->Indent();
+
out->Print("return grpc::ServerServiceDefinition.CreateBuilder()");
- out->Indent();
- out->Indent();
- for (int i = 0; i < service->method_count(); i++) {
+ out->Indent();
+ out->Indent();
+ for (int i = 0; i < service->method_count(); i++) {
const MethodDescriptor* method = service->method(i);
out->Print("\n.AddMethod($methodfield$, serviceImpl.$methodname$)",
- "methodfield", GetMethodFieldName(method), "methodname",
- method->name());
- }
+ "methodfield", GetMethodFieldName(method), "methodname",
+ method->name());
+ }
out->Print(".Build();\n");
- out->Outdent();
- out->Outdent();
-
- out->Outdent();
- out->Print("}\n");
- out->Print("\n");
-}
-
+ out->Outdent();
+ out->Outdent();
+
+ out->Outdent();
+ out->Print("}\n");
+ out->Print("\n");
+}
+
void GenerateBindServiceWithBinderMethod(Printer* out,
const ServiceDescriptor* service) {
out->Print(
@@ -733,94 +733,94 @@ void GenerateBindServiceWithBinderMethod(Printer* out,
}
void GenerateService(Printer* out, const ServiceDescriptor* service,
- bool generate_client, bool generate_server,
- bool internal_access) {
- GenerateDocCommentBody(out, service);
- out->Print("$access_level$ static partial class $classname$\n",
- "access_level", GetAccessLevel(internal_access), "classname",
- GetServiceClassName(service));
- out->Print("{\n");
- out->Indent();
- out->Print("static readonly string $servicenamefield$ = \"$servicename$\";\n",
- "servicenamefield", GetServiceNameFieldName(), "servicename",
- service->full_name());
- out->Print("\n");
-
- GenerateMarshallerFields(out, service);
- for (int i = 0; i < service->method_count(); i++) {
- GenerateStaticMethodField(out, service->method(i));
- }
- GenerateServiceDescriptorProperty(out, service);
-
- if (generate_server) {
- GenerateServerClass(out, service);
- }
- if (generate_client) {
- GenerateClientStub(out, service);
- }
- if (generate_server) {
- GenerateBindServiceMethod(out, service);
+ bool generate_client, bool generate_server,
+ bool internal_access) {
+ GenerateDocCommentBody(out, service);
+ out->Print("$access_level$ static partial class $classname$\n",
+ "access_level", GetAccessLevel(internal_access), "classname",
+ GetServiceClassName(service));
+ out->Print("{\n");
+ out->Indent();
+ out->Print("static readonly string $servicenamefield$ = \"$servicename$\";\n",
+ "servicenamefield", GetServiceNameFieldName(), "servicename",
+ service->full_name());
+ out->Print("\n");
+
+ GenerateMarshallerFields(out, service);
+ for (int i = 0; i < service->method_count(); i++) {
+ GenerateStaticMethodField(out, service->method(i));
+ }
+ GenerateServiceDescriptorProperty(out, service);
+
+ if (generate_server) {
+ GenerateServerClass(out, service);
+ }
+ if (generate_client) {
+ GenerateClientStub(out, service);
+ }
+ if (generate_server) {
+ GenerateBindServiceMethod(out, service);
GenerateBindServiceWithBinderMethod(out, service);
- }
-
- out->Outdent();
- out->Print("}\n");
-}
-
-} // anonymous namespace
-
+ }
+
+ out->Outdent();
+ out->Print("}\n");
+}
+
+} // anonymous namespace
+
TString GetServices(const FileDescriptor* file, bool generate_client,
bool generate_server, bool internal_access) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
-
- StringOutputStream output_stream(&output);
- Printer out(&output_stream, '$');
-
- // Don't write out any output if there no services, to avoid empty service
- // files being generated for proto files that don't declare any.
- if (file->service_count() == 0) {
- return output;
- }
-
- // Write out a file header.
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+
+ StringOutputStream output_stream(&output);
+ Printer out(&output_stream, '$');
+
+ // Don't write out any output if there no services, to avoid empty service
+ // files being generated for proto files that don't declare any.
+ if (file->service_count() == 0) {
+ return output;
+ }
+
+ // Write out a file header.
out.Print("// <auto-generated>\n");
out.Print(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print("// source: $filename$\n", "filename", file->name());
out.Print("// </auto-generated>\n");
-
- // use C++ style as there are no file-level XML comments in .NET
+
+ // use C++ style as there are no file-level XML comments in .NET
TString leading_comments = GetCsharpComments(file, true);
- if (!leading_comments.empty()) {
- out.Print("// Original file comments:\n");
+ if (!leading_comments.empty()) {
+ out.Print("// Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
- }
-
+ }
+
out.Print("#pragma warning disable 0414, 1591\n");
- out.Print("#region Designer generated code\n");
- out.Print("\n");
+ out.Print("#region Designer generated code\n");
+ out.Print("\n");
out.Print("using grpc = global::Grpc.Core;\n");
- out.Print("\n");
-
+ out.Print("\n");
+
TString file_namespace = GetFileNamespace(file);
if (file_namespace != "") {
out.Print("namespace $namespace$ {\n", "namespace", file_namespace);
out.Indent();
}
- for (int i = 0; i < file->service_count(); i++) {
- GenerateService(&out, file->service(i), generate_client, generate_server,
- internal_access);
- }
+ for (int i = 0; i < file->service_count(); i++) {
+ GenerateService(&out, file->service(i), generate_client, generate_server,
+ internal_access);
+ }
if (file_namespace != "") {
out.Outdent();
out.Print("}\n");
}
- out.Print("#endregion\n");
- }
- return output;
-}
-
-} // namespace grpc_csharp_generator
+ out.Print("#endregion\n");
+ }
+ return output;
+}
+
+} // namespace grpc_csharp_generator
diff --git a/contrib/libs/grpc/src/compiler/csharp_generator.h b/contrib/libs/grpc/src/compiler/csharp_generator.h
index c13da4657f3..9ff81bff4ba 100644
--- a/contrib/libs/grpc/src/compiler/csharp_generator.h
+++ b/contrib/libs/grpc/src/compiler/csharp_generator.h
@@ -1,34 +1,34 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_H
-#define GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_H
-
-#include "src/compiler/config.h"
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_H
+#define GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_H
+
+#include "src/compiler/config.h"
+
#include <google/protobuf/compiler/csharp/csharp_names.h>
-
-namespace grpc_csharp_generator {
-
+
+namespace grpc_csharp_generator {
+
TString GetServices(const grpc::protobuf::FileDescriptor* file,
bool generate_client, bool generate_server,
bool internal_access);
-
-} // namespace grpc_csharp_generator
-
-#endif // GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_H
+
+} // namespace grpc_csharp_generator
+
+#endif // GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_H
diff --git a/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h b/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h
index a8af7f3ccd1..5c189b7340e 100644
--- a/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h
+++ b/contrib/libs/grpc/src/compiler/csharp_generator_helpers.h
@@ -1,43 +1,43 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
-#define GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-
-namespace grpc_csharp_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
+#define GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+
+namespace grpc_csharp_generator {
+
inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
TString* file_name_or_error) {
- *file_name_or_error =
- grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs";
- return true;
-}
-
-// Get leading or trailing comments in a string. Comment lines start with "// ".
+ *file_name_or_error =
+ grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs";
+ return true;
+}
+
+// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
-template <typename DescriptorType>
+template <typename DescriptorType>
inline TString GetCsharpComments(const DescriptorType* desc, bool leading) {
- return grpc_generator::GetPrefixedComments(desc, leading, "//");
-}
-
-} // namespace grpc_csharp_generator
-
-#endif // GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
+ return grpc_generator::GetPrefixedComments(desc, leading, "//");
+}
+
+} // namespace grpc_csharp_generator
+
+#endif // GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
diff --git a/contrib/libs/grpc/src/compiler/generator_helpers.h b/contrib/libs/grpc/src/compiler/generator_helpers.h
index 265713a16b3..39e68b334b8 100644
--- a/contrib/libs/grpc/src/compiler/generator_helpers.h
+++ b/contrib/libs/grpc/src/compiler/generator_helpers.h
@@ -1,291 +1,291 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
-#define GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
-
-#include <iostream>
-#include <map>
-#include <sstream>
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
+#define GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
+
+#include <iostream>
+#include <map>
+#include <sstream>
#include <util/generic/string.h>
-#include <vector>
-
+#include <vector>
+
#include <util/generic/string.h>
#include <util/string/split.h>
-#include <util/stream/str.h>
-
+#include <util/stream/str.h>
+
#include "src/compiler/config.h"
-namespace grpc_generator {
-
+namespace grpc_generator {
+
inline bool StripSuffix(TString* filename, const TString& suffix) {
- if (filename->length() >= suffix.length()) {
- size_t suffix_pos = filename->length() - suffix.length();
+ if (filename->length() >= suffix.length()) {
+ size_t suffix_pos = filename->length() - suffix.length();
if (filename->compare(suffix_pos, TString::npos, suffix) == 0) {
- filename->resize(filename->size() - suffix.size());
- return true;
- }
- }
-
- return false;
-}
-
+ filename->resize(filename->size() - suffix.size());
+ return true;
+ }
+ }
+
+ return false;
+}
+
inline bool StripPrefix(TString* name, const TString& prefix) {
- if (name->length() >= prefix.length()) {
- if (name->substr(0, prefix.size()) == prefix) {
- *name = name->substr(prefix.size());
- return true;
- }
- }
- return false;
-}
-
+ if (name->length() >= prefix.length()) {
+ if (name->substr(0, prefix.size()) == prefix) {
+ *name = name->substr(prefix.size());
+ return true;
+ }
+ }
+ return false;
+}
+
inline TString StripProto(TString filename) {
- if (!StripSuffix(&filename, ".protodevel")) {
- StripSuffix(&filename, ".proto");
- }
- return filename;
-}
-
+ if (!StripSuffix(&filename, ".protodevel")) {
+ StripSuffix(&filename, ".proto");
+ }
+ return filename;
+}
+
inline TString StringReplace(TString str, const TString& from,
const TString& to, bool replace_all) {
- size_t pos = 0;
-
- do {
- pos = str.find(from, pos);
+ size_t pos = 0;
+
+ do {
+ pos = str.find(from, pos);
if (pos == TString::npos) {
- break;
- }
- str.replace(pos, from.length(), to);
- pos += to.length();
- } while (replace_all);
-
- return str;
-}
-
+ break;
+ }
+ str.replace(pos, from.length(), to);
+ pos += to.length();
+ } while (replace_all);
+
+ return str;
+}
+
inline TString StringReplace(TString str, const TString& from,
const TString& to) {
- return StringReplace(str, from, to, true);
-}
-
+ return StringReplace(str, from, to, true);
+}
+
inline std::vector<TString> tokenize(const TString& input,
const TString& delimiters) {
std::vector<TString> tokens;
- size_t pos, last_pos = 0;
-
- for (;;) {
- bool done = false;
- pos = input.find_first_of(delimiters, last_pos);
+ size_t pos, last_pos = 0;
+
+ for (;;) {
+ bool done = false;
+ pos = input.find_first_of(delimiters, last_pos);
if (pos == TString::npos) {
- done = true;
- pos = input.length();
- }
-
- tokens.push_back(input.substr(last_pos, pos - last_pos));
- if (done) return tokens;
-
- last_pos = pos + 1;
- }
-}
-
+ done = true;
+ pos = input.length();
+ }
+
+ tokens.push_back(input.substr(last_pos, pos - last_pos));
+ if (done) return tokens;
+
+ last_pos = pos + 1;
+ }
+}
+
inline TString CapitalizeFirstLetter(TString s) {
- if (s.empty()) {
- return s;
- }
- s[0] = ::toupper(s[0]);
- return s;
-}
-
+ if (s.empty()) {
+ return s;
+ }
+ s[0] = ::toupper(s[0]);
+ return s;
+}
+
inline TString LowercaseFirstLetter(TString s) {
- if (s.empty()) {
- return s;
- }
- s[0] = ::tolower(s[0]);
- return s;
-}
-
+ if (s.empty()) {
+ return s;
+ }
+ s[0] = ::tolower(s[0]);
+ return s;
+}
+
inline TString LowerUnderscoreToUpperCamel(TString str) {
std::vector<TString> tokens = tokenize(str, "_");
TString result = "";
- for (unsigned int i = 0; i < tokens.size(); i++) {
- result += CapitalizeFirstLetter(tokens[i]);
- }
- return result;
-}
-
+ for (unsigned int i = 0; i < tokens.size(); i++) {
+ result += CapitalizeFirstLetter(tokens[i]);
+ }
+ return result;
+}
+
inline TString FileNameInUpperCamel(
const grpc::protobuf::FileDescriptor* file, bool include_package_path) {
std::vector<TString> tokens = tokenize(StripProto(file->name()), "/");
TString result = "";
- if (include_package_path) {
- for (unsigned int i = 0; i < tokens.size() - 1; i++) {
- result += tokens[i] + "/";
- }
- }
- result += LowerUnderscoreToUpperCamel(tokens.back());
- return result;
-}
-
+ if (include_package_path) {
+ for (unsigned int i = 0; i < tokens.size() - 1; i++) {
+ result += tokens[i] + "/";
+ }
+ }
+ result += LowerUnderscoreToUpperCamel(tokens.back());
+ return result;
+}
+
inline TString FileNameInUpperCamel(
const grpc::protobuf::FileDescriptor* file) {
- return FileNameInUpperCamel(file, true);
-}
-
-enum MethodType {
- METHODTYPE_NO_STREAMING,
- METHODTYPE_CLIENT_STREAMING,
- METHODTYPE_SERVER_STREAMING,
- METHODTYPE_BIDI_STREAMING
-};
-
-inline MethodType GetMethodType(
+ return FileNameInUpperCamel(file, true);
+}
+
+enum MethodType {
+ METHODTYPE_NO_STREAMING,
+ METHODTYPE_CLIENT_STREAMING,
+ METHODTYPE_SERVER_STREAMING,
+ METHODTYPE_BIDI_STREAMING
+};
+
+inline MethodType GetMethodType(
const grpc::protobuf::MethodDescriptor* method) {
- if (method->client_streaming()) {
- if (method->server_streaming()) {
- return METHODTYPE_BIDI_STREAMING;
- } else {
- return METHODTYPE_CLIENT_STREAMING;
- }
- } else {
- if (method->server_streaming()) {
- return METHODTYPE_SERVER_STREAMING;
- } else {
- return METHODTYPE_NO_STREAMING;
- }
- }
-}
-
-template <typename TStringType>
+ if (method->client_streaming()) {
+ if (method->server_streaming()) {
+ return METHODTYPE_BIDI_STREAMING;
+ } else {
+ return METHODTYPE_CLIENT_STREAMING;
+ }
+ } else {
+ if (method->server_streaming()) {
+ return METHODTYPE_SERVER_STREAMING;
+ } else {
+ return METHODTYPE_NO_STREAMING;
+ }
+ }
+}
+
+template <typename TStringType>
inline void Split(const TStringType& s, char /*delim*/,
std::vector<TStringType>* append_to) {
- std::istringstream iss(s);
- TStringType piece;
+ std::istringstream iss(s);
+ TStringType piece;
while (std::getline(iss, piece)) {
- append_to->push_back(piece);
- }
-}
-
-template <>
+ append_to->push_back(piece);
+ }
+}
+
+template <>
inline void Split(const TString &s, char delim,
std::vector<TString> *append_to) {
TVector<TString> parts;
Split(s, TString(1, delim), parts);
for (auto& p : parts) {
append_to->push_back(std::move(p));
- }
-}
-
-enum CommentType {
- COMMENTTYPE_LEADING,
- COMMENTTYPE_TRAILING,
- COMMENTTYPE_LEADING_DETACHED
-};
-
-// Get all the raw comments and append each line without newline to out.
-template <typename DescriptorType>
+ }
+}
+
+enum CommentType {
+ COMMENTTYPE_LEADING,
+ COMMENTTYPE_TRAILING,
+ COMMENTTYPE_LEADING_DETACHED
+};
+
+// Get all the raw comments and append each line without newline to out.
+template <typename DescriptorType>
inline void GetComment(const DescriptorType* desc, CommentType type,
std::vector<TString>* out) {
- grpc::protobuf::SourceLocation location;
- if (!desc->GetSourceLocation(&location)) {
- return;
- }
- if (type == COMMENTTYPE_LEADING || type == COMMENTTYPE_TRAILING) {
+ grpc::protobuf::SourceLocation location;
+ if (!desc->GetSourceLocation(&location)) {
+ return;
+ }
+ if (type == COMMENTTYPE_LEADING || type == COMMENTTYPE_TRAILING) {
const TString& comments = type == COMMENTTYPE_LEADING
? location.leading_comments
: location.trailing_comments;
- Split(comments, '\n', out);
- } else if (type == COMMENTTYPE_LEADING_DETACHED) {
- for (unsigned int i = 0; i < location.leading_detached_comments.size();
- i++) {
- Split(location.leading_detached_comments[i], '\n', out);
- out->push_back("");
- }
- } else {
- std::cerr << "Unknown comment type " << type << std::endl;
- abort();
- }
-}
-
-// Each raw comment line without newline is appended to out.
-// For file level leading and detached leading comments, we return comments
-// above syntax line. Return nothing for trailing comments.
-template <>
+ Split(comments, '\n', out);
+ } else if (type == COMMENTTYPE_LEADING_DETACHED) {
+ for (unsigned int i = 0; i < location.leading_detached_comments.size();
+ i++) {
+ Split(location.leading_detached_comments[i], '\n', out);
+ out->push_back("");
+ }
+ } else {
+ std::cerr << "Unknown comment type " << type << std::endl;
+ abort();
+ }
+}
+
+// Each raw comment line without newline is appended to out.
+// For file level leading and detached leading comments, we return comments
+// above syntax line. Return nothing for trailing comments.
+template <>
inline void GetComment(const grpc::protobuf::FileDescriptor* desc,
CommentType type, std::vector<TString>* out) {
- if (type == COMMENTTYPE_TRAILING) {
- return;
- }
- grpc::protobuf::SourceLocation location;
- std::vector<int> path;
- path.push_back(grpc::protobuf::FileDescriptorProto::kSyntaxFieldNumber);
- if (!desc->GetSourceLocation(path, &location)) {
- return;
- }
- if (type == COMMENTTYPE_LEADING) {
- Split(location.leading_comments, '\n', out);
- } else if (type == COMMENTTYPE_LEADING_DETACHED) {
- for (unsigned int i = 0; i < location.leading_detached_comments.size();
- i++) {
- Split(location.leading_detached_comments[i], '\n', out);
- out->push_back("");
- }
- } else {
- std::cerr << "Unknown comment type " << type << std::endl;
- abort();
- }
-}
-
-// Add prefix and newline to each comment line and concatenate them together.
-// Make sure there is a space after the prefix unless the line is empty.
+ if (type == COMMENTTYPE_TRAILING) {
+ return;
+ }
+ grpc::protobuf::SourceLocation location;
+ std::vector<int> path;
+ path.push_back(grpc::protobuf::FileDescriptorProto::kSyntaxFieldNumber);
+ if (!desc->GetSourceLocation(path, &location)) {
+ return;
+ }
+ if (type == COMMENTTYPE_LEADING) {
+ Split(location.leading_comments, '\n', out);
+ } else if (type == COMMENTTYPE_LEADING_DETACHED) {
+ for (unsigned int i = 0; i < location.leading_detached_comments.size();
+ i++) {
+ Split(location.leading_detached_comments[i], '\n', out);
+ out->push_back("");
+ }
+ } else {
+ std::cerr << "Unknown comment type " << type << std::endl;
+ abort();
+ }
+}
+
+// Add prefix and newline to each comment line and concatenate them together.
+// Make sure there is a space after the prefix unless the line is empty.
inline TString GenerateCommentsWithPrefix(
const std::vector<TString>& in, const TString& prefix) {
- std::ostringstream oss;
- for (auto it = in.begin(); it != in.end(); it++) {
+ std::ostringstream oss;
+ for (auto it = in.begin(); it != in.end(); it++) {
const TString& elem = *it;
- if (elem.empty()) {
- oss << prefix << "\n";
- } else if (elem[0] == ' ') {
- oss << prefix << elem << "\n";
- } else {
- oss << prefix << " " << elem << "\n";
- }
- }
+ if (elem.empty()) {
+ oss << prefix << "\n";
+ } else if (elem[0] == ' ') {
+ oss << prefix << elem << "\n";
+ } else {
+ oss << prefix << " " << elem << "\n";
+ }
+ }
return oss.str();
-}
-
-template <typename DescriptorType>
+}
+
+template <typename DescriptorType>
inline TString GetPrefixedComments(const DescriptorType* desc, bool leading,
const TString& prefix) {
std::vector<TString> out;
- if (leading) {
- grpc_generator::GetComment(
- desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED, &out);
+ if (leading) {
+ grpc_generator::GetComment(
+ desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED, &out);
std::vector<TString> leading;
- grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING,
- &leading);
- out.insert(out.end(), leading.begin(), leading.end());
- } else {
- grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING,
- &out);
- }
- return GenerateCommentsWithPrefix(out, prefix);
-}
-
-} // namespace grpc_generator
-
-#endif // GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
+ grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING,
+ &leading);
+ out.insert(out.end(), leading.begin(), leading.end());
+ } else {
+ grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING,
+ &out);
+ }
+ return GenerateCommentsWithPrefix(out, prefix);
+}
+
+} // namespace grpc_generator
+
+#endif // GRPC_INTERNAL_COMPILER_GENERATOR_HELPERS_H
diff --git a/contrib/libs/grpc/src/compiler/node_generator.cc b/contrib/libs/grpc/src/compiler/node_generator.cc
index 89e4871a660..7865705ab49 100644
--- a/contrib/libs/grpc/src/compiler/node_generator.cc
+++ b/contrib/libs/grpc/src/compiler/node_generator.cc
@@ -1,275 +1,275 @@
-/*
- *
+/*
+ *
* Copyright 2016 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <map>
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
+ *
+ */
+
+#include <map>
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
#include "src/compiler/node_generator.h"
-#include "src/compiler/node_generator_helpers.h"
-
+#include "src/compiler/node_generator_helpers.h"
+
using grpc::protobuf::Descriptor;
-using grpc::protobuf::FileDescriptor;
+using grpc::protobuf::FileDescriptor;
using grpc::protobuf::MethodDescriptor;
-using grpc::protobuf::ServiceDescriptor;
-using grpc::protobuf::io::Printer;
-using grpc::protobuf::io::StringOutputStream;
-using std::map;
-
-namespace grpc_node_generator {
-namespace {
-
-// Returns the alias we assign to the module of the given .proto filename
-// when importing. Copied entirely from
-// github:google/protobuf/src/google/protobuf/compiler/js/js_generator.cc#L154
+using grpc::protobuf::ServiceDescriptor;
+using grpc::protobuf::io::Printer;
+using grpc::protobuf::io::StringOutputStream;
+using std::map;
+
+namespace grpc_node_generator {
+namespace {
+
+// Returns the alias we assign to the module of the given .proto filename
+// when importing. Copied entirely from
+// github:google/protobuf/src/google/protobuf/compiler/js/js_generator.cc#L154
TString ModuleAlias(const TString filename) {
- // This scheme could technically cause problems if a file includes any 2 of:
- // foo/bar_baz.proto
- // foo_bar_baz.proto
- // foo_bar/baz.proto
- //
- // We'll worry about this problem if/when we actually see it. This name isn't
- // exposed to users so we can change it later if we need to.
+ // This scheme could technically cause problems if a file includes any 2 of:
+ // foo/bar_baz.proto
+ // foo_bar_baz.proto
+ // foo_bar/baz.proto
+ //
+ // We'll worry about this problem if/when we actually see it. This name isn't
+ // exposed to users so we can change it later if we need to.
TString basename = grpc_generator::StripProto(filename);
- basename = grpc_generator::StringReplace(basename, "-", "$");
- basename = grpc_generator::StringReplace(basename, "/", "_");
+ basename = grpc_generator::StringReplace(basename, "-", "$");
+ basename = grpc_generator::StringReplace(basename, "/", "_");
basename = grpc_generator::StringReplace(basename, ".", "_");
- return basename + "_pb";
-}
-
-// Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript
-// message file foo/bar/baz.js
+ return basename + "_pb";
+}
+
+// Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript
+// message file foo/bar/baz.js
TString GetJSMessageFilename(const TString& filename) {
TString name = filename;
- return grpc_generator::StripProto(name) + "_pb.js";
-}
-
-// Given a filename like foo/bar/baz.proto, returns the root directory
-// path ../../
+ return grpc_generator::StripProto(name) + "_pb.js";
+}
+
+// Given a filename like foo/bar/baz.proto, returns the root directory
+// path ../../
TString GetRootPath(const TString& from_filename,
const TString& to_filename) {
- if (to_filename.find("google/protobuf") == 0) {
- // Well-known types (.proto files in the google/protobuf directory) are
- // assumed to come from the 'google-protobuf' npm package. We may want to
- // generalize this exception later by letting others put generated code in
- // their own npm packages.
- return "google-protobuf/";
- }
- size_t slashes = std::count(from_filename.begin(), from_filename.end(), '/');
- if (slashes == 0) {
- return "./";
- }
+ if (to_filename.find("google/protobuf") == 0) {
+ // Well-known types (.proto files in the google/protobuf directory) are
+ // assumed to come from the 'google-protobuf' npm package. We may want to
+ // generalize this exception later by letting others put generated code in
+ // their own npm packages.
+ return "google-protobuf/";
+ }
+ size_t slashes = std::count(from_filename.begin(), from_filename.end(), '/');
+ if (slashes == 0) {
+ return "./";
+ }
TString result = "";
- for (size_t i = 0; i < slashes; i++) {
- result += "../";
- }
- return result;
-}
-
-// Return the relative path to load to_file from the directory containing
-// from_file, assuming that both paths are relative to the same directory
+ for (size_t i = 0; i < slashes; i++) {
+ result += "../";
+ }
+ return result;
+}
+
+// Return the relative path to load to_file from the directory containing
+// from_file, assuming that both paths are relative to the same directory
TString GetRelativePath(const TString& from_file,
const TString& to_file) {
- return GetRootPath(from_file, to_file) + to_file;
-}
-
-/* Finds all message types used in all services in the file, and returns them
- * as a map of fully qualified message type name to message descriptor */
+ return GetRootPath(from_file, to_file) + to_file;
+}
+
+/* Finds all message types used in all services in the file, and returns them
+ * as a map of fully qualified message type name to message descriptor */
map<TString, const Descriptor*> GetAllMessages(const FileDescriptor* file) {
map<TString, const Descriptor*> message_types;
- for (int service_num = 0; service_num < file->service_count();
- service_num++) {
+ for (int service_num = 0; service_num < file->service_count();
+ service_num++) {
const ServiceDescriptor* service = file->service(service_num);
- for (int method_num = 0; method_num < service->method_count();
- method_num++) {
+ for (int method_num = 0; method_num < service->method_count();
+ method_num++) {
const MethodDescriptor* method = service->method(method_num);
const Descriptor* input_type = method->input_type();
const Descriptor* output_type = method->output_type();
- message_types[input_type->full_name()] = input_type;
- message_types[output_type->full_name()] = output_type;
- }
- }
- return message_types;
-}
-
+ message_types[input_type->full_name()] = input_type;
+ message_types[output_type->full_name()] = output_type;
+ }
+ }
+ return message_types;
+}
+
TString MessageIdentifierName(const TString& name) {
- return grpc_generator::StringReplace(name, ".", "_");
-}
-
+ return grpc_generator::StringReplace(name, ".", "_");
+}
+
TString NodeObjectPath(const Descriptor* descriptor) {
TString module_alias = ModuleAlias(descriptor->file()->name());
TString name = descriptor->full_name();
- grpc_generator::StripPrefix(&name, descriptor->file()->package() + ".");
- return module_alias + "." + name;
-}
-
-// Prints out the message serializer and deserializer functions
+ grpc_generator::StripPrefix(&name, descriptor->file()->package() + ".");
+ return module_alias + "." + name;
+}
+
+// Prints out the message serializer and deserializer functions
void PrintMessageTransformer(const Descriptor* descriptor, Printer* out,
const Parameters& params) {
map<TString, TString> template_vars;
TString full_name = descriptor->full_name();
- template_vars["identifier_name"] = MessageIdentifierName(full_name);
- template_vars["name"] = full_name;
- template_vars["node_name"] = NodeObjectPath(descriptor);
- // Print the serializer
- out->Print(template_vars, "function serialize_$identifier_name$(arg) {\n");
- out->Indent();
- out->Print(template_vars, "if (!(arg instanceof $node_name$)) {\n");
- out->Indent();
- out->Print(template_vars,
- "throw new Error('Expected argument of type $name$');\n");
- out->Outdent();
- out->Print("}\n");
+ template_vars["identifier_name"] = MessageIdentifierName(full_name);
+ template_vars["name"] = full_name;
+ template_vars["node_name"] = NodeObjectPath(descriptor);
+ // Print the serializer
+ out->Print(template_vars, "function serialize_$identifier_name$(arg) {\n");
+ out->Indent();
+ out->Print(template_vars, "if (!(arg instanceof $node_name$)) {\n");
+ out->Indent();
+ out->Print(template_vars,
+ "throw new Error('Expected argument of type $name$');\n");
+ out->Outdent();
+ out->Print("}\n");
if (params.minimum_node_version > 5) {
// Node version is > 5, we should use Buffer.from
out->Print("return Buffer.from(arg.serializeBinary());\n");
} else {
out->Print("return new Buffer(arg.serializeBinary());\n");
}
- out->Outdent();
- out->Print("}\n\n");
-
- // Print the deserializer
- out->Print(template_vars,
- "function deserialize_$identifier_name$(buffer_arg) {\n");
- out->Indent();
- out->Print(
- template_vars,
- "return $node_name$.deserializeBinary(new Uint8Array(buffer_arg));\n");
- out->Outdent();
- out->Print("}\n\n");
-}
-
+ out->Outdent();
+ out->Print("}\n\n");
+
+ // Print the deserializer
+ out->Print(template_vars,
+ "function deserialize_$identifier_name$(buffer_arg) {\n");
+ out->Indent();
+ out->Print(
+ template_vars,
+ "return $node_name$.deserializeBinary(new Uint8Array(buffer_arg));\n");
+ out->Outdent();
+ out->Print("}\n\n");
+}
+
void PrintMethod(const MethodDescriptor* method, Printer* out) {
const Descriptor* input_type = method->input_type();
const Descriptor* output_type = method->output_type();
map<TString, TString> vars;
- vars["service_name"] = method->service()->full_name();
- vars["name"] = method->name();
- vars["input_type"] = NodeObjectPath(input_type);
- vars["input_type_id"] = MessageIdentifierName(input_type->full_name());
- vars["output_type"] = NodeObjectPath(output_type);
- vars["output_type_id"] = MessageIdentifierName(output_type->full_name());
- vars["client_stream"] = method->client_streaming() ? "true" : "false";
- vars["server_stream"] = method->server_streaming() ? "true" : "false";
- out->Print("{\n");
- out->Indent();
- out->Print(vars, "path: '/$service_name$/$name$',\n");
- out->Print(vars, "requestStream: $client_stream$,\n");
- out->Print(vars, "responseStream: $server_stream$,\n");
- out->Print(vars, "requestType: $input_type$,\n");
- out->Print(vars, "responseType: $output_type$,\n");
- out->Print(vars, "requestSerialize: serialize_$input_type_id$,\n");
- out->Print(vars, "requestDeserialize: deserialize_$input_type_id$,\n");
- out->Print(vars, "responseSerialize: serialize_$output_type_id$,\n");
- out->Print(vars, "responseDeserialize: deserialize_$output_type_id$,\n");
- out->Outdent();
- out->Print("}");
-}
-
-// Prints out the service descriptor object
+ vars["service_name"] = method->service()->full_name();
+ vars["name"] = method->name();
+ vars["input_type"] = NodeObjectPath(input_type);
+ vars["input_type_id"] = MessageIdentifierName(input_type->full_name());
+ vars["output_type"] = NodeObjectPath(output_type);
+ vars["output_type_id"] = MessageIdentifierName(output_type->full_name());
+ vars["client_stream"] = method->client_streaming() ? "true" : "false";
+ vars["server_stream"] = method->server_streaming() ? "true" : "false";
+ out->Print("{\n");
+ out->Indent();
+ out->Print(vars, "path: '/$service_name$/$name$',\n");
+ out->Print(vars, "requestStream: $client_stream$,\n");
+ out->Print(vars, "responseStream: $server_stream$,\n");
+ out->Print(vars, "requestType: $input_type$,\n");
+ out->Print(vars, "responseType: $output_type$,\n");
+ out->Print(vars, "requestSerialize: serialize_$input_type_id$,\n");
+ out->Print(vars, "requestDeserialize: deserialize_$input_type_id$,\n");
+ out->Print(vars, "responseSerialize: serialize_$output_type_id$,\n");
+ out->Print(vars, "responseDeserialize: deserialize_$output_type_id$,\n");
+ out->Outdent();
+ out->Print("}");
+}
+
+// Prints out the service descriptor object
void PrintService(const ServiceDescriptor* service, Printer* out) {
map<TString, TString> template_vars;
- out->Print(GetNodeComments(service, true).c_str());
- template_vars["name"] = service->name();
- out->Print(template_vars, "var $name$Service = exports.$name$Service = {\n");
- out->Indent();
- for (int i = 0; i < service->method_count(); i++) {
+ out->Print(GetNodeComments(service, true).c_str());
+ template_vars["name"] = service->name();
+ out->Print(template_vars, "var $name$Service = exports.$name$Service = {\n");
+ out->Indent();
+ for (int i = 0; i < service->method_count(); i++) {
TString method_name =
- grpc_generator::LowercaseFirstLetter(service->method(i)->name());
- out->Print(GetNodeComments(service->method(i), true).c_str());
- out->Print("$method_name$: ", "method_name", method_name);
- PrintMethod(service->method(i), out);
- out->Print(",\n");
- out->Print(GetNodeComments(service->method(i), false).c_str());
- }
- out->Outdent();
- out->Print("};\n\n");
- out->Print(template_vars,
- "exports.$name$Client = "
- "grpc.makeGenericClientConstructor($name$Service);\n");
- out->Print(GetNodeComments(service, false).c_str());
-}
-
+ grpc_generator::LowercaseFirstLetter(service->method(i)->name());
+ out->Print(GetNodeComments(service->method(i), true).c_str());
+ out->Print("$method_name$: ", "method_name", method_name);
+ PrintMethod(service->method(i), out);
+ out->Print(",\n");
+ out->Print(GetNodeComments(service->method(i), false).c_str());
+ }
+ out->Outdent();
+ out->Print("};\n\n");
+ out->Print(template_vars,
+ "exports.$name$Client = "
+ "grpc.makeGenericClientConstructor($name$Service);\n");
+ out->Print(GetNodeComments(service, false).c_str());
+}
+
void PrintImports(const FileDescriptor* file, Printer* out) {
- out->Print("var grpc = require('grpc');\n");
- if (file->message_type_count() > 0) {
+ out->Print("var grpc = require('grpc');\n");
+ if (file->message_type_count() > 0) {
TString file_path =
- GetRelativePath(file->name(), GetJSMessageFilename(file->name()));
- out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias",
- ModuleAlias(file->name()), "file_path", file_path);
- }
-
- for (int i = 0; i < file->dependency_count(); i++) {
+ GetRelativePath(file->name(), GetJSMessageFilename(file->name()));
+ out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias",
+ ModuleAlias(file->name()), "file_path", file_path);
+ }
+
+ for (int i = 0; i < file->dependency_count(); i++) {
TString file_path = GetRelativePath(
- file->name(), GetJSMessageFilename(file->dependency(i)->name()));
- out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias",
- ModuleAlias(file->dependency(i)->name()), "file_path",
- file_path);
- }
- out->Print("\n");
-}
-
+ file->name(), GetJSMessageFilename(file->dependency(i)->name()));
+ out->Print("var $module_alias$ = require('$file_path$');\n", "module_alias",
+ ModuleAlias(file->dependency(i)->name()), "file_path",
+ file_path);
+ }
+ out->Print("\n");
+}
+
void PrintTransformers(const FileDescriptor* file, Printer* out,
const Parameters& params) {
map<TString, const Descriptor*> messages = GetAllMessages(file);
for (std::map<TString, const Descriptor*>::iterator it = messages.begin();
- it != messages.end(); it++) {
+ it != messages.end(); it++) {
PrintMessageTransformer(it->second, out, params);
- }
- out->Print("\n");
-}
-
+ }
+ out->Print("\n");
+}
+
void PrintServices(const FileDescriptor* file, Printer* out) {
- for (int i = 0; i < file->service_count(); i++) {
- PrintService(file->service(i), out);
- }
-}
+ for (int i = 0; i < file->service_count(); i++) {
+ PrintService(file->service(i), out);
+ }
+}
} // namespace
-
+
TString GenerateFile(const FileDescriptor* file, const Parameters& params) {
TString output;
- {
- StringOutputStream output_stream(&output);
- Printer out(&output_stream, '$');
-
- if (file->service_count() == 0) {
- return output;
- }
- out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
-
+ {
+ StringOutputStream output_stream(&output);
+ Printer out(&output_stream, '$');
+
+ if (file->service_count() == 0) {
+ return output;
+ }
+ out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
+
TString leading_comments = GetNodeComments(file, true);
- if (!leading_comments.empty()) {
- out.Print("// Original file comments:\n");
+ if (!leading_comments.empty()) {
+ out.Print("// Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
- }
-
- out.Print("'use strict';\n");
-
- PrintImports(file, &out);
-
+ }
+
+ out.Print("'use strict';\n");
+
+ PrintImports(file, &out);
+
PrintTransformers(file, &out, params);
-
- PrintServices(file, &out);
-
- out.Print(GetNodeComments(file, false).c_str());
- }
- return output;
-}
-
-} // namespace grpc_node_generator
+
+ PrintServices(file, &out);
+
+ out.Print(GetNodeComments(file, false).c_str());
+ }
+ return output;
+}
+
+} // namespace grpc_node_generator
diff --git a/contrib/libs/grpc/src/compiler/node_generator.h b/contrib/libs/grpc/src/compiler/node_generator.h
index 959df436ea5..f964a1e4798 100644
--- a/contrib/libs/grpc/src/compiler/node_generator.h
+++ b/contrib/libs/grpc/src/compiler/node_generator.h
@@ -1,37 +1,37 @@
-/*
- *
+/*
+ *
* Copyright 2016 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_NODE_GENERATOR_H
-#define GRPC_INTERNAL_COMPILER_NODE_GENERATOR_H
-
-#include "src/compiler/config.h"
-
-namespace grpc_node_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_NODE_GENERATOR_H
+#define GRPC_INTERNAL_COMPILER_NODE_GENERATOR_H
+
+#include "src/compiler/config.h"
+
+namespace grpc_node_generator {
+
// Contains all the parameters that are parsed from the command line.
struct Parameters {
// Sets the earliest version of nodejs that needs to be supported.
int minimum_node_version;
};
-
+
TString GenerateFile(const grpc::protobuf::FileDescriptor* file,
const Parameters& params);
-} // namespace grpc_node_generator
-
-#endif // GRPC_INTERNAL_COMPILER_NODE_GENERATOR_H
+} // namespace grpc_node_generator
+
+#endif // GRPC_INTERNAL_COMPILER_NODE_GENERATOR_H
diff --git a/contrib/libs/grpc/src/compiler/node_generator_helpers.h b/contrib/libs/grpc/src/compiler/node_generator_helpers.h
index ccf57ec8a62..1ab0e2eaf8c 100644
--- a/contrib/libs/grpc/src/compiler/node_generator_helpers.h
+++ b/contrib/libs/grpc/src/compiler/node_generator_helpers.h
@@ -1,42 +1,42 @@
-/*
- *
+/*
+ *
* Copyright 2016 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
-#define GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
-
-#include <algorithm>
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-
-namespace grpc_node_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
+#define GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
+
+#include <algorithm>
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+
+namespace grpc_node_generator {
+
inline TString GetJSServiceFilename(const TString& filename) {
- return grpc_generator::StripProto(filename) + "_grpc_pb.js";
-}
-
-// Get leading or trailing comments in a string. Comment lines start with "// ".
+ return grpc_generator::StripProto(filename) + "_grpc_pb.js";
+}
+
+// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
-template <typename DescriptorType>
+template <typename DescriptorType>
inline TString GetNodeComments(const DescriptorType* desc, bool leading) {
- return grpc_generator::GetPrefixedComments(desc, leading, "//");
-}
-
-} // namespace grpc_node_generator
-
-#endif // GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
+ return grpc_generator::GetPrefixedComments(desc, leading, "//");
+}
+
+} // namespace grpc_node_generator
+
+#endif // GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
diff --git a/contrib/libs/grpc/src/compiler/objective_c_generator.cc b/contrib/libs/grpc/src/compiler/objective_c_generator.cc
index 07826b6a8d8..80b58ee13ce 100644
--- a/contrib/libs/grpc/src/compiler/objective_c_generator.cc
+++ b/contrib/libs/grpc/src/compiler/objective_c_generator.cc
@@ -1,75 +1,75 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <map>
+ *
+ */
+
+#include <map>
#include <set>
-#include <sstream>
-
-#include "src/compiler/config.h"
-#include "src/compiler/objective_c_generator.h"
-#include "src/compiler/objective_c_generator_helpers.h"
-
+#include <sstream>
+
+#include "src/compiler/config.h"
+#include "src/compiler/objective_c_generator.h"
+#include "src/compiler/objective_c_generator_helpers.h"
+
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
-
-using ::google::protobuf::compiler::objectivec::ClassName;
+
+using ::google::protobuf::compiler::objectivec::ClassName;
using ::grpc::protobuf::FileDescriptor;
-using ::grpc::protobuf::MethodDescriptor;
-using ::grpc::protobuf::ServiceDescriptor;
+using ::grpc::protobuf::MethodDescriptor;
+using ::grpc::protobuf::ServiceDescriptor;
using ::grpc::protobuf::io::Printer;
-using ::std::map;
+using ::std::map;
using ::std::set;
-
-namespace grpc_objective_c_generator {
-namespace {
-
+
+namespace grpc_objective_c_generator {
+namespace {
+
void PrintProtoRpcDeclarationAsPragma(Printer* printer,
const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
- vars["client_stream"] = method->client_streaming() ? "stream " : "";
- vars["server_stream"] = method->server_streaming() ? "stream " : "";
-
- printer->Print(vars,
- "#pragma mark $method_name$($client_stream$$request_type$)"
- " returns ($server_stream$$response_type$)\n\n");
-}
-
-template <typename DescriptorType>
+ vars["client_stream"] = method->client_streaming() ? "stream " : "";
+ vars["server_stream"] = method->server_streaming() ? "stream " : "";
+
+ printer->Print(vars,
+ "#pragma mark $method_name$($client_stream$$request_type$)"
+ " returns ($server_stream$$response_type$)\n\n");
+}
+
+template <typename DescriptorType>
static void PrintAllComments(const DescriptorType* desc, Printer* printer,
bool deprecated = false) {
std::vector<TString> comments;
- grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED,
- &comments);
- grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING,
- &comments);
- grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING,
- &comments);
- if (comments.empty()) {
- return;
- }
- printer->Print("/**\n");
- for (auto it = comments.begin(); it != comments.end(); ++it) {
- printer->Print(" * ");
- size_t start_pos = it->find_first_not_of(' ');
+ grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING_DETACHED,
+ &comments);
+ grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_LEADING,
+ &comments);
+ grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING,
+ &comments);
+ if (comments.empty()) {
+ return;
+ }
+ printer->Print("/**\n");
+ for (auto it = comments.begin(); it != comments.end(); ++it) {
+ printer->Print(" * ");
+ size_t start_pos = it->find_first_not_of(' ');
if (start_pos != TString::npos) {
printer->PrintRaw(it->c_str() + start_pos);
- }
- printer->Print("\n");
- }
+ }
+ printer->Print("\n");
+ }
if (deprecated) {
printer->Print(" *\n");
printer->Print(
@@ -77,49 +77,49 @@ static void PrintAllComments(const DescriptorType* desc, Printer* printer,
"Using"
" the v2 API is recommended.\n");
}
- printer->Print(" */\n");
-}
-
+ printer->Print(" */\n");
+}
+
void PrintMethodSignature(Printer* printer, const MethodDescriptor* method,
const map< ::TString, ::TString>& vars) {
- // Print comment
+ // Print comment
PrintAllComments(method, printer, true);
-
- printer->Print(vars, "- ($return_type$)$method_name$With");
- if (method->client_streaming()) {
- printer->Print("RequestsWriter:(GRXWriter *)requestWriter");
- } else {
- printer->Print(vars, "Request:($request_class$ *)request");
- }
-
- // TODO(jcanizales): Put this on a new line and align colons.
- if (method->server_streaming()) {
- printer->Print(vars,
- " eventHandler:(void(^)(BOOL done, "
- "$response_class$ *_Nullable response, NSError *_Nullable "
- "error))eventHandler");
- } else {
- printer->Print(vars,
- " handler:(void(^)($response_class$ *_Nullable response, "
- "NSError *_Nullable error))handler");
- }
-}
-
+
+ printer->Print(vars, "- ($return_type$)$method_name$With");
+ if (method->client_streaming()) {
+ printer->Print("RequestsWriter:(GRXWriter *)requestWriter");
+ } else {
+ printer->Print(vars, "Request:($request_class$ *)request");
+ }
+
+ // TODO(jcanizales): Put this on a new line and align colons.
+ if (method->server_streaming()) {
+ printer->Print(vars,
+ " eventHandler:(void(^)(BOOL done, "
+ "$response_class$ *_Nullable response, NSError *_Nullable "
+ "error))eventHandler");
+ } else {
+ printer->Print(vars,
+ " handler:(void(^)($response_class$ *_Nullable response, "
+ "NSError *_Nullable error))handler");
+ }
+}
+
void PrintSimpleSignature(Printer* printer, const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
- vars["method_name"] =
- grpc_generator::LowercaseFirstLetter(vars["method_name"]);
- vars["return_type"] = "void";
- PrintMethodSignature(printer, method, vars);
-}
-
+ vars["method_name"] =
+ grpc_generator::LowercaseFirstLetter(vars["method_name"]);
+ vars["return_type"] = "void";
+ PrintMethodSignature(printer, method, vars);
+}
+
void PrintAdvancedSignature(Printer* printer, const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
- vars["method_name"] = "RPCTo" + vars["method_name"];
- vars["return_type"] = "GRPCProtoCall *";
- PrintMethodSignature(printer, method, vars);
-}
-
+ vars["method_name"] = "RPCTo" + vars["method_name"];
+ vars["return_type"] = "GRPCProtoCall *";
+ PrintMethodSignature(printer, method, vars);
+}
+
void PrintV2Signature(Printer* printer, const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
if (method->client_streaming()) {
@@ -146,25 +146,25 @@ void PrintV2Signature(Printer* printer, const MethodDescriptor* method,
inline map< ::TString, ::TString> GetMethodVars(
const MethodDescriptor* method) {
map< ::TString, ::TString> res;
- res["method_name"] = method->name();
- res["request_type"] = method->input_type()->name();
- res["response_type"] = method->output_type()->name();
- res["request_class"] = ClassName(method->input_type());
- res["response_class"] = ClassName(method->output_type());
- return res;
-}
-
+ res["method_name"] = method->name();
+ res["request_type"] = method->input_type()->name();
+ res["response_type"] = method->output_type()->name();
+ res["request_class"] = ClassName(method->input_type());
+ res["response_class"] = ClassName(method->output_type());
+ return res;
+}
+
void PrintMethodDeclarations(Printer* printer, const MethodDescriptor* method) {
map< ::TString, ::TString> vars = GetMethodVars(method);
-
- PrintProtoRpcDeclarationAsPragma(printer, method, vars);
-
- PrintSimpleSignature(printer, method, vars);
- printer->Print(";\n\n");
- PrintAdvancedSignature(printer, method, vars);
- printer->Print(";\n\n\n");
-}
-
+
+ PrintProtoRpcDeclarationAsPragma(printer, method, vars);
+
+ PrintSimpleSignature(printer, method, vars);
+ printer->Print(";\n\n");
+ PrintAdvancedSignature(printer, method, vars);
+ printer->Print(";\n\n\n");
+}
+
void PrintV2MethodDeclarations(Printer* printer,
const MethodDescriptor* method) {
map< ::TString, ::TString> vars = GetMethodVars(method);
@@ -177,46 +177,46 @@ void PrintV2MethodDeclarations(Printer* printer,
void PrintSimpleImplementation(Printer* printer, const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
- printer->Print("{\n");
- printer->Print(vars, " [[self RPCTo$method_name$With");
- if (method->client_streaming()) {
- printer->Print("RequestsWriter:requestWriter");
- } else {
- printer->Print("Request:request");
- }
- if (method->server_streaming()) {
- printer->Print(" eventHandler:eventHandler] start];\n");
- } else {
- printer->Print(" handler:handler] start];\n");
- }
- printer->Print("}\n");
-}
-
+ printer->Print("{\n");
+ printer->Print(vars, " [[self RPCTo$method_name$With");
+ if (method->client_streaming()) {
+ printer->Print("RequestsWriter:requestWriter");
+ } else {
+ printer->Print("Request:request");
+ }
+ if (method->server_streaming()) {
+ printer->Print(" eventHandler:eventHandler] start];\n");
+ } else {
+ printer->Print(" handler:handler] start];\n");
+ }
+ printer->Print("}\n");
+}
+
void PrintAdvancedImplementation(Printer* printer,
const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
- printer->Print("{\n");
- printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n");
-
- printer->Print(" requestsWriter:");
- if (method->client_streaming()) {
- printer->Print("requestWriter\n");
- } else {
- printer->Print("[GRXWriter writerWithValue:request]\n");
- }
-
- printer->Print(vars, " responseClass:[$response_class$ class]\n");
-
- printer->Print(" responsesWriteable:[GRXWriteable ");
- if (method->server_streaming()) {
- printer->Print("writeableWithEventHandler:eventHandler]];\n");
- } else {
- printer->Print("writeableWithSingleHandler:handler]];\n");
- }
-
- printer->Print("}\n");
-}
-
+ printer->Print("{\n");
+ printer->Print(vars, " return [self RPCToMethod:@\"$method_name$\"\n");
+
+ printer->Print(" requestsWriter:");
+ if (method->client_streaming()) {
+ printer->Print("requestWriter\n");
+ } else {
+ printer->Print("[GRXWriter writerWithValue:request]\n");
+ }
+
+ printer->Print(vars, " responseClass:[$response_class$ class]\n");
+
+ printer->Print(" responsesWriteable:[GRXWriteable ");
+ if (method->server_streaming()) {
+ printer->Print("writeableWithEventHandler:eventHandler]];\n");
+ } else {
+ printer->Print("writeableWithSingleHandler:handler]];\n");
+ }
+
+ printer->Print("}\n");
+}
+
void PrintV2Implementation(Printer* printer, const MethodDescriptor* method,
map< ::TString, ::TString> vars) {
printer->Print(" {\n");
@@ -240,14 +240,14 @@ void PrintMethodImplementations(Printer* printer,
const MethodDescriptor* method,
const Parameters& generator_params) {
map< ::TString, ::TString> vars = GetMethodVars(method);
-
- PrintProtoRpcDeclarationAsPragma(printer, method, vars);
-
+
+ PrintProtoRpcDeclarationAsPragma(printer, method, vars);
+
if (!generator_params.no_v1_compatibility) {
// TODO(jcanizales): Print documentation from the method.
PrintSimpleSignature(printer, method, vars);
PrintSimpleImplementation(printer, method, vars);
-
+
printer->Print("// Returns a not-yet-started RPC object.\n");
PrintAdvancedSignature(printer, method, vars);
PrintAdvancedImplementation(printer, method, vars);
@@ -255,10 +255,10 @@ void PrintMethodImplementations(Printer* printer,
PrintV2Signature(printer, method, vars);
PrintV2Implementation(printer, method, vars);
-}
-
-} // namespace
-
+}
+
+} // namespace
+
::TString GetAllMessageClasses(const FileDescriptor* file) {
::TString output;
set< ::TString> classes;
@@ -273,20 +273,20 @@ void PrintMethodImplementations(Printer* printer,
for (auto one_class : classes) {
output += "@class " + one_class + ";\n";
}
-
+
return output;
}
-
+
::TString GetProtocol(const ServiceDescriptor* service,
const Parameters& generator_params) {
::TString output;
-
+
if (generator_params.no_v1_compatibility) return output;
// Scope the output stream so it closes and finalizes output to the string.
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');
-
+
map< ::TString, ::TString> vars = {
{"service_class", ServiceClassName(service)}};
@@ -300,12 +300,12 @@ void PrintMethodImplementations(Printer* printer,
printer.Print(vars, "@protocol $service_class$ <NSObject>\n\n");
for (int i = 0; i < service->method_count(); i++) {
PrintMethodDeclarations(&printer, service->method(i));
- }
+ }
printer.Print("@end\n\n");
- return output;
-}
-
+ return output;
+}
+
::TString GetV2Protocol(const ServiceDescriptor* service) {
::TString output;
@@ -371,16 +371,16 @@ void PrintMethodImplementations(Printer* printer,
::TString GetSource(const ServiceDescriptor* service,
const Parameters& generator_params) {
::TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
- grpc::protobuf::io::StringOutputStream output_stream(&output);
- Printer printer(&output_stream, '$');
-
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+ grpc::protobuf::io::StringOutputStream output_stream(&output);
+ Printer printer(&output_stream, '$');
+
map< ::TString, ::TString> vars = {
- {"service_name", service->name()},
- {"service_class", ServiceClassName(service)},
- {"package", service->file()->package()}};
-
+ {"service_name", service->name()},
+ {"service_class", ServiceClassName(service)},
+ {"package", service->file()->package()}};
+
printer.Print(vars,
"@implementation $service_class$\n\n"
"#pragma clang diagnostic push\n"
@@ -403,7 +403,7 @@ void PrintMethodImplementations(Printer* printer,
"}\n\n");
}
printer.Print("#pragma clang diagnostic pop\n\n");
-
+
if (!generator_params.no_v1_compatibility) {
printer.Print(
"// Override superclass initializer to disallow different"
@@ -414,14 +414,14 @@ void PrintMethodImplementations(Printer* printer,
" return [self initWithHost:host];\n"
"}\n\n");
}
- printer.Print(
+ printer.Print(
"- (instancetype)initWithHost:(NSString *)host\n"
" packageName:(NSString *)packageName\n"
" serviceName:(NSString *)serviceName\n"
" callOptions:(GRPCCallOptions *)callOptions {\n"
" return [self initWithHost:host callOptions:callOptions];\n"
"}\n\n");
-
+
printer.Print("#pragma mark - Class Methods\n\n");
if (!generator_params.no_v1_compatibility) {
printer.Print(
@@ -437,14 +437,14 @@ void PrintMethodImplementations(Printer* printer,
printer.Print("#pragma mark - Method Implementations\n\n");
- for (int i = 0; i < service->method_count(); i++) {
+ for (int i = 0; i < service->method_count(); i++) {
PrintMethodImplementations(&printer, service->method(i),
generator_params);
- }
-
- printer.Print("@end\n");
- }
- return output;
-}
-
-} // namespace grpc_objective_c_generator
+ }
+
+ printer.Print("@end\n");
+ }
+ return output;
+}
+
+} // namespace grpc_objective_c_generator
diff --git a/contrib/libs/grpc/src/compiler/objective_c_generator.h b/contrib/libs/grpc/src/compiler/objective_c_generator.h
index 9770f65436d..0f3eb635669 100644
--- a/contrib/libs/grpc/src/compiler/objective_c_generator.h
+++ b/contrib/libs/grpc/src/compiler/objective_c_generator.h
@@ -1,40 +1,40 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_H
-#define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_H
-
-#include "src/compiler/config.h"
-
-namespace grpc_objective_c_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_H
+#define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_H
+
+#include "src/compiler/config.h"
+
+namespace grpc_objective_c_generator {
+
struct Parameters {
// Do not generate V1 interface and implementation
bool no_v1_compatibility;
};
using ::grpc::protobuf::FileDescriptor;
-using ::grpc::protobuf::ServiceDescriptor;
+using ::grpc::protobuf::ServiceDescriptor;
using ::TString;
-
+
// Returns forward declaration of classes in the generated header file.
string GetAllMessageClasses(const FileDescriptor* file);
-
+
// Returns the content to be included defining the @protocol segment at the
// insertion point of the generated implementation file. This interface is
// legacy and for backwards compatibility.
@@ -50,11 +50,11 @@ string GetV2Protocol(const ServiceDescriptor* service);
string GetInterface(const ServiceDescriptor* service,
const Parameters& generator_params);
-// Returns the content to be included in the "global_scope" insertion point of
-// the generated implementation file.
+// Returns the content to be included in the "global_scope" insertion point of
+// the generated implementation file.
string GetSource(const ServiceDescriptor* service,
const Parameters& generator_params);
-
-} // namespace grpc_objective_c_generator
-
-#endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_H
+
+} // namespace grpc_objective_c_generator
+
+#endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_H
diff --git a/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h b/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h
index ae296741cec..ee42afe62b6 100644
--- a/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h
+++ b/contrib/libs/grpc/src/compiler/objective_c_generator_helpers.h
@@ -1,49 +1,49 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
-#define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
-
-#include <map>
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
+#define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
+
+#include <map>
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
-namespace grpc_objective_c_generator {
-
-using ::grpc::protobuf::FileDescriptor;
-using ::grpc::protobuf::ServiceDescriptor;
+namespace grpc_objective_c_generator {
+
+using ::grpc::protobuf::FileDescriptor;
+using ::grpc::protobuf::ServiceDescriptor;
using ::TString;
-
+
inline string MessageHeaderName(const FileDescriptor* file) {
return google::protobuf::compiler::objectivec::FilePath(file) + ".pbobjc.h";
-}
-
+}
+
inline string ServiceClassName(const ServiceDescriptor* service) {
const FileDescriptor* file = service->file();
- string prefix = file->options().objc_class_prefix();
- return prefix + service->name();
-}
+ string prefix = file->options().objc_class_prefix();
+ return prefix + service->name();
+}
inline ::TString LocalImport(const ::TString& import) {
return ::TString("#import \"" + import + "\"\n");
-}
+}
inline ::TString FrameworkImport(const ::TString& import,
const ::TString& framework) {
@@ -91,4 +91,4 @@ inline ::TString PreprocIfNotElse(const ::TString& symbol,
}
} // namespace grpc_objective_c_generator
-#endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
+#endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
diff --git a/contrib/libs/grpc/src/compiler/php_generator.cc b/contrib/libs/grpc/src/compiler/php_generator.cc
index b35d3f2a02e..a4a5f5aa805 100644
--- a/contrib/libs/grpc/src/compiler/php_generator.cc
+++ b/contrib/libs/grpc/src/compiler/php_generator.cc
@@ -1,50 +1,50 @@
-/*
- *
+/*
+ *
* Copyright 2016 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <map>
-
+ *
+ */
+
+#include <map>
+
#include <google/protobuf/compiler/php/php_generator.h>
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-#include "src/compiler/php_generator_helpers.h"
-
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+#include "src/compiler/php_generator_helpers.h"
+
using google::protobuf::compiler::php::GeneratedClassName;
using grpc::protobuf::Descriptor;
-using grpc::protobuf::FileDescriptor;
+using grpc::protobuf::FileDescriptor;
using grpc::protobuf::MethodDescriptor;
-using grpc::protobuf::ServiceDescriptor;
-using grpc::protobuf::io::Printer;
-using grpc::protobuf::io::StringOutputStream;
-using std::map;
-
-namespace grpc_php_generator {
-namespace {
-
+using grpc::protobuf::ServiceDescriptor;
+using grpc::protobuf::io::Printer;
+using grpc::protobuf::io::StringOutputStream;
+using std::map;
+
+namespace grpc_php_generator {
+namespace {
+
TString ConvertToPhpNamespace(const TString& name) {
std::vector<TString> tokens = grpc_generator::tokenize(name, ".");
- std::ostringstream oss;
- for (unsigned int i = 0; i < tokens.size(); i++) {
- oss << (i == 0 ? "" : "\\")
- << grpc_generator::CapitalizeFirstLetter(tokens[i]);
- }
- return oss.str();
-}
-
+ std::ostringstream oss;
+ for (unsigned int i = 0; i < tokens.size(); i++) {
+ oss << (i == 0 ? "" : "\\")
+ << grpc_generator::CapitalizeFirstLetter(tokens[i]);
+ }
+ return oss.str();
+}
+
TString PackageName(const FileDescriptor* file) {
if (file->options().has_php_namespace()) {
return file->options().php_namespace();
@@ -68,70 +68,70 @@ void PrintMethod(const MethodDescriptor* method, Printer* out) {
const Descriptor* input_type = method->input_type();
const Descriptor* output_type = method->output_type();
map<TString, TString> vars;
- vars["service_name"] = method->service()->full_name();
- vars["name"] = method->name();
+ vars["service_name"] = method->service()->full_name();
+ vars["name"] = method->name();
vars["input_type_id"] =
MessageIdentifierName(GeneratedClassName(input_type), input_type->file());
vars["output_type_id"] = MessageIdentifierName(
GeneratedClassName(output_type), output_type->file());
-
- out->Print("/**\n");
- out->Print(GetPHPComments(method, " *").c_str());
- if (method->client_streaming()) {
+
+ out->Print("/**\n");
+ out->Print(GetPHPComments(method, " *").c_str());
+ if (method->client_streaming()) {
if (method->server_streaming()) {
vars["return_type_id"] = "\\Grpc\\BidiStreamingCall";
} else {
vars["return_type_id"] = "\\Grpc\\ClientStreamingCall";
}
- out->Print(vars,
- " * @param array $$metadata metadata\n"
+ out->Print(vars,
+ " * @param array $$metadata metadata\n"
" * @param array $$options call options\n"
" * @return $return_type_id$\n */\n"
- "public function $name$($$metadata = [], "
- "$$options = []) {\n");
- out->Indent();
+ "public function $name$($$metadata = [], "
+ "$$options = []) {\n");
+ out->Indent();
out->Indent();
- if (method->server_streaming()) {
- out->Print("return $$this->_bidiRequest(");
- } else {
- out->Print("return $$this->_clientStreamRequest(");
- }
- out->Print(vars,
- "'/$service_name$/$name$',\n"
- "['\\$output_type_id$','decode'],\n"
- "$$metadata, $$options);\n");
- } else {
+ if (method->server_streaming()) {
+ out->Print("return $$this->_bidiRequest(");
+ } else {
+ out->Print("return $$this->_clientStreamRequest(");
+ }
+ out->Print(vars,
+ "'/$service_name$/$name$',\n"
+ "['\\$output_type_id$','decode'],\n"
+ "$$metadata, $$options);\n");
+ } else {
if (method->server_streaming()) {
vars["return_type_id"] = "\\Grpc\\ServerStreamingCall";
} else {
vars["return_type_id"] = "\\Grpc\\UnaryCall";
}
- out->Print(vars,
- " * @param \\$input_type_id$ $$argument input argument\n"
- " * @param array $$metadata metadata\n"
+ out->Print(vars,
+ " * @param \\$input_type_id$ $$argument input argument\n"
+ " * @param array $$metadata metadata\n"
" * @param array $$options call options\n"
" * @return $return_type_id$\n */\n"
- "public function $name$(\\$input_type_id$ $$argument,\n"
- " $$metadata = [], $$options = []) {\n");
- out->Indent();
+ "public function $name$(\\$input_type_id$ $$argument,\n"
+ " $$metadata = [], $$options = []) {\n");
+ out->Indent();
out->Indent();
- if (method->server_streaming()) {
- out->Print("return $$this->_serverStreamRequest(");
- } else {
- out->Print("return $$this->_simpleRequest(");
- }
- out->Print(vars,
- "'/$service_name$/$name$',\n"
- "$$argument,\n"
- "['\\$output_type_id$', 'decode'],\n"
- "$$metadata, $$options);\n");
- }
- out->Outdent();
+ if (method->server_streaming()) {
+ out->Print("return $$this->_serverStreamRequest(");
+ } else {
+ out->Print("return $$this->_simpleRequest(");
+ }
+ out->Print(vars,
+ "'/$service_name$/$name$',\n"
+ "$$argument,\n"
+ "['\\$output_type_id$', 'decode'],\n"
+ "$$metadata, $$options);\n");
+ }
+ out->Outdent();
out->Outdent();
- out->Print("}\n\n");
-}
-
-// Prints out the service descriptor object
+ out->Print("}\n\n");
+}
+
+// Prints out the service descriptor object
void PrintService(const ServiceDescriptor* service,
const TString& class_suffix, Printer* out) {
map<TString, TString> vars;
@@ -140,57 +140,57 @@ void PrintService(const ServiceDescriptor* service,
out->Print(" */\n");
vars["name"] = GetPHPServiceClassname(service, class_suffix);
out->Print(vars, "class $name$ extends \\Grpc\\BaseStub {\n\n");
+ out->Indent();
out->Indent();
- out->Indent();
- out->Print(
- "/**\n * @param string $$hostname hostname\n"
- " * @param array $$opts channel options\n"
+ out->Print(
+ "/**\n * @param string $$hostname hostname\n"
+ " * @param array $$opts channel options\n"
" * @param \\Grpc\\Channel $$channel (optional) re-use channel "
- "object\n */\n"
- "public function __construct($$hostname, $$opts, "
- "$$channel = null) {\n");
- out->Indent();
+ "object\n */\n"
+ "public function __construct($$hostname, $$opts, "
+ "$$channel = null) {\n");
+ out->Indent();
out->Indent();
- out->Print("parent::__construct($$hostname, $$opts, $$channel);\n");
- out->Outdent();
+ out->Print("parent::__construct($$hostname, $$opts, $$channel);\n");
+ out->Outdent();
out->Outdent();
- out->Print("}\n\n");
- for (int i = 0; i < service->method_count(); i++) {
+ out->Print("}\n\n");
+ for (int i = 0; i < service->method_count(); i++) {
TString method_name =
- grpc_generator::LowercaseFirstLetter(service->method(i)->name());
- PrintMethod(service->method(i), out);
- }
- out->Outdent();
- out->Outdent();
- out->Print("}\n");
-}
+ grpc_generator::LowercaseFirstLetter(service->method(i)->name());
+ PrintMethod(service->method(i), out);
+ }
+ out->Outdent();
+ out->Outdent();
+ out->Print("}\n");
+}
} // namespace
-
+
TString GenerateFile(const FileDescriptor* file,
const ServiceDescriptor* service,
const TString& class_suffix) {
TString output;
- {
- StringOutputStream output_stream(&output);
- Printer out(&output_stream, '$');
-
- out.Print("<?php\n");
- out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
-
+ {
+ StringOutputStream output_stream(&output);
+ Printer out(&output_stream, '$');
+
+ out.Print("<?php\n");
+ out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
+
TString leading_comments = GetPHPComments(file, "//");
- if (!leading_comments.empty()) {
- out.Print("// Original file comments:\n");
+ if (!leading_comments.empty()) {
+ out.Print("// Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
- }
-
+ }
+
map<TString, TString> vars;
TString php_namespace = PackageName(file);
vars["package"] = php_namespace;
out.Print(vars, "namespace $package$;\n\n");
PrintService(service, class_suffix, &out);
- }
- return output;
-}
-
-} // namespace grpc_php_generator
+ }
+ return output;
+}
+
+} // namespace grpc_php_generator
diff --git a/contrib/libs/grpc/src/compiler/php_generator_helpers.h b/contrib/libs/grpc/src/compiler/php_generator_helpers.h
index 70a31eaf75e..ba642e2ecdd 100644
--- a/contrib/libs/grpc/src/compiler/php_generator_helpers.h
+++ b/contrib/libs/grpc/src/compiler/php_generator_helpers.h
@@ -1,37 +1,37 @@
-/*
- *
+/*
+ *
* Copyright 2016 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
-#define GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
-
-#include <algorithm>
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-
-namespace grpc_php_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
+#define GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
+
+#include <algorithm>
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+
+namespace grpc_php_generator {
+
inline TString GetPHPServiceClassname(
const grpc::protobuf::ServiceDescriptor* service,
const TString& class_suffix) {
return service->name() + (class_suffix == "" ? "Client" : class_suffix);
-}
-
+}
+
// ReplaceAll replaces all instances of search with replace in s.
inline TString ReplaceAll(TString s, const TString& search,
const TString& replace) {
@@ -62,15 +62,15 @@ inline TString GetPHPServiceFilename(
".php";
}
-// Get leading or trailing comments in a string. Comment lines start with "// ".
+// Get leading or trailing comments in a string. Comment lines start with "// ".
// Leading detached comments are put in front of leading comments.
-template <typename DescriptorType>
+template <typename DescriptorType>
inline TString GetPHPComments(const DescriptorType* desc,
TString prefix) {
return ReplaceAll(grpc_generator::GetPrefixedComments(desc, true, prefix),
"*/", "&#42;/");
-}
-
-} // namespace grpc_php_generator
-
-#endif // GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
+}
+
+} // namespace grpc_php_generator
+
+#endif // GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H
diff --git a/contrib/libs/grpc/src/compiler/python_generator.cc b/contrib/libs/grpc/src/compiler/python_generator.cc
index d083d19f0b3..31fe39dbf75 100644
--- a/contrib/libs/grpc/src/compiler/python_generator.cc
+++ b/contrib/libs/grpc/src/compiler/python_generator.cc
@@ -1,97 +1,97 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <algorithm>
-#include <cassert>
-#include <cctype>
-#include <cstring>
-#include <fstream>
-#include <iostream>
-#include <map>
-#include <memory>
-#include <ostream>
-#include <set>
-#include <sstream>
-#include <tuple>
-#include <vector>
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
+ *
+ */
+
+#include <algorithm>
+#include <cassert>
+#include <cctype>
+#include <cstring>
+#include <fstream>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <ostream>
+#include <set>
+#include <sstream>
+#include <tuple>
+#include <vector>
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
#include "src/compiler/protobuf_plugin.h"
-#include "src/compiler/python_generator.h"
+#include "src/compiler/python_generator.h"
#include "src/compiler/python_generator_helpers.h"
#include "src/compiler/python_private_generator.h"
-
-using grpc::protobuf::FileDescriptor;
-using grpc::protobuf::compiler::GeneratorContext;
-using grpc::protobuf::io::CodedOutputStream;
-using grpc::protobuf::io::ZeroCopyOutputStream;
-using std::make_pair;
-using std::map;
-using std::pair;
-using std::replace;
+
+using grpc::protobuf::FileDescriptor;
+using grpc::protobuf::compiler::GeneratorContext;
+using grpc::protobuf::io::CodedOutputStream;
+using grpc::protobuf::io::ZeroCopyOutputStream;
+using std::make_pair;
+using std::map;
+using std::pair;
+using std::replace;
using std::set;
-using std::tuple;
-using std::vector;
-
-namespace grpc_python_generator {
-
+using std::tuple;
+using std::vector;
+
+namespace grpc_python_generator {
+
TString generator_file_name;
-namespace {
-
+namespace {
+
typedef map<TString, TString> StringMap;
typedef vector<TString> StringVector;
typedef tuple<TString, TString> StringPair;
-typedef set<StringPair> StringPairSet;
-
-// Provides RAII indentation handling. Use as:
-// {
-// IndentScope raii_my_indent_var_name_here(my_py_printer);
-// // constructor indented my_py_printer
-// ...
-// // destructor called at end of scope, un-indenting my_py_printer
-// }
-class IndentScope {
- public:
+typedef set<StringPair> StringPairSet;
+
+// Provides RAII indentation handling. Use as:
+// {
+// IndentScope raii_my_indent_var_name_here(my_py_printer);
+// // constructor indented my_py_printer
+// ...
+// // destructor called at end of scope, un-indenting my_py_printer
+// }
+class IndentScope {
+ public:
explicit IndentScope(grpc_generator::Printer* printer) : printer_(printer) {
// NOTE(rbellevi): Two-space tabs are hard-coded in the protocol compiler.
// Doubling our indents and outdents guarantees compliance with PEP8.
+ printer_->Indent();
printer_->Indent();
- printer_->Indent();
- }
-
+ }
+
~IndentScope() {
printer_->Outdent();
printer_->Outdent();
}
-
- private:
+
+ private:
grpc_generator::Printer* printer_;
-};
-
-PrivateGenerator::PrivateGenerator(const GeneratorConfiguration& config,
+};
+
+PrivateGenerator::PrivateGenerator(const GeneratorConfiguration& config,
const grpc_generator::File* file)
- : config(config), file(file) {}
-
+ : config(config), file(file) {}
+
void PrivateGenerator::PrintAllComments(StringVector comments,
grpc_generator::Printer* out) {
- if (comments.empty()) {
+ if (comments.empty()) {
// Python requires code structures like class and def to have
// a body, even if it is just "pass" or a docstring. We need
// to ensure not to generate empty bodies. We could do something
@@ -101,38 +101,38 @@ void PrivateGenerator::PrintAllComments(StringVector comments,
out->Print(
"\"\"\"Missing associated documentation comment in .proto "
"file.\"\"\"\n");
- return;
- }
- out->Print("\"\"\"");
- for (StringVector::iterator it = comments.begin(); it != comments.end();
- ++it) {
- size_t start_pos = it->find_first_not_of(' ');
+ return;
+ }
+ out->Print("\"\"\"");
+ for (StringVector::iterator it = comments.begin(); it != comments.end();
+ ++it) {
+ size_t start_pos = it->find_first_not_of(' ');
if (start_pos != TString::npos) {
out->PrintRaw(it->c_str() + start_pos);
- }
- out->Print("\n");
- }
- out->Print("\"\"\"\n");
-}
-
+ }
+ out->Print("\n");
+ }
+ out->Print("\"\"\"\n");
+}
+
bool PrivateGenerator::PrintBetaServicer(const grpc_generator::Service* service,
grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
- out->Print("\n\n");
+ out->Print("\n\n");
out->Print(service_dict, "class Beta$Service$Servicer(object):\n");
- {
- IndentScope raii_class_indent(out);
- out->Print(
- "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
- "\nIt is recommended to use the GA API (classes and functions in this\n"
- "file not marked beta) for all further purposes. This class was "
- "generated\n"
- "only to ease transition from grpcio<0.15.0 to "
- "grpcio>=0.15.0.\"\"\"\n");
+ {
+ IndentScope raii_class_indent(out);
+ out->Print(
+ "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
+ "\nIt is recommended to use the GA API (classes and functions in this\n"
+ "file not marked beta) for all further purposes. This class was "
+ "generated\n"
+ "only to ease transition from grpcio<0.15.0 to "
+ "grpcio>=0.15.0.\"\"\"\n");
StringVector service_comments = service->GetAllComments();
PrintAllComments(service_comments, out);
- for (int i = 0; i < service->method_count(); ++i) {
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
TString arg_name =
method->ClientStreaming() ? "request_iterator" : "request";
@@ -140,188 +140,188 @@ bool PrivateGenerator::PrintBetaServicer(const grpc_generator::Service* service,
method_dict["Method"] = method->name();
method_dict["ArgName"] = arg_name;
out->Print(method_dict, "def $Method$(self, $ArgName$, context):\n");
- {
- IndentScope raii_method_indent(out);
+ {
+ IndentScope raii_method_indent(out);
StringVector method_comments = method->GetAllComments();
PrintAllComments(method_comments, out);
- out->Print("context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)\n");
- }
- }
- }
- return true;
-}
-
+ out->Print("context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)\n");
+ }
+ }
+ }
+ return true;
+}
+
bool PrivateGenerator::PrintBetaStub(const grpc_generator::Service* service,
grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
- out->Print("\n\n");
+ out->Print("\n\n");
out->Print(service_dict, "class Beta$Service$Stub(object):\n");
- {
- IndentScope raii_class_indent(out);
- out->Print(
- "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
- "\nIt is recommended to use the GA API (classes and functions in this\n"
- "file not marked beta) for all further purposes. This class was "
- "generated\n"
- "only to ease transition from grpcio<0.15.0 to "
- "grpcio>=0.15.0.\"\"\"\n");
+ {
+ IndentScope raii_class_indent(out);
+ out->Print(
+ "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
+ "\nIt is recommended to use the GA API (classes and functions in this\n"
+ "file not marked beta) for all further purposes. This class was "
+ "generated\n"
+ "only to ease transition from grpcio<0.15.0 to "
+ "grpcio>=0.15.0.\"\"\"\n");
StringVector service_comments = service->GetAllComments();
PrintAllComments(service_comments, out);
- for (int i = 0; i < service->method_count(); ++i) {
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
TString arg_name =
method->ClientStreaming() ? "request_iterator" : "request";
- StringMap method_dict;
- method_dict["Method"] = method->name();
- method_dict["ArgName"] = arg_name;
- out->Print(method_dict,
- "def $Method$(self, $ArgName$, timeout, metadata=None, "
- "with_call=False, protocol_options=None):\n");
- {
- IndentScope raii_method_indent(out);
+ StringMap method_dict;
+ method_dict["Method"] = method->name();
+ method_dict["ArgName"] = arg_name;
+ out->Print(method_dict,
+ "def $Method$(self, $ArgName$, timeout, metadata=None, "
+ "with_call=False, protocol_options=None):\n");
+ {
+ IndentScope raii_method_indent(out);
StringVector method_comments = method->GetAllComments();
PrintAllComments(method_comments, out);
- out->Print("raise NotImplementedError()\n");
- }
+ out->Print("raise NotImplementedError()\n");
+ }
if (!method->ServerStreaming()) {
- out->Print(method_dict, "$Method$.future = None\n");
- }
- }
- }
- return true;
-}
-
-bool PrivateGenerator::PrintBetaServerFactory(
+ out->Print(method_dict, "$Method$.future = None\n");
+ }
+ }
+ }
+ return true;
+}
+
+bool PrivateGenerator::PrintBetaServerFactory(
const TString& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
- out->Print("\n\n");
+ out->Print("\n\n");
out->Print(service_dict,
"def beta_create_$Service$_server(servicer, pool=None, "
"pool_size=None, default_timeout=None, maximum_timeout=None):\n");
- {
- IndentScope raii_create_server_indent(out);
- out->Print(
- "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
- "\nIt is recommended to use the GA API (classes and functions in this\n"
- "file not marked beta) for all further purposes. This function was\n"
- "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"
- "\"\"\"\n");
- StringMap method_implementation_constructors;
- StringMap input_message_modules_and_classes;
- StringMap output_message_modules_and_classes;
- for (int i = 0; i < service->method_count(); ++i) {
+ {
+ IndentScope raii_create_server_indent(out);
+ out->Print(
+ "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
+ "\nIt is recommended to use the GA API (classes and functions in this\n"
+ "file not marked beta) for all further purposes. This function was\n"
+ "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"
+ "\"\"\"\n");
+ StringMap method_implementation_constructors;
+ StringMap input_message_modules_and_classes;
+ StringMap output_message_modules_and_classes;
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
const TString method_implementation_constructor =
TString(method->ClientStreaming() ? "stream_" : "unary_") +
TString(method->ServerStreaming() ? "stream_" : "unary_") +
- "inline";
+ "inline";
TString input_message_module_and_class;
if (!method->get_module_and_message_path_input(
&input_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
+ return false;
+ }
TString output_message_module_and_class;
if (!method->get_module_and_message_path_output(
&output_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
- method_implementation_constructors.insert(
- make_pair(method->name(), method_implementation_constructor));
- input_message_modules_and_classes.insert(
- make_pair(method->name(), input_message_module_and_class));
- output_message_modules_and_classes.insert(
- make_pair(method->name(), output_message_module_and_class));
- }
+ return false;
+ }
+ method_implementation_constructors.insert(
+ make_pair(method->name(), method_implementation_constructor));
+ input_message_modules_and_classes.insert(
+ make_pair(method->name(), input_message_module_and_class));
+ output_message_modules_and_classes.insert(
+ make_pair(method->name(), output_message_module_and_class));
+ }
StringMap method_dict;
method_dict["PackageQualifiedServiceName"] = package_qualified_service_name;
- out->Print("request_deserializers = {\n");
- for (StringMap::iterator name_and_input_module_class_pair =
- input_message_modules_and_classes.begin();
- name_and_input_module_class_pair !=
- input_message_modules_and_classes.end();
- name_and_input_module_class_pair++) {
+ out->Print("request_deserializers = {\n");
+ for (StringMap::iterator name_and_input_module_class_pair =
+ input_message_modules_and_classes.begin();
+ name_and_input_module_class_pair !=
+ input_message_modules_and_classes.end();
+ name_and_input_module_class_pair++) {
method_dict["MethodName"] = name_and_input_module_class_pair->first;
method_dict["InputTypeModuleAndClass"] =
name_and_input_module_class_pair->second;
- IndentScope raii_indent(out);
+ IndentScope raii_indent(out);
out->Print(method_dict,
"(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
"$InputTypeModuleAndClass$.FromString,\n");
- }
- out->Print("}\n");
- out->Print("response_serializers = {\n");
- for (StringMap::iterator name_and_output_module_class_pair =
- output_message_modules_and_classes.begin();
- name_and_output_module_class_pair !=
- output_message_modules_and_classes.end();
- name_and_output_module_class_pair++) {
+ }
+ out->Print("}\n");
+ out->Print("response_serializers = {\n");
+ for (StringMap::iterator name_and_output_module_class_pair =
+ output_message_modules_and_classes.begin();
+ name_and_output_module_class_pair !=
+ output_message_modules_and_classes.end();
+ name_and_output_module_class_pair++) {
method_dict["MethodName"] = name_and_output_module_class_pair->first;
method_dict["OutputTypeModuleAndClass"] =
name_and_output_module_class_pair->second;
- IndentScope raii_indent(out);
+ IndentScope raii_indent(out);
out->Print(method_dict,
"(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
"$OutputTypeModuleAndClass$.SerializeToString,\n");
- }
- out->Print("}\n");
- out->Print("method_implementations = {\n");
- for (StringMap::iterator name_and_implementation_constructor =
- method_implementation_constructors.begin();
- name_and_implementation_constructor !=
- method_implementation_constructors.end();
- name_and_implementation_constructor++) {
+ }
+ out->Print("}\n");
+ out->Print("method_implementations = {\n");
+ for (StringMap::iterator name_and_implementation_constructor =
+ method_implementation_constructors.begin();
+ name_and_implementation_constructor !=
+ method_implementation_constructors.end();
+ name_and_implementation_constructor++) {
method_dict["Method"] = name_and_implementation_constructor->first;
method_dict["Constructor"] = name_and_implementation_constructor->second;
- IndentScope raii_descriptions_indent(out);
+ IndentScope raii_descriptions_indent(out);
const TString method_name =
- name_and_implementation_constructor->first;
+ name_and_implementation_constructor->first;
out->Print(method_dict,
"(\'$PackageQualifiedServiceName$\', \'$Method$\'): "
"face_utilities.$Constructor$(servicer.$Method$),\n");
- }
- out->Print("}\n");
- out->Print(
- "server_options = beta_implementations.server_options("
- "request_deserializers=request_deserializers, "
- "response_serializers=response_serializers, "
- "thread_pool=pool, thread_pool_size=pool_size, "
- "default_timeout=default_timeout, "
- "maximum_timeout=maximum_timeout)\n");
- out->Print(
- "return beta_implementations.server(method_implementations, "
- "options=server_options)\n");
- }
- return true;
-}
-
-bool PrivateGenerator::PrintBetaStubFactory(
+ }
+ out->Print("}\n");
+ out->Print(
+ "server_options = beta_implementations.server_options("
+ "request_deserializers=request_deserializers, "
+ "response_serializers=response_serializers, "
+ "thread_pool=pool, thread_pool_size=pool_size, "
+ "default_timeout=default_timeout, "
+ "maximum_timeout=maximum_timeout)\n");
+ out->Print(
+ "return beta_implementations.server(method_implementations, "
+ "options=server_options)\n");
+ }
+ return true;
+}
+
+bool PrivateGenerator::PrintBetaStubFactory(
const TString& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
- StringMap dict;
- dict["Service"] = service->name();
- out->Print("\n\n");
- out->Print(dict,
- "def beta_create_$Service$_stub(channel, host=None,"
- " metadata_transformer=None, pool=None, pool_size=None):\n");
- {
- IndentScope raii_create_server_indent(out);
- out->Print(
- "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
- "\nIt is recommended to use the GA API (classes and functions in this\n"
- "file not marked beta) for all further purposes. This function was\n"
- "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"
- "\"\"\"\n");
- StringMap method_cardinalities;
- StringMap input_message_modules_and_classes;
- StringMap output_message_modules_and_classes;
- for (int i = 0; i < service->method_count(); ++i) {
+ StringMap dict;
+ dict["Service"] = service->name();
+ out->Print("\n\n");
+ out->Print(dict,
+ "def beta_create_$Service$_stub(channel, host=None,"
+ " metadata_transformer=None, pool=None, pool_size=None):\n");
+ {
+ IndentScope raii_create_server_indent(out);
+ out->Print(
+ "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n"
+ "\nIt is recommended to use the GA API (classes and functions in this\n"
+ "file not marked beta) for all further purposes. This function was\n"
+ "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"
+ "\"\"\"\n");
+ StringMap method_cardinalities;
+ StringMap input_message_modules_and_classes;
+ StringMap output_message_modules_and_classes;
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
const TString method_cardinality =
TString(method->ClientStreaming() ? "STREAM" : "UNARY") + "_" +
@@ -331,104 +331,104 @@ bool PrivateGenerator::PrintBetaStubFactory(
&input_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
+ return false;
+ }
TString output_message_module_and_class;
if (!method->get_module_and_message_path_output(
&output_message_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
- method_cardinalities.insert(
- make_pair(method->name(), method_cardinality));
- input_message_modules_and_classes.insert(
- make_pair(method->name(), input_message_module_and_class));
- output_message_modules_and_classes.insert(
- make_pair(method->name(), output_message_module_and_class));
- }
+ return false;
+ }
+ method_cardinalities.insert(
+ make_pair(method->name(), method_cardinality));
+ input_message_modules_and_classes.insert(
+ make_pair(method->name(), input_message_module_and_class));
+ output_message_modules_and_classes.insert(
+ make_pair(method->name(), output_message_module_and_class));
+ }
StringMap method_dict;
method_dict["PackageQualifiedServiceName"] = package_qualified_service_name;
- out->Print("request_serializers = {\n");
- for (StringMap::iterator name_and_input_module_class_pair =
- input_message_modules_and_classes.begin();
- name_and_input_module_class_pair !=
- input_message_modules_and_classes.end();
- name_and_input_module_class_pair++) {
+ out->Print("request_serializers = {\n");
+ for (StringMap::iterator name_and_input_module_class_pair =
+ input_message_modules_and_classes.begin();
+ name_and_input_module_class_pair !=
+ input_message_modules_and_classes.end();
+ name_and_input_module_class_pair++) {
method_dict["MethodName"] = name_and_input_module_class_pair->first;
method_dict["InputTypeModuleAndClass"] =
name_and_input_module_class_pair->second;
- IndentScope raii_indent(out);
+ IndentScope raii_indent(out);
out->Print(method_dict,
"(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
"$InputTypeModuleAndClass$.SerializeToString,\n");
- }
- out->Print("}\n");
- out->Print("response_deserializers = {\n");
- for (StringMap::iterator name_and_output_module_class_pair =
- output_message_modules_and_classes.begin();
- name_and_output_module_class_pair !=
- output_message_modules_and_classes.end();
- name_and_output_module_class_pair++) {
+ }
+ out->Print("}\n");
+ out->Print("response_deserializers = {\n");
+ for (StringMap::iterator name_and_output_module_class_pair =
+ output_message_modules_and_classes.begin();
+ name_and_output_module_class_pair !=
+ output_message_modules_and_classes.end();
+ name_and_output_module_class_pair++) {
method_dict["MethodName"] = name_and_output_module_class_pair->first;
method_dict["OutputTypeModuleAndClass"] =
name_and_output_module_class_pair->second;
- IndentScope raii_indent(out);
+ IndentScope raii_indent(out);
out->Print(method_dict,
"(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
"$OutputTypeModuleAndClass$.FromString,\n");
- }
- out->Print("}\n");
- out->Print("cardinalities = {\n");
- for (StringMap::iterator name_and_cardinality =
- method_cardinalities.begin();
- name_and_cardinality != method_cardinalities.end();
- name_and_cardinality++) {
+ }
+ out->Print("}\n");
+ out->Print("cardinalities = {\n");
+ for (StringMap::iterator name_and_cardinality =
+ method_cardinalities.begin();
+ name_and_cardinality != method_cardinalities.end();
+ name_and_cardinality++) {
method_dict["Method"] = name_and_cardinality->first;
method_dict["Cardinality"] = name_and_cardinality->second;
- IndentScope raii_descriptions_indent(out);
+ IndentScope raii_descriptions_indent(out);
out->Print(method_dict,
"\'$Method$\': cardinality.Cardinality.$Cardinality$,\n");
- }
- out->Print("}\n");
- out->Print(
- "stub_options = beta_implementations.stub_options("
- "host=host, metadata_transformer=metadata_transformer, "
- "request_serializers=request_serializers, "
- "response_deserializers=response_deserializers, "
- "thread_pool=pool, thread_pool_size=pool_size)\n");
+ }
+ out->Print("}\n");
+ out->Print(
+ "stub_options = beta_implementations.stub_options("
+ "host=host, metadata_transformer=metadata_transformer, "
+ "request_serializers=request_serializers, "
+ "response_deserializers=response_deserializers, "
+ "thread_pool=pool, thread_pool_size=pool_size)\n");
out->Print(method_dict,
"return beta_implementations.dynamic_stub(channel, "
"\'$PackageQualifiedServiceName$\', "
"cardinalities, options=stub_options)\n");
- }
- return true;
-}
-
-bool PrivateGenerator::PrintStub(
+ }
+ return true;
+}
+
+bool PrivateGenerator::PrintStub(
const TString& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap dict;
dict["Service"] = service->name();
- out->Print("\n\n");
+ out->Print("\n\n");
out->Print(dict, "class $Service$Stub(object):\n");
- {
- IndentScope raii_class_indent(out);
+ {
+ IndentScope raii_class_indent(out);
StringVector service_comments = service->GetAllComments();
PrintAllComments(service_comments, out);
- out->Print("\n");
- out->Print("def __init__(self, channel):\n");
- {
- IndentScope raii_init_indent(out);
- out->Print("\"\"\"Constructor.\n");
- out->Print("\n");
- out->Print("Args:\n");
- {
- IndentScope raii_args_indent(out);
- out->Print("channel: A grpc.Channel.\n");
- }
- out->Print("\"\"\"\n");
- for (int i = 0; i < service->method_count(); ++i) {
+ out->Print("\n");
+ out->Print("def __init__(self, channel):\n");
+ {
+ IndentScope raii_init_indent(out);
+ out->Print("\"\"\"Constructor.\n");
+ out->Print("\n");
+ out->Print("Args:\n");
+ {
+ IndentScope raii_args_indent(out);
+ out->Print("channel: A grpc.Channel.\n");
+ }
+ out->Print("\"\"\"\n");
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
TString multi_callable_constructor =
TString(method->ClientStreaming() ? "stream" : "unary") + "_" +
@@ -438,108 +438,108 @@ bool PrivateGenerator::PrintStub(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
+ return false;
+ }
TString response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
+ return false;
+ }
StringMap method_dict;
method_dict["Method"] = method->name();
method_dict["MultiCallableConstructor"] = multi_callable_constructor;
out->Print(method_dict,
"self.$Method$ = channel.$MultiCallableConstructor$(\n");
- {
+ {
method_dict["PackageQualifiedService"] =
package_qualified_service_name;
method_dict["RequestModuleAndClass"] = request_module_and_class;
method_dict["ResponseModuleAndClass"] = response_module_and_class;
- IndentScope raii_first_attribute_indent(out);
- IndentScope raii_second_attribute_indent(out);
+ IndentScope raii_first_attribute_indent(out);
+ IndentScope raii_second_attribute_indent(out);
out->Print(method_dict, "'/$PackageQualifiedService$/$Method$',\n");
out->Print(method_dict,
"request_serializer=$RequestModuleAndClass$."
"SerializeToString,\n");
- out->Print(
+ out->Print(
method_dict,
"response_deserializer=$ResponseModuleAndClass$.FromString,\n");
- out->Print(")\n");
- }
- }
- }
- }
- return true;
-}
-
+ out->Print(")\n");
+ }
+ }
+ }
+ }
+ return true;
+}
+
bool PrivateGenerator::PrintServicer(const grpc_generator::Service* service,
grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
- out->Print("\n\n");
+ out->Print("\n\n");
out->Print(service_dict, "class $Service$Servicer(object):\n");
- {
- IndentScope raii_class_indent(out);
+ {
+ IndentScope raii_class_indent(out);
StringVector service_comments = service->GetAllComments();
PrintAllComments(service_comments, out);
- for (int i = 0; i < service->method_count(); ++i) {
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
TString arg_name =
method->ClientStreaming() ? "request_iterator" : "request";
StringMap method_dict;
method_dict["Method"] = method->name();
method_dict["ArgName"] = arg_name;
- out->Print("\n");
+ out->Print("\n");
out->Print(method_dict, "def $Method$(self, $ArgName$, context):\n");
- {
- IndentScope raii_method_indent(out);
+ {
+ IndentScope raii_method_indent(out);
StringVector method_comments = method->GetAllComments();
PrintAllComments(method_comments, out);
- out->Print("context.set_code(grpc.StatusCode.UNIMPLEMENTED)\n");
- out->Print("context.set_details('Method not implemented!')\n");
- out->Print("raise NotImplementedError('Method not implemented!')\n");
- }
- }
- }
- return true;
-}
-
-bool PrivateGenerator::PrintAddServicerToServer(
+ out->Print("context.set_code(grpc.StatusCode.UNIMPLEMENTED)\n");
+ out->Print("context.set_details('Method not implemented!')\n");
+ out->Print("raise NotImplementedError('Method not implemented!')\n");
+ }
+ }
+ }
+ return true;
+}
+
+bool PrivateGenerator::PrintAddServicerToServer(
const TString& package_qualified_service_name,
const grpc_generator::Service* service, grpc_generator::Printer* out) {
StringMap service_dict;
service_dict["Service"] = service->name();
- out->Print("\n\n");
+ out->Print("\n\n");
out->Print(service_dict,
"def add_$Service$Servicer_to_server(servicer, server):\n");
- {
- IndentScope raii_class_indent(out);
- out->Print("rpc_method_handlers = {\n");
- {
- IndentScope raii_dict_first_indent(out);
- IndentScope raii_dict_second_indent(out);
- for (int i = 0; i < service->method_count(); ++i) {
+ {
+ IndentScope raii_class_indent(out);
+ out->Print("rpc_method_handlers = {\n");
+ {
+ IndentScope raii_dict_first_indent(out);
+ IndentScope raii_dict_second_indent(out);
+ for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i);
TString method_handler_constructor =
TString(method->ClientStreaming() ? "stream" : "unary") + "_" +
TString(method->ServerStreaming() ? "stream" : "unary") +
- "_rpc_method_handler";
+ "_rpc_method_handler";
TString request_module_and_class;
if (!method->get_module_and_message_path_input(
&request_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
+ return false;
+ }
TString response_module_and_class;
if (!method->get_module_and_message_path_output(
&response_module_and_class, generator_file_name,
generate_in_pb2_grpc, config.import_prefix,
config.prefixes_to_filter)) {
- return false;
- }
+ return false;
+ }
StringMap method_dict;
method_dict["Method"] = method->name();
method_dict["MethodHandlerConstructor"] = method_handler_constructor;
@@ -547,36 +547,36 @@ bool PrivateGenerator::PrintAddServicerToServer(
method_dict["ResponseModuleAndClass"] = response_module_and_class;
out->Print(method_dict,
"'$Method$': grpc.$MethodHandlerConstructor$(\n");
- {
- IndentScope raii_call_first_indent(out);
- IndentScope raii_call_second_indent(out);
+ {
+ IndentScope raii_call_first_indent(out);
+ IndentScope raii_call_second_indent(out);
out->Print(method_dict, "servicer.$Method$,\n");
- out->Print(
+ out->Print(
method_dict,
"request_deserializer=$RequestModuleAndClass$.FromString,\n");
- out->Print(
+ out->Print(
method_dict,
- "response_serializer=$ResponseModuleAndClass$.SerializeToString,"
+ "response_serializer=$ResponseModuleAndClass$.SerializeToString,"
"\n");
- }
- out->Print("),\n");
- }
- }
+ }
+ out->Print("),\n");
+ }
+ }
StringMap method_dict;
method_dict["PackageQualifiedServiceName"] = package_qualified_service_name;
- out->Print("}\n");
- out->Print("generic_handler = grpc.method_handlers_generic_handler(\n");
- {
- IndentScope raii_call_first_indent(out);
- IndentScope raii_call_second_indent(out);
+ out->Print("}\n");
+ out->Print("generic_handler = grpc.method_handlers_generic_handler(\n");
+ {
+ IndentScope raii_call_first_indent(out);
+ IndentScope raii_call_second_indent(out);
out->Print(method_dict,
"'$PackageQualifiedServiceName$', rpc_method_handlers)\n");
- }
- out->Print("server.add_generic_rpc_handlers((generic_handler,))\n");
- }
- return true;
-}
-
+ }
+ out->Print("server.add_generic_rpc_handlers((generic_handler,))\n");
+ }
+ return true;
+}
+
/* Prints out a service class used as a container for static methods pertaining
* to a class. This class has the exact name of service written in the ".proto"
* file, with no suffixes. Since this class merely acts as a namespace, it
@@ -671,10 +671,10 @@ bool PrivateGenerator::PrintBetaPreamble(grpc_generator::Printer* out) {
out->Print(var,
"from $Package$ import implementations as beta_implementations\n");
out->Print(var, "from $Package$ import interfaces as beta_interfaces\n");
- out->Print("from grpc.framework.common import cardinality\n");
- out->Print(
- "from grpc.framework.interfaces.face import utilities as "
- "face_utilities\n");
+ out->Print("from grpc.framework.common import cardinality\n");
+ out->Print(
+ "from grpc.framework.interfaces.face import utilities as "
+ "face_utilities\n");
return true;
}
@@ -682,12 +682,12 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
StringMap var;
var["Package"] = config.grpc_package_root;
out->Print(var, "import $Package$\n");
- if (generate_in_pb2_grpc) {
- out->Print("\n");
- StringPairSet imports_set;
- for (int i = 0; i < file->service_count(); ++i) {
+ if (generate_in_pb2_grpc) {
+ out->Print("\n");
+ StringPairSet imports_set;
+ for (int i = 0; i < file->service_count(); ++i) {
auto service = file->service(i);
- for (int j = 0; j < service->method_count(); ++j) {
+ for (int j = 0; j < service->method_count(); ++j) {
auto method = service.get()->method(j);
TString input_type_file_name = method->get_input_type_name();
@@ -709,11 +709,11 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
config.prefixes_to_filter);
imports_set.insert(
std::make_tuple(output_module_name, output_module_alias));
- }
- }
+ }
+ }
- for (StringPairSet::iterator it = imports_set.begin();
- it != imports_set.end(); ++it) {
+ for (StringPairSet::iterator it = imports_set.begin();
+ it != imports_set.end(); ++it) {
auto module_name = std::get<0>(*it);
var["ModuleAlias"] = std::get<1>(*it);
const size_t last_dot_pos = module_name.rfind('.');
@@ -725,17 +725,17 @@ bool PrivateGenerator::PrintPreamble(grpc_generator::Printer* out) {
module_name.substr(last_dot_pos + 1);
}
out->Print(var, "$ImportStatement$ as $ModuleAlias$\n");
- }
- }
- return true;
-}
-
+ }
+ }
+ return true;
+}
+
bool PrivateGenerator::PrintGAServices(grpc_generator::Printer* out) {
TString package = file->package();
- if (!package.empty()) {
- package = package.append(".");
- }
- for (int i = 0; i < file->service_count(); ++i) {
+ if (!package.empty()) {
+ package = package.append(".");
+ }
+ for (int i = 0; i < file->service_count(); ++i) {
auto service = file->service(i);
TString package_qualified_service_name = package + service->name();
if (!(PrintStub(package_qualified_service_name, service.get(), out) &&
@@ -744,18 +744,18 @@ bool PrivateGenerator::PrintGAServices(grpc_generator::Printer* out) {
service.get(), out) &&
PrintServiceClass(package_qualified_service_name, service.get(),
out))) {
- return false;
- }
- }
- return true;
-}
-
+ return false;
+ }
+ }
+ return true;
+}
+
bool PrivateGenerator::PrintBetaServices(grpc_generator::Printer* out) {
TString package = file->package();
- if (!package.empty()) {
- package = package.append(".");
- }
- for (int i = 0; i < file->service_count(); ++i) {
+ if (!package.empty()) {
+ package = package.append(".");
+ }
+ for (int i = 0; i < file->service_count(); ++i) {
auto service = file->service(i);
TString package_qualified_service_name = package + service->name();
if (!(PrintBetaServicer(service.get(), out) &&
@@ -764,97 +764,97 @@ bool PrivateGenerator::PrintBetaServices(grpc_generator::Printer* out) {
out) &&
PrintBetaStubFactory(package_qualified_service_name, service.get(),
out))) {
- return false;
- }
- }
- return true;
-}
-
+ return false;
+ }
+ }
+ return true;
+}
+
pair<bool, TString> PrivateGenerator::GetGrpcServices() {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
auto out = file->CreatePrinter(&output);
- if (generate_in_pb2_grpc) {
- out->Print(
- "# Generated by the gRPC Python protocol compiler plugin. "
+ if (generate_in_pb2_grpc) {
+ out->Print(
+ "# Generated by the gRPC Python protocol compiler plugin. "
"DO NOT EDIT!\n\"\"\""
"Client and server classes corresponding to protobuf-defined "
"services.\"\"\"\n");
if (!PrintPreamble(out.get())) {
- return make_pair(false, "");
- }
+ return make_pair(false, "");
+ }
if (!PrintGAServices(out.get())) {
- return make_pair(false, "");
- }
- } else {
- out->Print("try:\n");
- {
+ return make_pair(false, "");
+ }
+ } else {
+ out->Print("try:\n");
+ {
IndentScope raii_dict_try_indent(out.get());
- out->Print(
- "# THESE ELEMENTS WILL BE DEPRECATED.\n"
- "# Please use the generated *_pb2_grpc.py files instead.\n");
+ out->Print(
+ "# THESE ELEMENTS WILL BE DEPRECATED.\n"
+ "# Please use the generated *_pb2_grpc.py files instead.\n");
if (!PrintPreamble(out.get())) {
- return make_pair(false, "");
- }
+ return make_pair(false, "");
+ }
if (!PrintBetaPreamble(out.get())) {
- return make_pair(false, "");
- }
+ return make_pair(false, "");
+ }
if (!PrintGAServices(out.get())) {
- return make_pair(false, "");
- }
+ return make_pair(false, "");
+ }
if (!PrintBetaServices(out.get())) {
- return make_pair(false, "");
- }
- }
- out->Print("except ImportError:\n");
- {
+ return make_pair(false, "");
+ }
+ }
+ out->Print("except ImportError:\n");
+ {
IndentScope raii_dict_except_indent(out.get());
- out->Print("pass");
- }
- }
- }
- return make_pair(true, std::move(output));
-}
-
-} // namespace
-
-GeneratorConfiguration::GeneratorConfiguration()
+ out->Print("pass");
+ }
+ }
+ }
+ return make_pair(true, std::move(output));
+}
+
+} // namespace
+
+GeneratorConfiguration::GeneratorConfiguration()
: grpc_package_root("grpc"),
beta_package_root("grpc.beta"),
import_prefix("") {}
-
-PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config)
- : config_(config) {}
-
-PythonGrpcGenerator::~PythonGrpcGenerator() {}
-
-static bool GenerateGrpc(GeneratorContext* context, PrivateGenerator& generator,
+
+PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config)
+ : config_(config) {}
+
+PythonGrpcGenerator::~PythonGrpcGenerator() {}
+
+static bool GenerateGrpc(GeneratorContext* context, PrivateGenerator& generator,
TString file_name, bool generate_in_pb2_grpc) {
- bool success;
- std::unique_ptr<ZeroCopyOutputStream> output;
- std::unique_ptr<CodedOutputStream> coded_output;
+ bool success;
+ std::unique_ptr<ZeroCopyOutputStream> output;
+ std::unique_ptr<CodedOutputStream> coded_output;
TString grpc_code;
-
- if (generate_in_pb2_grpc) {
- output.reset(context->Open(file_name));
- generator.generate_in_pb2_grpc = true;
- } else {
- output.reset(context->OpenForInsert(file_name, "module_scope"));
- generator.generate_in_pb2_grpc = false;
- }
-
- coded_output.reset(new CodedOutputStream(output.get()));
+
+ if (generate_in_pb2_grpc) {
+ output.reset(context->Open(file_name));
+ generator.generate_in_pb2_grpc = true;
+ } else {
+ output.reset(context->OpenForInsert(file_name, "module_scope"));
+ generator.generate_in_pb2_grpc = false;
+ }
+
+ coded_output.reset(new CodedOutputStream(output.get()));
tie(success, grpc_code) = generator.GetGrpcServices();
-
- if (success) {
- coded_output->WriteRaw(grpc_code.data(), grpc_code.size());
- return true;
- } else {
- return false;
- }
-}
-
+
+ if (success) {
+ coded_output->WriteRaw(grpc_code.data(), grpc_code.size());
+ return true;
+ } else {
+ return false;
+ }
+}
+
static bool ParseParameters(const TString& parameter,
TString* grpc_version,
std::vector<TString>* strip_prefixes,
@@ -882,26 +882,26 @@ uint64_t PythonGrpcGenerator::GetSupportedFeatures() const {
return FEATURE_PROTO3_OPTIONAL;
}
-bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
+bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
const TString& parameter,
- GeneratorContext* context,
+ GeneratorContext* context,
TString* error) const {
- // Get output file name.
+ // Get output file name.
TString pb2_file_name;
TString pb2_grpc_file_name;
- static const int proto_suffix_length = strlen(".proto");
- if (file->name().size() > static_cast<size_t>(proto_suffix_length) &&
- file->name().find_last_of(".proto") == file->name().size() - 1) {
+ static const int proto_suffix_length = strlen(".proto");
+ if (file->name().size() > static_cast<size_t>(proto_suffix_length) &&
+ file->name().find_last_of(".proto") == file->name().size() - 1) {
TString base =
- file->name().substr(0, file->name().size() - proto_suffix_length);
- pb2_file_name = base + "_pb2.py";
- pb2_grpc_file_name = base + "_pb2_grpc.py";
- } else {
- *error = "Invalid proto file name. Proto file must end with .proto";
- return false;
- }
+ file->name().substr(0, file->name().size() - proto_suffix_length);
+ pb2_file_name = base + "_pb2.py";
+ pb2_grpc_file_name = base + "_pb2_grpc.py";
+ } else {
+ *error = "Invalid proto file name. Proto file must end with .proto";
+ return false;
+ }
generator_file_name = file->name();
-
+
ProtoBufFile pbfile(file);
TString grpc_version;
GeneratorConfiguration extended_config(config_);
@@ -910,14 +910,14 @@ bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
PrivateGenerator generator(extended_config, &pbfile);
if (!success) return false;
if (grpc_version == "grpc_2_0") {
- return GenerateGrpc(context, generator, pb2_grpc_file_name, true);
+ return GenerateGrpc(context, generator, pb2_grpc_file_name, true);
} else if (grpc_version == "grpc_1_0") {
- return GenerateGrpc(context, generator, pb2_grpc_file_name, true) &&
- GenerateGrpc(context, generator, pb2_file_name, false);
- } else {
+ return GenerateGrpc(context, generator, pb2_grpc_file_name, true) &&
+ GenerateGrpc(context, generator, pb2_file_name, false);
+ } else {
*error = "Invalid grpc version '" + grpc_version + "'.";
- return false;
- }
-}
-
-} // namespace grpc_python_generator
+ return false;
+ }
+}
+
+} // namespace grpc_python_generator
diff --git a/contrib/libs/grpc/src/compiler/python_generator.h b/contrib/libs/grpc/src/compiler/python_generator.h
index bcde0a5e358..0239d13fcdc 100644
--- a/contrib/libs/grpc/src/compiler/python_generator.h
+++ b/contrib/libs/grpc/src/compiler/python_generator.h
@@ -1,60 +1,60 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
-#define GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
-
-#include <utility>
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
+#define GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
+
+#include <utility>
#include <vector>
-
-#include "src/compiler/config.h"
+
+#include "src/compiler/config.h"
#include "src/compiler/schema_interface.h"
-
-namespace grpc_python_generator {
-
-// Data pertaining to configuration of the generator with respect to anything
-// that may be used internally at Google.
-struct GeneratorConfiguration {
- GeneratorConfiguration();
+
+namespace grpc_python_generator {
+
+// Data pertaining to configuration of the generator with respect to anything
+// that may be used internally at Google.
+struct GeneratorConfiguration {
+ GeneratorConfiguration();
TString grpc_package_root;
// TODO(https://github.com/grpc/grpc/issues/8622): Drop this.
TString beta_package_root;
// TODO(https://github.com/google/protobuf/issues/888): Drop this.
TString import_prefix;
std::vector<TString> prefixes_to_filter;
-};
-
-class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
- public:
- PythonGrpcGenerator(const GeneratorConfiguration& config);
- ~PythonGrpcGenerator();
-
+};
+
+class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
+ public:
+ PythonGrpcGenerator(const GeneratorConfiguration& config);
+ ~PythonGrpcGenerator();
+
uint64_t GetSupportedFeatures() const override;
- bool Generate(const grpc::protobuf::FileDescriptor* file,
+ bool Generate(const grpc::protobuf::FileDescriptor* file,
const TString& parameter,
- grpc::protobuf::compiler::GeneratorContext* context,
+ grpc::protobuf::compiler::GeneratorContext* context,
TString* error) const override;
-
- private:
- GeneratorConfiguration config_;
-};
-
-} // namespace grpc_python_generator
-
-#endif // GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
+
+ private:
+ GeneratorConfiguration config_;
+};
+
+} // namespace grpc_python_generator
+
+#endif // GRPC_INTERNAL_COMPILER_PYTHON_GENERATOR_H
diff --git a/contrib/libs/grpc/src/compiler/python_plugin.cc b/contrib/libs/grpc/src/compiler/python_plugin.cc
index 81eb1d4fc2e..0f0c77fd3a1 100644
--- a/contrib/libs/grpc/src/compiler/python_plugin.cc
+++ b/contrib/libs/grpc/src/compiler/python_plugin.cc
@@ -1,29 +1,29 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-// Generates a Python gRPC service interface out of Protobuf IDL.
-
-#include "src/compiler/config.h"
+ *
+ */
+
+// Generates a Python gRPC service interface out of Protobuf IDL.
+
+#include "src/compiler/config.h"
#include "src/compiler/protobuf_plugin.h"
-#include "src/compiler/python_generator.h"
-
-int main(int argc, char* argv[]) {
- grpc_python_generator::GeneratorConfiguration config;
- grpc_python_generator::PythonGrpcGenerator generator(config);
- return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
-}
+#include "src/compiler/python_generator.h"
+
+int main(int argc, char* argv[]) {
+ grpc_python_generator::GeneratorConfiguration config;
+ grpc_python_generator::PythonGrpcGenerator generator(config);
+ return grpc::protobuf::compiler::PluginMain(argc, argv, &generator);
+}
diff --git a/contrib/libs/grpc/src/compiler/ruby_generator.cc b/contrib/libs/grpc/src/compiler/ruby_generator.cc
index c82e78fd640..6c7702ae6c0 100644
--- a/contrib/libs/grpc/src/compiler/ruby_generator.cc
+++ b/contrib/libs/grpc/src/compiler/ruby_generator.cc
@@ -1,214 +1,214 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#include <cctype>
-#include <map>
-#include <vector>
-
-#include "src/compiler/config.h"
-#include "src/compiler/ruby_generator.h"
-#include "src/compiler/ruby_generator_helpers-inl.h"
-#include "src/compiler/ruby_generator_map-inl.h"
-#include "src/compiler/ruby_generator_string-inl.h"
-
-using grpc::protobuf::FileDescriptor;
+ *
+ */
+
+#include <cctype>
+#include <map>
+#include <vector>
+
+#include "src/compiler/config.h"
+#include "src/compiler/ruby_generator.h"
+#include "src/compiler/ruby_generator_helpers-inl.h"
+#include "src/compiler/ruby_generator_map-inl.h"
+#include "src/compiler/ruby_generator_string-inl.h"
+
+using grpc::protobuf::FileDescriptor;
using grpc::protobuf::MethodDescriptor;
-using grpc::protobuf::ServiceDescriptor;
-using grpc::protobuf::io::Printer;
-using grpc::protobuf::io::StringOutputStream;
-using std::map;
-using std::vector;
-
-namespace grpc_ruby_generator {
-namespace {
-
-// Prints out the method using the ruby gRPC DSL.
+using grpc::protobuf::ServiceDescriptor;
+using grpc::protobuf::io::Printer;
+using grpc::protobuf::io::StringOutputStream;
+using std::map;
+using std::vector;
+
+namespace grpc_ruby_generator {
+namespace {
+
+// Prints out the method using the ruby gRPC DSL.
void PrintMethod(const MethodDescriptor* method, Printer* out) {
TString input_type = RubyTypeOf(method->input_type());
- if (method->client_streaming()) {
- input_type = "stream(" + input_type + ")";
- }
+ if (method->client_streaming()) {
+ input_type = "stream(" + input_type + ")";
+ }
TString output_type = RubyTypeOf(method->output_type());
- if (method->server_streaming()) {
- output_type = "stream(" + output_type + ")";
- }
+ if (method->server_streaming()) {
+ output_type = "stream(" + output_type + ")";
+ }
std::map<TString, TString> method_vars = ListToDict({
"mth.name",
method->name(),
"input.type",
input_type,
"output.type",
- output_type,
- });
- out->Print(GetRubyComments(method, true).c_str());
- out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
- out->Print(GetRubyComments(method, false).c_str());
-}
-
-// Prints out the service using the ruby gRPC DSL.
+ output_type,
+ });
+ out->Print(GetRubyComments(method, true).c_str());
+ out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
+ out->Print(GetRubyComments(method, false).c_str());
+}
+
+// Prints out the service using the ruby gRPC DSL.
void PrintService(const ServiceDescriptor* service, Printer* out) {
- if (service->method_count() == 0) {
- return;
- }
-
- // Begin the service module
+ if (service->method_count() == 0) {
+ return;
+ }
+
+ // Begin the service module
std::map<TString, TString> module_vars = ListToDict({
"module.name",
Modularize(service->name()),
- });
- out->Print(module_vars, "module $module.name$\n");
- out->Indent();
-
- out->Print(GetRubyComments(service, true).c_str());
- out->Print("class Service\n");
-
- // Write the indented class body.
- out->Indent();
- out->Print("\n");
- out->Print("include GRPC::GenericService\n");
- out->Print("\n");
- out->Print("self.marshal_class_method = :encode\n");
- out->Print("self.unmarshal_class_method = :decode\n");
+ });
+ out->Print(module_vars, "module $module.name$\n");
+ out->Indent();
+
+ out->Print(GetRubyComments(service, true).c_str());
+ out->Print("class Service\n");
+
+ // Write the indented class body.
+ out->Indent();
+ out->Print("\n");
+ out->Print("include GRPC::GenericService\n");
+ out->Print("\n");
+ out->Print("self.marshal_class_method = :encode\n");
+ out->Print("self.unmarshal_class_method = :decode\n");
std::map<TString, TString> pkg_vars =
- ListToDict({"service_full_name", service->full_name()});
- out->Print(pkg_vars, "self.service_name = '$service_full_name$'\n");
- out->Print("\n");
- for (int i = 0; i < service->method_count(); ++i) {
+ ListToDict({"service_full_name", service->full_name()});
+ out->Print(pkg_vars, "self.service_name = '$service_full_name$'\n");
+ out->Print("\n");
+ for (int i = 0; i < service->method_count(); ++i) {
PrintMethod(service->method(i), out);
- }
- out->Outdent();
-
- out->Print("end\n");
- out->Print("\n");
- out->Print("Stub = Service.rpc_stub_class\n");
-
- // End the service module
- out->Outdent();
- out->Print("end\n");
- out->Print(GetRubyComments(service, false).c_str());
-}
-
-} // namespace
-
-// The following functions are copied directly from the source for the protoc
-// ruby generator
-// to ensure compatibility (with the exception of int and string type changes).
-// See
-// https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/ruby/ruby_generator.cc#L250
-// TODO: keep up to date with protoc code generation, though this behavior isn't
-// expected to change
-bool IsLower(char ch) { return ch >= 'a' && ch <= 'z'; }
-
-char ToUpper(char ch) { return IsLower(ch) ? (ch - 'a' + 'A') : ch; }
-
-// Package names in protobuf are snake_case by convention, but Ruby module
-// names must be PascalCased.
-//
-// foo_bar_baz -> FooBarBaz
+ }
+ out->Outdent();
+
+ out->Print("end\n");
+ out->Print("\n");
+ out->Print("Stub = Service.rpc_stub_class\n");
+
+ // End the service module
+ out->Outdent();
+ out->Print("end\n");
+ out->Print(GetRubyComments(service, false).c_str());
+}
+
+} // namespace
+
+// The following functions are copied directly from the source for the protoc
+// ruby generator
+// to ensure compatibility (with the exception of int and string type changes).
+// See
+// https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/ruby/ruby_generator.cc#L250
+// TODO: keep up to date with protoc code generation, though this behavior isn't
+// expected to change
+bool IsLower(char ch) { return ch >= 'a' && ch <= 'z'; }
+
+char ToUpper(char ch) { return IsLower(ch) ? (ch - 'a' + 'A') : ch; }
+
+// Package names in protobuf are snake_case by convention, but Ruby module
+// names must be PascalCased.
+//
+// foo_bar_baz -> FooBarBaz
TString PackageToModule(const TString& name) {
- bool next_upper = true;
+ bool next_upper = true;
TString result;
- result.reserve(name.size());
-
+ result.reserve(name.size());
+
for (TString::size_type i = 0; i < name.size(); i++) {
- if (name[i] == '_') {
- next_upper = true;
- } else {
- if (next_upper) {
- result.push_back(ToUpper(name[i]));
- } else {
- result.push_back(name[i]);
- }
- next_upper = false;
- }
- }
-
- return result;
-}
-// end copying of protoc generator for ruby code
-
+ if (name[i] == '_') {
+ next_upper = true;
+ } else {
+ if (next_upper) {
+ result.push_back(ToUpper(name[i]));
+ } else {
+ result.push_back(name[i]);
+ }
+ next_upper = false;
+ }
+ }
+
+ return result;
+}
+// end copying of protoc generator for ruby code
+
TString GetServices(const FileDescriptor* file) {
TString output;
- {
- // Scope the output stream so it closes and finalizes output to the string.
-
- StringOutputStream output_stream(&output);
- Printer out(&output_stream, '$');
-
- // Don't write out any output if there no services, to avoid empty service
- // files being generated for proto files that don't declare any.
- if (file->service_count() == 0) {
- return output;
- }
-
+ {
+ // Scope the output stream so it closes and finalizes output to the string.
+
+ StringOutputStream output_stream(&output);
+ Printer out(&output_stream, '$');
+
+ // Don't write out any output if there no services, to avoid empty service
+ // files being generated for proto files that don't declare any.
+ if (file->service_count() == 0) {
+ return output;
+ }
+
TString package_name = RubyPackage(file);
- // Write out a file header.
+ // Write out a file header.
std::map<TString, TString> header_comment_vars = ListToDict({
"file.name",
file->name(),
"file.package",
package_name,
- });
- out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
- out.Print(header_comment_vars,
- "# Source: $file.name$ for package '$file.package$'\n");
-
+ });
+ out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
+ out.Print(header_comment_vars,
+ "# Source: $file.name$ for package '$file.package$'\n");
+
TString leading_comments = GetRubyComments(file, true);
- if (!leading_comments.empty()) {
- out.Print("# Original file comments:\n");
+ if (!leading_comments.empty()) {
+ out.Print("# Original file comments:\n");
out.PrintRaw(leading_comments.c_str());
- }
-
- out.Print("\n");
- out.Print("require 'grpc'\n");
- // Write out require statemment to import the separately generated file
- // that defines the messages used by the service. This is generated by the
- // main ruby plugin.
+ }
+
+ out.Print("\n");
+ out.Print("require 'grpc'\n");
+ // Write out require statemment to import the separately generated file
+ // that defines the messages used by the service. This is generated by the
+ // main ruby plugin.
std::map<TString, TString> dep_vars = ListToDict({
"dep.name",
MessagesRequireName(file),
- });
- out.Print(dep_vars, "require '$dep.name$'\n");
-
- // Write out services within the modules
- out.Print("\n");
+ });
+ out.Print(dep_vars, "require '$dep.name$'\n");
+
+ // Write out services within the modules
+ out.Print("\n");
std::vector<TString> modules = Split(package_name, '.');
- for (size_t i = 0; i < modules.size(); ++i) {
+ for (size_t i = 0; i < modules.size(); ++i) {
std::map<TString, TString> module_vars = ListToDict({
"module.name",
PackageToModule(modules[i]),
- });
- out.Print(module_vars, "module $module.name$\n");
- out.Indent();
- }
- for (int i = 0; i < file->service_count(); ++i) {
- auto service = file->service(i);
+ });
+ out.Print(module_vars, "module $module.name$\n");
+ out.Indent();
+ }
+ for (int i = 0; i < file->service_count(); ++i) {
+ auto service = file->service(i);
PrintService(service, &out);
- }
- for (size_t i = 0; i < modules.size(); ++i) {
- out.Outdent();
- out.Print("end\n");
- }
-
- out.Print(GetRubyComments(file, false).c_str());
- }
- return output;
-}
-
-} // namespace grpc_ruby_generator
+ }
+ for (size_t i = 0; i < modules.size(); ++i) {
+ out.Outdent();
+ out.Print("end\n");
+ }
+
+ out.Print(GetRubyComments(file, false).c_str());
+ }
+ return output;
+}
+
+} // namespace grpc_ruby_generator
diff --git a/contrib/libs/grpc/src/compiler/ruby_generator.h b/contrib/libs/grpc/src/compiler/ruby_generator.h
index 325dc02294a..3a7766056dc 100644
--- a/contrib/libs/grpc/src/compiler/ruby_generator.h
+++ b/contrib/libs/grpc/src/compiler/ruby_generator.h
@@ -1,30 +1,30 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
-#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
-
-#include "src/compiler/config.h"
-
-namespace grpc_ruby_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
+#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
+
+#include "src/compiler/config.h"
+
+namespace grpc_ruby_generator {
+
TString GetServices(const grpc::protobuf::FileDescriptor* file);
-
-} // namespace grpc_ruby_generator
-
-#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
+
+} // namespace grpc_ruby_generator
+
+#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_H
diff --git a/contrib/libs/grpc/src/compiler/ruby_generator_helpers-inl.h b/contrib/libs/grpc/src/compiler/ruby_generator_helpers-inl.h
index 9a109766194..c22c4be0d9d 100644
--- a/contrib/libs/grpc/src/compiler/ruby_generator_helpers-inl.h
+++ b/contrib/libs/grpc/src/compiler/ruby_generator_helpers-inl.h
@@ -1,58 +1,58 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
-#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
-
-#include "src/compiler/config.h"
-#include "src/compiler/generator_helpers.h"
-#include "src/compiler/ruby_generator_string-inl.h"
-
-namespace grpc_ruby_generator {
-
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
+#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
+
+#include "src/compiler/config.h"
+#include "src/compiler/generator_helpers.h"
+#include "src/compiler/ruby_generator_string-inl.h"
+
+namespace grpc_ruby_generator {
+
inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file,
TString* file_name_or_error) {
- // Get output file name.
- static const unsigned proto_suffix_length = 6; // length of ".proto"
- if (file->name().size() > proto_suffix_length &&
- file->name().find_last_of(".proto") == file->name().size() - 1) {
- *file_name_or_error =
- file->name().substr(0, file->name().size() - proto_suffix_length) +
- "_services_pb.rb";
- return true;
- } else {
- *file_name_or_error = "Invalid proto file name: must end with .proto";
- return false;
- }
-}
-
+ // Get output file name.
+ static const unsigned proto_suffix_length = 6; // length of ".proto"
+ if (file->name().size() > proto_suffix_length &&
+ file->name().find_last_of(".proto") == file->name().size() - 1) {
+ *file_name_or_error =
+ file->name().substr(0, file->name().size() - proto_suffix_length) +
+ "_services_pb.rb";
+ return true;
+ } else {
+ *file_name_or_error = "Invalid proto file name: must end with .proto";
+ return false;
+ }
+}
+
inline TString MessagesRequireName(
const grpc::protobuf::FileDescriptor* file) {
- return Replace(file->name(), ".proto", "_pb");
-}
-
-// Get leading or trailing comments in a string. Comment lines start with "# ".
+ return Replace(file->name(), ".proto", "_pb");
+}
+
+// Get leading or trailing comments in a string. Comment lines start with "# ".
// Leading detached comments are put in front of leading comments.
-template <typename DescriptorType>
+template <typename DescriptorType>
inline TString GetRubyComments(const DescriptorType* desc, bool leading) {
- return grpc_generator::GetPrefixedComments(desc, leading, "#");
-}
-
-} // namespace grpc_ruby_generator
-
-#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
+ return grpc_generator::GetPrefixedComments(desc, leading, "#");
+}
+
+} // namespace grpc_ruby_generator
+
+#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_HELPERS_INL_H
diff --git a/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h b/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h
index 4c75780b1a3..3b217cf7d2d 100644
--- a/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h
+++ b/contrib/libs/grpc/src/compiler/ruby_generator_map-inl.h
@@ -1,57 +1,57 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
-#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
-
-#include "src/compiler/config.h"
-
-#include <initializer_list>
-#include <iostream>
-#include <map>
-#include <ostream> // NOLINT
-#include <vector>
-
-using std::initializer_list;
-using std::map;
-using std::vector;
-
-namespace grpc_ruby_generator {
-
-// Converts an initializer list of the form { key0, value0, key1, value1, ... }
-// into a map of key* to value*. Is merely a readability helper for later code.
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
+#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
+
+#include "src/compiler/config.h"
+
+#include <initializer_list>
+#include <iostream>
+#include <map>
+#include <ostream> // NOLINT
+#include <vector>
+
+using std::initializer_list;
+using std::map;
+using std::vector;
+
+namespace grpc_ruby_generator {
+
+// Converts an initializer list of the form { key0, value0, key1, value1, ... }
+// into a map of key* to value*. Is merely a readability helper for later code.
inline std::map<TString, TString> ListToDict(
const initializer_list<TString>& values) {
- if (values.size() % 2 != 0) {
- std::cerr << "Not every 'key' has a value in `values`." << std::endl;
- }
+ if (values.size() % 2 != 0) {
+ std::cerr << "Not every 'key' has a value in `values`." << std::endl;
+ }
std::map<TString, TString> value_map;
- auto value_iter = values.begin();
- for (unsigned i = 0; i < values.size() / 2; ++i) {
+ auto value_iter = values.begin();
+ for (unsigned i = 0; i < values.size() / 2; ++i) {
TString key = *value_iter;
- ++value_iter;
+ ++value_iter;
TString value = *value_iter;
- value_map[key] = value;
- ++value_iter;
- }
- return value_map;
-}
-
-} // namespace grpc_ruby_generator
-
-#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
+ value_map[key] = value;
+ ++value_iter;
+ }
+ return value_map;
+}
+
+} // namespace grpc_ruby_generator
+
+#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_MAP_INL_H
diff --git a/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h b/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h
index 956539f392a..247d7f5e2c0 100644
--- a/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h
+++ b/contrib/libs/grpc/src/compiler/ruby_generator_string-inl.h
@@ -1,91 +1,91 @@
-/*
- *
+/*
+ *
* Copyright 2015 gRPC authors.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- */
-
-#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
-#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
-
-#include "src/compiler/config.h"
-
-#include <algorithm>
-#include <sstream>
-#include <vector>
-
-using std::getline;
-using std::transform;
-
-namespace grpc_ruby_generator {
-
-// Split splits a string using char into elems.
+ *
+ */
+
+#ifndef GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
+#define GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
+
+#include "src/compiler/config.h"
+
+#include <algorithm>
+#include <sstream>
+#include <vector>
+
+using std::getline;
+using std::transform;
+
+namespace grpc_ruby_generator {
+
+// Split splits a string using char into elems.
inline std::vector<TString>& Split(const TString& s, char delim,
std::vector<TString>* elems) {
- std::stringstream ss(s);
+ std::stringstream ss(s);
TString item;
- while (getline(ss, item, delim)) {
- elems->push_back(item);
- }
- return *elems;
-}
-
-// Split splits a string using char, returning the result in a vector.
+ while (getline(ss, item, delim)) {
+ elems->push_back(item);
+ }
+ return *elems;
+}
+
+// Split splits a string using char, returning the result in a vector.
inline std::vector<TString> Split(const TString& s, char delim) {
std::vector<TString> elems;
- Split(s, delim, &elems);
- return elems;
-}
-
-// Replace replaces from with to in s.
+ Split(s, delim, &elems);
+ return elems;
+}
+
+// Replace replaces from with to in s.
inline TString Replace(TString s, const TString& from,
const TString& to) {
- size_t start_pos = s.find(from);
+ size_t start_pos = s.find(from);
if (start_pos == TString::npos) {
- return s;
- }
- s.replace(start_pos, from.length(), to);
- return s;
-}
-
-// ReplaceAll replaces all instances of search with replace in s.
+ return s;
+ }
+ s.replace(start_pos, from.length(), to);
+ return s;
+}
+
+// ReplaceAll replaces all instances of search with replace in s.
inline TString ReplaceAll(TString s, const TString& search,
const TString& replace) {
- size_t pos = 0;
+ size_t pos = 0;
while ((pos = s.find(search, pos)) != TString::npos) {
- s.replace(pos, search.length(), replace);
- pos += replace.length();
- }
- return s;
-}
-
-// ReplacePrefix replaces from with to in s if search is a prefix of s.
+ s.replace(pos, search.length(), replace);
+ pos += replace.length();
+ }
+ return s;
+}
+
+// ReplacePrefix replaces from with to in s if search is a prefix of s.
inline bool ReplacePrefix(TString* s, const TString& from,
const TString& to) {
- size_t start_pos = s->find(from);
+ size_t start_pos = s->find(from);
if (start_pos == TString::npos || start_pos != 0) {
- return false;
- }
- s->replace(start_pos, from.length(), to);
- return true;
-}
-
+ return false;
+ }
+ s->replace(start_pos, from.length(), to);
+ return true;
+}
+
// Modularize converts a string into a ruby module compatible name
inline TString Modularize(TString s) {
- if (s.empty()) {
- return s;
- }
+ if (s.empty()) {
+ return s;
+ }
TString new_string = "";
bool was_last_underscore = false;
new_string.append(1, ::toupper(s[0]));
@@ -98,8 +98,8 @@ inline TString Modularize(TString s) {
was_last_underscore = s[i] == '_';
}
return new_string;
-}
-
+}
+
// RubyPackage gets the ruby package in either proto or ruby_package format
inline TString RubyPackage(const grpc::protobuf::FileDescriptor* file) {
TString package_name = file->package();
@@ -115,7 +115,7 @@ inline TString RubyPackage(const grpc::protobuf::FileDescriptor* file) {
return package_name;
}
-// RubyTypeOf updates a proto type to the required ruby equivalent.
+// RubyTypeOf updates a proto type to the required ruby equivalent.
inline TString RubyTypeOf(const grpc::protobuf::Descriptor* descriptor) {
TString proto_type = descriptor->full_name();
if (descriptor->file()->options().has_ruby_package()) {
@@ -126,24 +126,24 @@ inline TString RubyTypeOf(const grpc::protobuf::Descriptor* descriptor) {
}
TString res("." + proto_type);
if (res.find('.') == TString::npos) {
- return res;
- } else {
+ return res;
+ } else {
std::vector<TString> prefixes_and_type = Split(res, '.');
- res.clear();
- for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
- if (i != 0) {
- res += "::"; // switch '.' to the ruby module delim
- }
- if (i < prefixes_and_type.size() - 1) {
+ res.clear();
+ for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
+ if (i != 0) {
+ res += "::"; // switch '.' to the ruby module delim
+ }
+ if (i < prefixes_and_type.size() - 1) {
res += Modularize(prefixes_and_type[i]); // capitalize pkgs
- } else {
- res += prefixes_and_type[i];
- }
- }
- return res;
- }
-}
-
-} // namespace grpc_ruby_generator
-
-#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H
+ } else {
+ res += prefixes_and_type[i];
+ }
+ }
+ return res;
+ }
+}
+
+} // namespace grpc_ruby_generator
+
+#endif // GRPC_INTERNAL_COMPILER_RUBY_GENERATOR_STRING_INL_H