4 import demo_pb2
as demo__pb2
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
16 channel: A grpc.Channel.
19 '/demo.GRPCDemo/SimpleMethod',
20 request_serializer=demo__pb2.Request.SerializeToString,
21 response_deserializer=demo__pb2.Response.FromString,
24 '/demo.GRPCDemo/ClientStreamingMethod',
25 request_serializer=demo__pb2.Request.SerializeToString,
26 response_deserializer=demo__pb2.Response.FromString,
29 '/demo.GRPCDemo/ServerStreamingMethod',
30 request_serializer=demo__pb2.Request.SerializeToString,
31 response_deserializer=demo__pb2.Response.FromString,
34 '/demo.GRPCDemo/BidirectionalStreamingMethod',
35 request_serializer=demo__pb2.Request.SerializeToString,
36 response_deserializer=demo__pb2.Response.FromString,
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
49 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
50 context.set_details(
'Method not implemented!')
51 raise NotImplementedError(
'Method not implemented!')
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.)
58 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
59 context.set_details(
'Method not implemented!')
60 raise NotImplementedError(
'Method not implemented!')
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.)
67 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
68 context.set_details(
'Method not implemented!')
69 raise NotImplementedError(
'Method not implemented!')
72 """双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
73 stream-stream (In a single call, both client and server can send and receive data
74 to each other multiple times.)
76 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
77 context.set_details(
'Method not implemented!')
78 raise NotImplementedError(
'Method not implemented!')
82 rpc_method_handlers = {
84 servicer.SimpleMethod,
85 request_deserializer=demo__pb2.Request.FromString,
86 response_serializer=demo__pb2.Response.SerializeToString,
89 servicer.ClientStreamingMethod,
90 request_deserializer=demo__pb2.Request.FromString,
91 response_serializer=demo__pb2.Response.SerializeToString,
94 servicer.ServerStreamingMethod,
95 request_deserializer=demo__pb2.Request.FromString,
96 response_serializer=demo__pb2.Response.SerializeToString,
99 servicer.BidirectionalStreamingMethod,
100 request_deserializer=demo__pb2.Request.FromString,
101 response_serializer=demo__pb2.Response.SerializeToString,
105 'demo.GRPCDemo', rpc_method_handlers)
106 server.add_generic_rpc_handlers((generic_handler,))