diff --git a/src/compiler/protobuf_plugin.h b/src/compiler/protobuf_plugin.h index 789e4cd834c7273fb0bb56bf62e1c317c8284cee..bb77063796667b47c59138b034532fe01f91b556 100644 --- a/src/compiler/protobuf_plugin.h +++ b/src/compiler/protobuf_plugin.h @@ -92,10 +92,14 @@ class ProtoBufMethod : public grpc_generator::Method { return method_->client_streaming() && !method_->server_streaming(); } + bool python_ClientStreaming() const { return method_->client_streaming(); } + bool ServerStreaming() const { return !method_->client_streaming() && method_->server_streaming(); } + bool python_ServerStreaming() const { return method_->server_streaming(); } + bool BidiStreaming() const { return method_->client_streaming() && method_->server_streaming(); } @@ -207,4 +211,4 @@ class ProtoBufFile : public grpc_generator::File { const grpc::protobuf::FileDescriptor *file_; }; -#endif // GRPC_INTERNAL_COMPILER_PROTOBUF_PLUGIN_H \ No newline at end of file +#endif // GRPC_INTERNAL_COMPILER_PROTOBUF_PLUGIN_H diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc index 5d54d21ffe8feca6684b0649495c130a77d9c923..523fe801d18524d249e105c30e04962009592c47 100644 --- a/src/compiler/python_generator.cc +++ b/src/compiler/python_generator.cc @@ -135,7 +135,7 @@ bool PrivateGenerator::PrintBetaServicer(const grpc_generator::Service* service, for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); grpc::string arg_name = - method->ClientStreaming() ? "request_iterator" : "request"; + method->python_ClientStreaming() ? "request_iterator" : "request"; StringMap method_dict; method_dict["Method"] = method->name(); method_dict["ArgName"] = arg_name; @@ -171,7 +171,7 @@ bool PrivateGenerator::PrintBetaStub(const grpc_generator::Service* service, for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); grpc::string arg_name = - method->ClientStreaming() ? "request_iterator" : "request"; + method->python_ClientStreaming() ? "request_iterator" : "request"; StringMap method_dict; method_dict["Method"] = method->name(); method_dict["ArgName"] = arg_name; @@ -184,7 +184,7 @@ bool PrivateGenerator::PrintBetaStub(const grpc_generator::Service* service, PrintAllComments(method_comments, out); out->Print("raise NotImplementedError()\n"); } - if (!method->ServerStreaming()) { + if (!method->python_ServerStreaming()) { out->Print(method_dict, "$Method$.future = None\n"); } } @@ -215,8 +215,10 @@ bool PrivateGenerator::PrintBetaServerFactory( for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); const grpc::string method_implementation_constructor = - grpc::string(method->ClientStreaming() ? "stream_" : "unary_") + - grpc::string(method->ServerStreaming() ? "stream_" : "unary_") + + grpc::string(method->python_ClientStreaming() ? "stream_" + : "unary_") + + grpc::string(method->python_ServerStreaming() ? "stream_" + : "unary_") + "inline"; grpc::string input_message_module_and_class; if (!method->get_module_and_message_path_input( @@ -322,8 +324,9 @@ bool PrivateGenerator::PrintBetaStubFactory( for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); const grpc::string method_cardinality = - grpc::string(method->ClientStreaming() ? "STREAM" : "UNARY") + "_" + - grpc::string(method->ServerStreaming() ? "STREAM" : "UNARY"); + grpc::string(method->python_ClientStreaming() ? "STREAM" : "UNARY") + + "_" + + grpc::string(method->python_ServerStreaming() ? "STREAM" : "UNARY"); grpc::string input_message_module_and_class; if (!method->get_module_and_message_path_input( &input_message_module_and_class, generator_file_name, @@ -427,8 +430,10 @@ bool PrivateGenerator::PrintStub( for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); grpc::string multi_callable_constructor = - grpc::string(method->ClientStreaming() ? "stream" : "unary") + "_" + - grpc::string(method->ServerStreaming() ? "stream" : "unary"); + grpc::string(method->python_ClientStreaming() ? "stream" + : "unary") + + "_" + + grpc::string(method->python_ServerStreaming() ? "stream" : "unary"); grpc::string request_module_and_class; if (!method->get_module_and_message_path_input( &request_module_and_class, generator_file_name, @@ -481,7 +486,7 @@ bool PrivateGenerator::PrintServicer(const grpc_generator::Service* service, for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); grpc::string arg_name = - method->ClientStreaming() ? "request_iterator" : "request"; + method->python_ClientStreaming() ? "request_iterator" : "request"; StringMap method_dict; method_dict["Method"] = method->name(); method_dict["ArgName"] = arg_name; @@ -517,8 +522,10 @@ bool PrivateGenerator::PrintAddServicerToServer( for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); grpc::string method_handler_constructor = - grpc::string(method->ClientStreaming() ? "stream" : "unary") + "_" + - grpc::string(method->ServerStreaming() ? "stream" : "unary") + + grpc::string(method->python_ClientStreaming() ? "stream" + : "unary") + + "_" + grpc::string(method->python_ServerStreaming() ? "stream" + : "unary") + "_rpc_method_handler"; grpc::string request_module_and_class; if (!method->get_module_and_message_path_input( diff --git a/src/compiler/schema_interface.h b/src/compiler/schema_interface.h index 41e9322a0d0100ac60682b34bc9cd9e4d855615d..88de1ecdf7112047c420815021fe90e5ca8a2169 100644 --- a/src/compiler/schema_interface.h +++ b/src/compiler/schema_interface.h @@ -81,7 +81,9 @@ struct Method : public CommentHolder { virtual grpc::string get_output_type_name() const = 0; virtual bool NoStreaming() const = 0; virtual bool ClientStreaming() const = 0; + virtual bool python_ClientStreaming() const = 0; virtual bool ServerStreaming() const = 0; + virtual bool python_ServerStreaming() const = 0; virtual bool BidiStreaming() const = 0; };