1# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2import grpc 3 4import demo_pb2 as demo__pb2 5 6 7class GRPCDemoStub(object): 8 """service是用来给GRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口 9 `service` is used to define methods for GRPC services in a fixed format, similar to defining an interface in Golang 10 """ 11 12 def __init__(self, channel): 13 """Constructor. 14 15 Args: 16 channel: A grpc.Channel. 17 """ 18 self.SimpleMethod = channel.unary_unary( 19 '/demo.GRPCDemo/SimpleMethod', 20 request_serializer=demo__pb2.Request.SerializeToString, 21 response_deserializer=demo__pb2.Response.FromString, 22 ) 23 self.ClientStreamingMethod = channel.stream_unary( 24 '/demo.GRPCDemo/ClientStreamingMethod', 25 request_serializer=demo__pb2.Request.SerializeToString, 26 response_deserializer=demo__pb2.Response.FromString, 27 ) 28 self.ServerStreamingMethod = channel.unary_stream( 29 '/demo.GRPCDemo/ServerStreamingMethod', 30 request_serializer=demo__pb2.Request.SerializeToString, 31 response_deserializer=demo__pb2.Response.FromString, 32 ) 33 self.BidirectionalStreamingMethod = channel.stream_stream( 34 '/demo.GRPCDemo/BidirectionalStreamingMethod', 35 request_serializer=demo__pb2.Request.SerializeToString, 36 response_deserializer=demo__pb2.Response.FromString, 37 ) 38 39 40class GRPCDemoServicer(object): 41 """service是用来给GRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口 42 `service` is used to define methods for GRPC services in a fixed format, similar to defining an interface in Golang 43 """ 44 45 def SimpleMethod(self, request, context): 46 """简单模式 47 unary-unary 48 """ 49 context.set_code(grpc.StatusCode.UNIMPLEMENTED) 50 context.set_details('Method not implemented!') 51 raise NotImplementedError('Method not implemented!') 52 53 def ClientStreamingMethod(self, request_iterator, context): 54 """客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应) 55 stream-unary (In a single call, the client can transfer data to the server several times, 56 but the server can only return a response once.) 57 """ 58 context.set_code(grpc.StatusCode.UNIMPLEMENTED) 59 context.set_details('Method not implemented!') 60 raise NotImplementedError('Method not implemented!') 61 62 def ServerStreamingMethod(self, request, context): 63 """服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应) 64 unary-stream (In a single call, the client can only transmit data to the server at one time, 65 but the server can return the response many times.) 66 """ 67 context.set_code(grpc.StatusCode.UNIMPLEMENTED) 68 context.set_details('Method not implemented!') 69 raise NotImplementedError('Method not implemented!') 70 71 def BidirectionalStreamingMethod(self, request_iterator, context): 72 """双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据) 73 stream-stream (In a single call, both client and server can send and receive data 74 to each other multiple times.) 75 """ 76 context.set_code(grpc.StatusCode.UNIMPLEMENTED) 77 context.set_details('Method not implemented!') 78 raise NotImplementedError('Method not implemented!') 79 80 81def add_GRPCDemoServicer_to_server(servicer, server): 82 rpc_method_handlers = { 83 'SimpleMethod': grpc.unary_unary_rpc_method_handler( 84 servicer.SimpleMethod, 85 request_deserializer=demo__pb2.Request.FromString, 86 response_serializer=demo__pb2.Response.SerializeToString, 87 ), 88 'ClientStreamingMethod': grpc.stream_unary_rpc_method_handler( 89 servicer.ClientStreamingMethod, 90 request_deserializer=demo__pb2.Request.FromString, 91 response_serializer=demo__pb2.Response.SerializeToString, 92 ), 93 'ServerStreamingMethod': grpc.unary_stream_rpc_method_handler( 94 servicer.ServerStreamingMethod, 95 request_deserializer=demo__pb2.Request.FromString, 96 response_serializer=demo__pb2.Response.SerializeToString, 97 ), 98 'BidirectionalStreamingMethod': grpc.stream_stream_rpc_method_handler( 99 servicer.BidirectionalStreamingMethod, 100 request_deserializer=demo__pb2.Request.FromString, 101 response_serializer=demo__pb2.Response.SerializeToString, 102 ), 103 } 104 generic_handler = grpc.method_handlers_generic_handler( 105 'demo.GRPCDemo', rpc_method_handlers) 106 server.add_generic_rpc_handlers((generic_handler,)) 107