Debian Codegraph @

examples/python/data_transmission/demo_pb2_grpc.py

raw
1 # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2 """Client and server classes corresponding to protobuf-defined services."""
3 import grpc
4
5 import demo_pb2 as demo__pb2
6
7
8 class GRPCDemoStub(object):
9 """`service` 是用来给gRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
10 `service` is used to define methods for gRPC services in a fixed format, similar to defining
11 an interface in Golang
12 """
13
14 def __init__(self, channel):
15 """Constructor.
16
17 Args:
18 channel: A grpc.Channel.
19 """
20 self.SimpleMethod = channel.unary_unary(
21 '/demo.GRPCDemo/SimpleMethod',
22 request_serializer=demo__pb2.Request.SerializeToString,
23 response_deserializer=demo__pb2.Response.FromString,
24 )
25 self.ClientStreamingMethod = channel.stream_unary(
26 '/demo.GRPCDemo/ClientStreamingMethod',
27 request_serializer=demo__pb2.Request.SerializeToString,
28 response_deserializer=demo__pb2.Response.FromString,
29 )
30 self.ServerStreamingMethod = channel.unary_stream(
31 '/demo.GRPCDemo/ServerStreamingMethod',
32 request_serializer=demo__pb2.Request.SerializeToString,
33 response_deserializer=demo__pb2.Response.FromString,
34 )
35 self.BidirectionalStreamingMethod = channel.stream_stream(
36 '/demo.GRPCDemo/BidirectionalStreamingMethod',
37 request_serializer=demo__pb2.Request.SerializeToString,
38 response_deserializer=demo__pb2.Response.FromString,
39 )
40
41
42 class GRPCDemoServicer(object):
43 """`service` 是用来给gRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
44 `service` is used to define methods for gRPC services in a fixed format, similar to defining
45 an interface in Golang
46 """
47
48 def SimpleMethod(self, request, context):
49 """一元模式(在一次调用中, 客户端只能向服务器传输一次请求数据, 服务器也只能返回一次响应)
50 unary-unary(In a single call, the client can only send request once, and the server can
51 only respond once.)
52 """
53 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
54 context.set_details('Method not implemented!')
55 raise NotImplementedError('Method not implemented!')
56
57 def ClientStreamingMethod(self, request_iterator, context):
58 """客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
59 stream-unary (In a single call, the client can transfer data to the server several times,
60 but the server can only return a response once.)
61 """
62 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
63 context.set_details('Method not implemented!')
64 raise NotImplementedError('Method not implemented!')
65
66 def ServerStreamingMethod(self, request, context):
67 """服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应)
68 unary-stream (In a single call, the client can only transmit data to the server at one time,
69 but the server can return the response many times.)
70 """
71 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
72 context.set_details('Method not implemented!')
73 raise NotImplementedError('Method not implemented!')
74
75 def BidirectionalStreamingMethod(self, request_iterator, context):
76 """双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
77 stream-stream (In a single call, both client and server can send and receive data
78 to each other multiple times.)
79 """
80 context.set_code(grpc.StatusCode.UNIMPLEMENTED)
81 context.set_details('Method not implemented!')
82 raise NotImplementedError('Method not implemented!')
83
84
85 def add_GRPCDemoServicer_to_server(servicer, server):
86 rpc_method_handlers = {
87 'SimpleMethod': grpc.unary_unary_rpc_method_handler(
88 servicer.SimpleMethod,
89 request_deserializer=demo__pb2.Request.FromString,
90 response_serializer=demo__pb2.Response.SerializeToString,
91 ),
92 'ClientStreamingMethod': grpc.stream_unary_rpc_method_handler(
93 servicer.ClientStreamingMethod,
94 request_deserializer=demo__pb2.Request.FromString,
95 response_serializer=demo__pb2.Response.SerializeToString,
96 ),
97 'ServerStreamingMethod': grpc.unary_stream_rpc_method_handler(
98 servicer.ServerStreamingMethod,
99 request_deserializer=demo__pb2.Request.FromString,
100 response_serializer=demo__pb2.Response.SerializeToString,
101 ),
102 'BidirectionalStreamingMethod': grpc.stream_stream_rpc_method_handler(
103 servicer.BidirectionalStreamingMethod,
104 request_deserializer=demo__pb2.Request.FromString,
105 response_serializer=demo__pb2.Response.SerializeToString,
106 ),
107 }
108 generic_handler = grpc.method_handlers_generic_handler(
109 'demo.GRPCDemo', rpc_method_handlers)
110 server.add_generic_rpc_handlers((generic_handler,))
111
112
113 # This class is part of an EXPERIMENTAL API.
114 class GRPCDemo(object):
115 """`service` 是用来给gRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
116 `service` is used to define methods for gRPC services in a fixed format, similar to defining
117 an interface in Golang
118 """
119
120 @staticmethod
121 def SimpleMethod(request,
122 target,
123 options=(),
124 channel_credentials=None,
125 call_credentials=None,
126 insecure=False,
127 compression=None,
128 wait_for_ready=None,
129 timeout=None,
130 metadata=None):
131 return grpc.experimental.unary_unary(request, target, '/demo.GRPCDemo/SimpleMethod',
132 demo__pb2.Request.SerializeToString,
133 demo__pb2.Response.FromString,
134 options, channel_credentials,
135 insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
136
137 @staticmethod
138 def ClientStreamingMethod(request_iterator,
139 target,
140 options=(),
141 channel_credentials=None,
142 call_credentials=None,
143 insecure=False,
144 compression=None,
145 wait_for_ready=None,
146 timeout=None,
147 metadata=None):
148 return grpc.experimental.stream_unary(request_iterator, target, '/demo.GRPCDemo/ClientStreamingMethod',
149 demo__pb2.Request.SerializeToString,
150 demo__pb2.Response.FromString,
151 options, channel_credentials,
152 insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
153
154 @staticmethod
155 def ServerStreamingMethod(request,
156 target,
157 options=(),
158 channel_credentials=None,
159 call_credentials=None,
160 insecure=False,
161 compression=None,
162 wait_for_ready=None,
163 timeout=None,
164 metadata=None):
165 return grpc.experimental.unary_stream(request, target, '/demo.GRPCDemo/ServerStreamingMethod',
166 demo__pb2.Request.SerializeToString,
167 demo__pb2.Response.FromString,
168 options, channel_credentials,
169 insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
170
171 @staticmethod
172 def BidirectionalStreamingMethod(request_iterator,
173 target,
174 options=(),
175 channel_credentials=None,
176 call_credentials=None,
177 insecure=False,
178 compression=None,
179 wait_for_ready=None,
180 timeout=None,
181 metadata=None):
182 return grpc.experimental.stream_stream(request_iterator, target, '/demo.GRPCDemo/BidirectionalStreamingMethod',
183 demo__pb2.Request.SerializeToString,
184 demo__pb2.Response.FromString,
185 options, channel_credentials,
186 insecure, call_credentials, compression, wait_for_ready, timeout, metadata)