mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 13:08:58 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -8,21 +8,22 @@
|
||||
namespace grpc_cpp_generator {
|
||||
namespace {
|
||||
|
||||
template<class T> static grpc::string as_string(T x) {
|
||||
template <class T>
|
||||
static grpc::string as_string(T x) {
|
||||
std::ostringstream out;
|
||||
out << x;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
static inline bool ClientOnlyStreaming(const grpc_generator::Method *method) {
|
||||
static inline bool ClientOnlyStreaming(const grpc_generator::Method* method) {
|
||||
return method->ClientStreaming() && !method->ServerStreaming();
|
||||
}
|
||||
|
||||
static inline bool ServerOnlyStreaming(const grpc_generator::Method *method) {
|
||||
static inline bool ServerOnlyStreaming(const grpc_generator::Method* method) {
|
||||
return !method->ClientStreaming() && method->ServerStreaming();
|
||||
}
|
||||
|
||||
static grpc::string FilenameIdentifier(const grpc::string &filename) {
|
||||
static grpc::string FilenameIdentifier(const grpc::string& filename) {
|
||||
grpc::string result;
|
||||
for (unsigned i = 0; i < filename.size(); i++) {
|
||||
char c = filename[i];
|
||||
@@ -38,22 +39,25 @@ static grpc::string FilenameIdentifier(const grpc::string &filename) {
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T, size_t N> static T *array_end(T (&array)[N]) {
|
||||
template <class T, size_t N>
|
||||
static T* array_end(T (&array)[N]) {
|
||||
return array + N;
|
||||
}
|
||||
|
||||
static void PrintIncludes(grpc_generator::Printer *printer,
|
||||
const std::vector<grpc::string> &headers,
|
||||
const Parameters ¶ms) {
|
||||
static void PrintIncludes(grpc_generator::Printer* printer,
|
||||
const std::vector<grpc::string>& headers,
|
||||
const Parameters& params) {
|
||||
std::map<grpc::string, grpc::string> vars;
|
||||
|
||||
vars["l"] = params.use_system_headers ? '<' : '"';
|
||||
vars["r"] = params.use_system_headers ? '>' : '"';
|
||||
|
||||
auto &s = params.grpc_search_path;
|
||||
auto& s = params.grpc_search_path;
|
||||
if (!s.empty()) {
|
||||
vars["l"] += s;
|
||||
if (s[s.size() - 1] != '/') { vars["l"] += '/'; }
|
||||
if (s[s.size() - 1] != '/') {
|
||||
vars["l"] += '/';
|
||||
}
|
||||
}
|
||||
|
||||
for (auto i = headers.begin(); i != headers.end(); i++) {
|
||||
@@ -62,12 +66,11 @@ static void PrintIncludes(grpc_generator::Printer *printer,
|
||||
}
|
||||
if (params.generate_callback_api) {
|
||||
// Callback API headers (guarded later by feature macro in emitted code).
|
||||
static const char *cb_headers[] = {
|
||||
"grpcpp/impl/codegen/callback_common.h",
|
||||
"grpcpp/impl/codegen/server_callback_handlers.h",
|
||||
"grpcpp/support/client_callback.h"
|
||||
};
|
||||
for (auto &h : cb_headers) {
|
||||
static const char* cb_headers[] = {
|
||||
"grpcpp/impl/codegen/callback_common.h",
|
||||
"grpcpp/impl/codegen/server_callback_handlers.h",
|
||||
"grpcpp/support/client_callback.h"};
|
||||
for (auto& h : cb_headers) {
|
||||
vars["h"] = h;
|
||||
printer->Print(vars, "#include $l$$h$$r$\n");
|
||||
}
|
||||
@@ -76,8 +79,8 @@ static void PrintIncludes(grpc_generator::Printer *printer,
|
||||
|
||||
} // namespace
|
||||
|
||||
grpc::string GetHeaderPrologue(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetHeaderPrologue(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -108,25 +111,24 @@ grpc::string GetHeaderPrologue(grpc_generator::File *file,
|
||||
return output;
|
||||
}
|
||||
|
||||
grpc::string GetHeaderIncludes(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetHeaderIncludes(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
auto printer = file->CreatePrinter(&output);
|
||||
std::map<grpc::string, grpc::string> vars;
|
||||
|
||||
static const char *headers_strs[] = {
|
||||
"grpcpp/impl/codegen/async_stream.h",
|
||||
"grpcpp/impl/codegen/async_unary_call.h",
|
||||
"grpcpp/impl/codegen/method_handler.h",
|
||||
"grpcpp/impl/codegen/proto_utils.h",
|
||||
"grpcpp/impl/codegen/rpc_method.h",
|
||||
"grpcpp/impl/codegen/service_type.h",
|
||||
"grpcpp/impl/codegen/status.h",
|
||||
"grpcpp/impl/codegen/stub_options.h",
|
||||
"grpcpp/impl/codegen/sync_stream.h"
|
||||
};
|
||||
static const char* headers_strs[] = {
|
||||
"grpcpp/impl/codegen/async_stream.h",
|
||||
"grpcpp/impl/codegen/async_unary_call.h",
|
||||
"grpcpp/impl/codegen/method_handler.h",
|
||||
"grpcpp/impl/codegen/proto_utils.h",
|
||||
"grpcpp/impl/codegen/rpc_method.h",
|
||||
"grpcpp/impl/codegen/service_type.h",
|
||||
"grpcpp/impl/codegen/status.h",
|
||||
"grpcpp/impl/codegen/stub_options.h",
|
||||
"grpcpp/impl/codegen/sync_stream.h"};
|
||||
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
|
||||
PrintIncludes(printer.get(), headers, params);
|
||||
printer->Print(vars, "\n");
|
||||
@@ -153,8 +155,8 @@ grpc::string GetHeaderIncludes(grpc_generator::File *file,
|
||||
namespace {
|
||||
|
||||
static void PrintHeaderClientMethodInterfaces(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars, bool is_public) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars, bool is_public) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -163,8 +165,8 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
grpc::string prefix;
|
||||
grpc::string method_params; // extra arguments to method
|
||||
grpc::string raw_args; // extra arguments to raw version of method
|
||||
} async_prefixes[] = { { "Async", ", void* tag", ", tag" },
|
||||
{ "PrepareAsync", "", "" } };
|
||||
} async_prefixes[] = {{"Async", ", void* tag", ", tag"},
|
||||
{"PrepareAsync", "", ""}};
|
||||
|
||||
if (is_public) {
|
||||
if (method->NoStreaming()) {
|
||||
@@ -174,7 +176,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
"const $Request$& request, $Response$* response) = 0;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
printer->Print(
|
||||
*vars,
|
||||
@@ -207,7 +209,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
printer->Print("}\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -242,7 +244,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
printer->Print("}\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -276,7 +278,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
printer->Print("}\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -300,7 +302,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
if (method->NoStreaming()) {
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
printer->Print(
|
||||
*vars,
|
||||
@@ -317,7 +319,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
"::grpc::ClientContext* context, $Response$* response) = 0;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
printer->Print(
|
||||
@@ -335,7 +337,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
"::grpc::ClientContext* context, const $Request$& request) = 0;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
printer->Print(
|
||||
@@ -352,7 +354,7 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
"$Method$Raw(::grpc::ClientContext* context) = 0;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
printer->Print(
|
||||
@@ -366,9 +368,9 @@ static void PrintHeaderClientMethodInterfaces(
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars,
|
||||
static void PrintHeaderClientMethod(grpc_generator::Printer* printer,
|
||||
const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars,
|
||||
bool is_public) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
@@ -377,8 +379,8 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
grpc::string prefix;
|
||||
grpc::string method_params; // extra arguments to method
|
||||
grpc::string raw_args; // extra arguments to raw version of method
|
||||
} async_prefixes[] = { { "Async", ", void* tag", ", tag" },
|
||||
{ "PrepareAsync", "", "" } };
|
||||
} async_prefixes[] = {{"Async", ", void* tag", ", tag"},
|
||||
{"PrepareAsync", "", ""}};
|
||||
|
||||
if (is_public) {
|
||||
if (method->NoStreaming()) {
|
||||
@@ -404,7 +406,7 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
printer->Print(
|
||||
*vars,
|
||||
@@ -432,15 +434,16 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
"($Method$Raw(context, response));\n");
|
||||
printer->Outdent();
|
||||
printer->Print("}\n");
|
||||
if ((*vars)["generate_callback_api"] == "1") {
|
||||
printer->Print(*vars, "// Client streaming callback reactor entry.\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
"void async_$Method$(::grpc::ClientContext* context, $Response$* response, ::grpc::ClientWriteReactor< $Request$ >* reactor);\n");
|
||||
}
|
||||
if ((*vars)["generate_callback_api"] == "1") {
|
||||
printer->Print(*vars, "// Client streaming callback reactor entry.\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
"void async_$Method$(::grpc::ClientContext* context, $Response$* "
|
||||
"response, ::grpc::ClientWriteReactor< $Request$ >* reactor);\n");
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -474,11 +477,13 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
if ((*vars)["generate_callback_api"] == "1") {
|
||||
printer->Print(*vars, "// Server streaming callback reactor entry.\n");
|
||||
printer->Print(*vars,
|
||||
"void async_$Method$(::grpc::ClientContext* context, const $Request$& request, ::grpc::ClientReadReactor< $Response$ >* reactor);\n");
|
||||
"void async_$Method$(::grpc::ClientContext* context, "
|
||||
"const $Request$& request, ::grpc::ClientReadReactor< "
|
||||
"$Response$ >* reactor);\n");
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -508,15 +513,17 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
"$Method$Raw(context));\n");
|
||||
printer->Outdent();
|
||||
printer->Print("}\n");
|
||||
if ((*vars)["generate_callback_api"] == "1") {
|
||||
printer->Print(*vars, "// Bidirectional streaming callback reactor entry.\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
"void async_$Method$(::grpc::ClientContext* context, ::grpc::ClientBidiReactor< $Request$, $Response$ >* reactor);\n");
|
||||
}
|
||||
if ((*vars)["generate_callback_api"] == "1") {
|
||||
printer->Print(*vars,
|
||||
"// Bidirectional streaming callback reactor entry.\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
"void async_$Method$(::grpc::ClientContext* context, "
|
||||
"::grpc::ClientBidiReactor< $Request$, $Response$ >* reactor);\n");
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -539,7 +546,7 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
if (method->NoStreaming()) {
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
printer->Print(
|
||||
*vars,
|
||||
@@ -559,7 +566,7 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
"override;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -576,7 +583,7 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
" override;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -592,7 +599,7 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
"$Method$Raw(::grpc::ClientContext* context) override;\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["AsyncRawArgs"] = async_prefix.raw_args;
|
||||
@@ -607,16 +614,16 @@ static void PrintHeaderClientMethod(grpc_generator::Printer *printer,
|
||||
}
|
||||
|
||||
static void PrintHeaderClientMethodData(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
printer->Print(*vars,
|
||||
"const ::grpc::internal::RpcMethod rpcmethod_$Method$_;\n");
|
||||
}
|
||||
|
||||
static void PrintHeaderServerMethodSync(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -649,8 +656,8 @@ static void PrintHeaderServerMethodSync(
|
||||
}
|
||||
|
||||
static void PrintHeaderServerMethodAsync(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -765,8 +772,8 @@ static void PrintHeaderServerMethodAsync(
|
||||
}
|
||||
|
||||
static void PrintHeaderServerMethodStreamedUnary(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -816,8 +823,8 @@ static void PrintHeaderServerMethodStreamedUnary(
|
||||
}
|
||||
|
||||
static void PrintHeaderServerMethodSplitStreaming(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -869,8 +876,8 @@ static void PrintHeaderServerMethodSplitStreaming(
|
||||
}
|
||||
|
||||
static void PrintHeaderServerMethodGeneric(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -939,9 +946,9 @@ static void PrintHeaderServerMethodGeneric(
|
||||
printer->Print(*vars, "};\n");
|
||||
}
|
||||
|
||||
static void PrintHeaderService(grpc_generator::Printer *printer,
|
||||
const grpc_generator::Service *service,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
static void PrintHeaderService(grpc_generator::Printer* printer,
|
||||
const grpc_generator::Service* service,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Service"] = service->name();
|
||||
|
||||
printer->Print(service->GetLeadingComments("//").c_str());
|
||||
@@ -1036,7 +1043,9 @@ static void PrintHeaderService(grpc_generator::Printer *printer,
|
||||
printer->Print(*vars, "WithAsyncMethod_$method_name$<");
|
||||
}
|
||||
printer->Print("Service");
|
||||
for (int i = 0; i < service->method_count(); ++i) { printer->Print(" >"); }
|
||||
for (int i = 0; i < service->method_count(); ++i) {
|
||||
printer->Print(" >");
|
||||
}
|
||||
printer->Print(" AsyncService;\n");
|
||||
|
||||
// Server side - Generic
|
||||
@@ -1061,7 +1070,9 @@ static void PrintHeaderService(grpc_generator::Printer *printer,
|
||||
}
|
||||
printer->Print("Service");
|
||||
for (int i = 0; i < service->method_count(); ++i) {
|
||||
if (service->method(i)->NoStreaming()) { printer->Print(" >"); }
|
||||
if (service->method(i)->NoStreaming()) {
|
||||
printer->Print(" >");
|
||||
}
|
||||
}
|
||||
printer->Print(" StreamedUnaryService;\n");
|
||||
|
||||
@@ -1083,7 +1094,9 @@ static void PrintHeaderService(grpc_generator::Printer *printer,
|
||||
printer->Print("Service");
|
||||
for (int i = 0; i < service->method_count(); ++i) {
|
||||
auto method = service->method(i);
|
||||
if (ServerOnlyStreaming(method.get())) { printer->Print(" >"); }
|
||||
if (ServerOnlyStreaming(method.get())) {
|
||||
printer->Print(" >");
|
||||
}
|
||||
}
|
||||
printer->Print(" SplitStreamedService;\n");
|
||||
|
||||
@@ -1117,10 +1130,10 @@ static void PrintHeaderService(grpc_generator::Printer *printer,
|
||||
if ((*vars)["generate_callback_api"] == "1") {
|
||||
(*vars)["Service"] = service->name();
|
||||
printer->Print("\n#if defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)\n");
|
||||
printer->Print(*vars,
|
||||
"class $Service$::CallbackService : public ::grpc::Service "
|
||||
"{\n public:\n CallbackService();\n virtual "
|
||||
"~CallbackService();\n");
|
||||
printer->Print(*vars,
|
||||
"class $Service$::CallbackService : public ::grpc::Service "
|
||||
"{\n public:\n CallbackService();\n virtual "
|
||||
"~CallbackService();\n");
|
||||
printer->Indent();
|
||||
for (int i = 0; i < service->method_count(); ++i) {
|
||||
auto m = service->method(i);
|
||||
@@ -1158,8 +1171,8 @@ static void PrintHeaderService(grpc_generator::Printer *printer,
|
||||
|
||||
} // namespace
|
||||
|
||||
grpc::string GetHeaderServices(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetHeaderServices(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -1168,7 +1181,9 @@ grpc::string GetHeaderServices(grpc_generator::File *file,
|
||||
// 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 (!file->package().empty()) {
|
||||
vars["Package"].append(".");
|
||||
}
|
||||
|
||||
if (!params.services_namespace.empty()) {
|
||||
vars["services_namespace"] = params.services_namespace;
|
||||
@@ -1192,8 +1207,8 @@ grpc::string GetHeaderServices(grpc_generator::File *file,
|
||||
return output;
|
||||
}
|
||||
|
||||
grpc::string GetHeaderEpilogue(grpc_generator::File *file,
|
||||
const Parameters & /*params*/) {
|
||||
grpc::string GetHeaderEpilogue(grpc_generator::File* file,
|
||||
const Parameters& /*params*/) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -1221,8 +1236,8 @@ grpc::string GetHeaderEpilogue(grpc_generator::File *file,
|
||||
return output;
|
||||
}
|
||||
|
||||
grpc::string GetSourcePrologue(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetSourcePrologue(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -1247,24 +1262,23 @@ grpc::string GetSourcePrologue(grpc_generator::File *file,
|
||||
return output;
|
||||
}
|
||||
|
||||
grpc::string GetSourceIncludes(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetSourceIncludes(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
auto printer = file->CreatePrinter(&output);
|
||||
std::map<grpc::string, grpc::string> vars;
|
||||
|
||||
static const char *headers_strs[] = {
|
||||
"grpcpp/impl/codegen/async_stream.h",
|
||||
"grpcpp/impl/codegen/async_unary_call.h",
|
||||
"grpcpp/impl/codegen/channel_interface.h",
|
||||
"grpcpp/impl/codegen/client_unary_call.h",
|
||||
"grpcpp/impl/codegen/method_handler.h",
|
||||
"grpcpp/impl/codegen/rpc_service_method.h",
|
||||
"grpcpp/impl/codegen/service_type.h",
|
||||
"grpcpp/impl/codegen/sync_stream.h"
|
||||
};
|
||||
static const char* headers_strs[] = {
|
||||
"grpcpp/impl/codegen/async_stream.h",
|
||||
"grpcpp/impl/codegen/async_unary_call.h",
|
||||
"grpcpp/impl/codegen/channel_interface.h",
|
||||
"grpcpp/impl/codegen/client_unary_call.h",
|
||||
"grpcpp/impl/codegen/method_handler.h",
|
||||
"grpcpp/impl/codegen/rpc_service_method.h",
|
||||
"grpcpp/impl/codegen/service_type.h",
|
||||
"grpcpp/impl/codegen/sync_stream.h"};
|
||||
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
|
||||
PrintIncludes(printer.get(), headers, params);
|
||||
|
||||
@@ -1285,8 +1299,8 @@ grpc::string GetSourceIncludes(grpc_generator::File *file,
|
||||
namespace {
|
||||
|
||||
static void PrintSourceClientMethod(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -1295,8 +1309,8 @@ static void PrintSourceClientMethod(
|
||||
grpc::string start; // bool literal expressed as string
|
||||
grpc::string method_params; // extra arguments to method
|
||||
grpc::string create_args; // extra arguments to creator
|
||||
} async_prefixes[] = { { "Async", "true", ", void* tag", ", tag" },
|
||||
{ "PrepareAsync", "false", "", ", nullptr" } };
|
||||
} async_prefixes[] = {{"Async", "true", ", void* tag", ", tag"},
|
||||
{"PrepareAsync", "false", "", ", nullptr"}};
|
||||
if (method->NoStreaming()) {
|
||||
printer->Print(*vars,
|
||||
"::grpc::Status $ns$$Service$::Stub::$Method$("
|
||||
@@ -1312,24 +1326,25 @@ static void PrintSourceClientMethod(
|
||||
"void $ns$$Service$::Stub::async_$Method$(::grpc::ClientContext* "
|
||||
"context, const $Request$& request, $Response$* response, "
|
||||
"std::function<void(::grpc::Status)> on_done) {\n");
|
||||
printer->Print(*vars,
|
||||
" ::grpc::internal::CallbackUnaryCall(channel_.get(), "
|
||||
"rpcmethod_$Method$_, context, &request, response, "
|
||||
"std::move(on_done));\n}\n\n");
|
||||
printer->Print(*vars,
|
||||
" ::grpc::internal::CallbackUnaryCall(channel_.get(), "
|
||||
"rpcmethod_$Method$_, context, &request, response, "
|
||||
"std::move(on_done));\n}\n\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
"void $ns$$Service$::Stub::async_$Method$(::grpc::ClientContext* "
|
||||
"context, const $Request$& request, $Response$* response, "
|
||||
"::grpc::ClientUnaryReactor* reactor) {\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
" "
|
||||
"::grpc::internal::ClientCallbackUnaryFactory::Create(channel_.get(),"
|
||||
" rpcmethod_$Method$_, context, &request, response, reactor);\n}\n\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
" "
|
||||
"::grpc::internal::ClientCallbackUnaryFactory::Create(channel_.get(),"
|
||||
" rpcmethod_$Method$_, context, &request, response, "
|
||||
"reactor);\n}\n\n");
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncStart"] = async_prefix.start;
|
||||
printer->Print(*vars,
|
||||
@@ -1372,7 +1387,7 @@ static void PrintSourceClientMethod(
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncStart"] = async_prefix.start;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
@@ -1409,14 +1424,15 @@ static void PrintSourceClientMethod(
|
||||
"void $ns$$Service$::Stub::async_$Method$(::grpc::ClientContext* "
|
||||
"context, const $Request$& request, ::grpc::ClientReadReactor< "
|
||||
"$Response$ >* reactor) {\n");
|
||||
printer->Print(*vars,
|
||||
" ::grpc::internal::ClientCallbackReaderFactory< "
|
||||
"$Response$ >::Create(channel_.get(), "
|
||||
"rpcmethod_$Method$_, context, &request, reactor);\n}\n\n");
|
||||
printer->Print(
|
||||
*vars,
|
||||
" ::grpc::internal::ClientCallbackReaderFactory< "
|
||||
"$Response$ >::Create(channel_.get(), "
|
||||
"rpcmethod_$Method$_, context, &request, reactor);\n}\n\n");
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncStart"] = async_prefix.start;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
@@ -1460,7 +1476,7 @@ static void PrintSourceClientMethod(
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncStart"] = async_prefix.start;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
@@ -1483,8 +1499,8 @@ static void PrintSourceClientMethod(
|
||||
}
|
||||
|
||||
static void PrintSourceServerMethod(
|
||||
grpc_generator::Printer *printer, const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
grpc_generator::Printer* printer, const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -1531,9 +1547,9 @@ static void PrintSourceServerMethod(
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintSourceService(grpc_generator::Printer *printer,
|
||||
const grpc_generator::Service *service,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
static void PrintSourceService(grpc_generator::Printer* printer,
|
||||
const grpc_generator::Service* service,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Service"] = service->name();
|
||||
|
||||
if (service->method_count() > 0) {
|
||||
@@ -1660,47 +1676,54 @@ static void PrintSourceService(grpc_generator::Printer *printer,
|
||||
(*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"
|
||||
" ::grpc::internal::RpcMethod::NORMAL_RPC,\n"
|
||||
" new ::grpc::internal::CallbackUnaryHandler<$Request$, $Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx, const $Request$* req, $Response$* resp) {\n"
|
||||
" return this->$Method$(ctx, req, resp);\n"
|
||||
" })));\n");
|
||||
} else if (ClientOnlyStreaming(method.get())) {
|
||||
printer->Print(
|
||||
*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::CLIENT_STREAMING,\n"
|
||||
" new ::grpc::internal::CallbackClientStreamingHandler<$Request$, $Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx, $Response$* resp) {\n"
|
||||
" return this->$Method$(ctx, resp);\n"
|
||||
" })));\n");
|
||||
} else if (ServerOnlyStreaming(method.get())) {
|
||||
printer->Print(
|
||||
*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::SERVER_STREAMING,\n"
|
||||
" new ::grpc::internal::CallbackServerStreamingHandler<$Request$, $Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx, const $Request$* req) {\n"
|
||||
" return this->$Method$(ctx, req);\n"
|
||||
" })));\n");
|
||||
} else if (method->BidiStreaming()) {
|
||||
printer->Print(
|
||||
*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::BIDI_STREAMING,\n"
|
||||
" new ::grpc::internal::CallbackBidiHandler<$Request$, $Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx) {\n"
|
||||
" return this->$Method$(ctx);\n"
|
||||
" })));\n");
|
||||
}
|
||||
if (method->NoStreaming()) {
|
||||
printer->Print(
|
||||
*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::NORMAL_RPC,\n"
|
||||
" new ::grpc::internal::CallbackUnaryHandler<$Request$, "
|
||||
"$Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx, const $Request$* "
|
||||
"req, $Response$* resp) {\n"
|
||||
" return this->$Method$(ctx, req, resp);\n"
|
||||
" })));\n");
|
||||
} else if (ClientOnlyStreaming(method.get())) {
|
||||
printer->Print(*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::CLIENT_STREAMING,\n"
|
||||
" new "
|
||||
"::grpc::internal::CallbackClientStreamingHandler<$"
|
||||
"Request$, $Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx, "
|
||||
"$Response$* resp) {\n"
|
||||
" return this->$Method$(ctx, resp);\n"
|
||||
" })));\n");
|
||||
} else if (ServerOnlyStreaming(method.get())) {
|
||||
printer->Print(*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::SERVER_STREAMING,\n"
|
||||
" new "
|
||||
"::grpc::internal::CallbackServerStreamingHandler<$"
|
||||
"Request$, $Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx, const "
|
||||
"$Request$* req) {\n"
|
||||
" return this->$Method$(ctx, req);\n"
|
||||
" })));\n");
|
||||
} else if (method->BidiStreaming()) {
|
||||
printer->Print(
|
||||
*vars,
|
||||
"AddMethod(new ::grpc::internal::RpcServiceMethod(\n"
|
||||
" $prefix$$Service$_method_names[$Idx$],\n"
|
||||
" ::grpc::internal::RpcMethod::BIDI_STREAMING,\n"
|
||||
" new ::grpc::internal::CallbackBidiHandler<$Request$, "
|
||||
"$Response$>(\n"
|
||||
" [this](::grpc::CallbackServerContext* ctx) {\n"
|
||||
" return this->$Method$(ctx);\n"
|
||||
" })));\n");
|
||||
}
|
||||
}
|
||||
printer->Outdent();
|
||||
printer->Print("}\n\n");
|
||||
@@ -1751,8 +1774,8 @@ static void PrintSourceService(grpc_generator::Printer *printer,
|
||||
|
||||
} // namespace
|
||||
|
||||
grpc::string GetSourceServices(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetSourceServices(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -1761,7 +1784,9 @@ grpc::string GetSourceServices(grpc_generator::File *file,
|
||||
// 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 (!file->package().empty()) {
|
||||
vars["Package"].append(".");
|
||||
}
|
||||
if (!params.services_namespace.empty()) {
|
||||
vars["ns"] = params.services_namespace + "::";
|
||||
vars["prefix"] = params.services_namespace;
|
||||
@@ -1779,8 +1804,8 @@ grpc::string GetSourceServices(grpc_generator::File *file,
|
||||
return output;
|
||||
}
|
||||
|
||||
grpc::string GetSourceEpilogue(grpc_generator::File *file,
|
||||
const Parameters & /*params*/) {
|
||||
grpc::string GetSourceEpilogue(grpc_generator::File* file,
|
||||
const Parameters& /*params*/) {
|
||||
grpc::string temp;
|
||||
|
||||
if (!file->package().empty()) {
|
||||
@@ -1797,8 +1822,8 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file,
|
||||
return temp;
|
||||
}
|
||||
|
||||
grpc::string GetMockPrologue(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetMockPrologue(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -1824,18 +1849,18 @@ grpc::string GetMockPrologue(grpc_generator::File *file,
|
||||
}
|
||||
|
||||
// TODO(mmukhi): Add client-stream and completion-queue headers.
|
||||
grpc::string GetMockIncludes(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetMockIncludes(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
auto printer = file->CreatePrinter(&output);
|
||||
std::map<grpc::string, grpc::string> vars;
|
||||
|
||||
static const char *headers_strs[] = {
|
||||
"grpcpp/impl/codegen/async_stream.h",
|
||||
"grpcpp/impl/codegen/sync_stream.h",
|
||||
"gmock/gmock.h",
|
||||
static const char* headers_strs[] = {
|
||||
"grpcpp/impl/codegen/async_stream.h",
|
||||
"grpcpp/impl/codegen/sync_stream.h",
|
||||
"gmock/gmock.h",
|
||||
};
|
||||
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
|
||||
PrintIncludes(printer.get(), headers, params);
|
||||
@@ -1856,9 +1881,9 @@ grpc::string GetMockIncludes(grpc_generator::File *file,
|
||||
|
||||
namespace {
|
||||
|
||||
static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
const grpc_generator::Method *method,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
static void PrintMockClientMethods(grpc_generator::Printer* printer,
|
||||
const grpc_generator::Method* method,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Method"] = method->name();
|
||||
(*vars)["Request"] = method->input_type_name();
|
||||
(*vars)["Response"] = method->output_type_name();
|
||||
@@ -1867,8 +1892,7 @@ static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
grpc::string prefix;
|
||||
grpc::string method_params; // extra arguments to method
|
||||
int extra_method_param_count;
|
||||
} async_prefixes[] = { { "Async", ", void* tag", 1 },
|
||||
{ "PrepareAsync", "", 0 } };
|
||||
} async_prefixes[] = {{"Async", ", void* tag", 1}, {"PrepareAsync", "", 0}};
|
||||
|
||||
if (method->NoStreaming()) {
|
||||
printer->Print(
|
||||
@@ -1877,7 +1901,7 @@ static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
"const $Request$& request, $Response$* response));\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
printer->Print(
|
||||
*vars,
|
||||
@@ -1894,7 +1918,7 @@ static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
"(::grpc::ClientContext* context, $Response$* response));\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["MockArgs"] =
|
||||
@@ -1913,7 +1937,7 @@ static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
"(::grpc::ClientContext* context, const $Request$& request));\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["MockArgs"] =
|
||||
@@ -1933,7 +1957,7 @@ static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
"(::grpc::ClientContext* context));\n");
|
||||
for (size_t i = 0; i < sizeof(async_prefixes) / sizeof(async_prefixes[0]);
|
||||
i++) {
|
||||
auto &async_prefix = async_prefixes[i];
|
||||
auto& async_prefix = async_prefixes[i];
|
||||
(*vars)["AsyncPrefix"] = async_prefix.prefix;
|
||||
(*vars)["AsyncMethodParams"] = async_prefix.method_params;
|
||||
(*vars)["MockArgs"] =
|
||||
@@ -1948,9 +1972,9 @@ static void PrintMockClientMethods(grpc_generator::Printer *printer,
|
||||
}
|
||||
}
|
||||
|
||||
static void PrintMockService(grpc_generator::Printer *printer,
|
||||
const grpc_generator::Service *service,
|
||||
std::map<grpc::string, grpc::string> *vars) {
|
||||
static void PrintMockService(grpc_generator::Printer* printer,
|
||||
const grpc_generator::Service* service,
|
||||
std::map<grpc::string, grpc::string>* vars) {
|
||||
(*vars)["Service"] = service->name();
|
||||
|
||||
printer->Print(*vars,
|
||||
@@ -1966,8 +1990,8 @@ static void PrintMockService(grpc_generator::Printer *printer,
|
||||
|
||||
} // namespace
|
||||
|
||||
grpc::string GetMockServices(grpc_generator::File *file,
|
||||
const Parameters ¶ms) {
|
||||
grpc::string GetMockServices(grpc_generator::File* file,
|
||||
const Parameters& params) {
|
||||
grpc::string output;
|
||||
{
|
||||
// Scope the output stream so it closes and finalizes output to the string.
|
||||
@@ -1976,7 +2000,9 @@ grpc::string GetMockServices(grpc_generator::File *file,
|
||||
// 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 (!file->package().empty()) {
|
||||
vars["Package"].append(".");
|
||||
}
|
||||
|
||||
if (!params.services_namespace.empty()) {
|
||||
vars["services_namespace"] = params.services_namespace;
|
||||
@@ -1995,8 +2021,8 @@ grpc::string GetMockServices(grpc_generator::File *file,
|
||||
return output;
|
||||
}
|
||||
|
||||
grpc::string GetMockEpilogue(grpc_generator::File *file,
|
||||
const Parameters & /*params*/) {
|
||||
grpc::string GetMockEpilogue(grpc_generator::File* file,
|
||||
const Parameters& /*params*/) {
|
||||
grpc::string temp;
|
||||
|
||||
if (!file->package().empty()) {
|
||||
|
||||
Reference in New Issue
Block a user