mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
4.5 KiB
107 lines
4.5 KiB
5 years ago
|
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
||
|
import grpc
|
||
|
|
||
5 years ago
|
import demo_pb2 as demo__pb2
|
||
5 years ago
|
|
||
|
|
||
|
class GRPCDemoStub(object):
|
||
5 years ago
|
"""service是用来给GRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
|
||
|
`service` is used to define methods for GRPC services in a fixed format, similar to defining an interface in Golang
|
||
5 years ago
|
"""
|
||
|
|
||
|
def __init__(self, channel):
|
||
|
"""Constructor.
|
||
|
|
||
|
Args:
|
||
|
channel: A grpc.Channel.
|
||
|
"""
|
||
|
self.SimpleMethod = channel.unary_unary(
|
||
|
'/demo.GRPCDemo/SimpleMethod',
|
||
|
request_serializer=demo__pb2.Request.SerializeToString,
|
||
|
response_deserializer=demo__pb2.Response.FromString,
|
||
|
)
|
||
5 years ago
|
self.ClientStreamingMethod = channel.stream_unary(
|
||
|
'/demo.GRPCDemo/ClientStreamingMethod',
|
||
5 years ago
|
request_serializer=demo__pb2.Request.SerializeToString,
|
||
|
response_deserializer=demo__pb2.Response.FromString,
|
||
|
)
|
||
5 years ago
|
self.ServerStreamingMethod = channel.unary_stream(
|
||
|
'/demo.GRPCDemo/ServerStreamingMethod',
|
||
5 years ago
|
request_serializer=demo__pb2.Request.SerializeToString,
|
||
|
response_deserializer=demo__pb2.Response.FromString,
|
||
|
)
|
||
5 years ago
|
self.BidirectionalStreamingMethod = channel.stream_stream(
|
||
|
'/demo.GRPCDemo/BidirectionalStreamingMethod',
|
||
5 years ago
|
request_serializer=demo__pb2.Request.SerializeToString,
|
||
|
response_deserializer=demo__pb2.Response.FromString,
|
||
|
)
|
||
|
|
||
|
|
||
|
class GRPCDemoServicer(object):
|
||
5 years ago
|
"""service是用来给GRPC服务定义方法的, 格式固定, 类似于Golang中定义一个接口
|
||
|
`service` is used to define methods for GRPC services in a fixed format, similar to defining an interface in Golang
|
||
5 years ago
|
"""
|
||
|
|
||
|
def SimpleMethod(self, request, context):
|
||
|
"""简单模式
|
||
5 years ago
|
unary-unary
|
||
5 years ago
|
"""
|
||
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||
|
context.set_details('Method not implemented!')
|
||
|
raise NotImplementedError('Method not implemented!')
|
||
|
|
||
5 years ago
|
def ClientStreamingMethod(self, request_iterator, context):
|
||
5 years ago
|
"""客户端流模式(在一次调用中, 客户端可以多次向服务器传输数据, 但是服务器只能返回一次响应)
|
||
5 years ago
|
stream-unary (In a single call, the client can transfer data to the server several times,
|
||
5 years ago
|
but the server can only return a response once.)
|
||
5 years ago
|
"""
|
||
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||
|
context.set_details('Method not implemented!')
|
||
|
raise NotImplementedError('Method not implemented!')
|
||
|
|
||
5 years ago
|
def ServerStreamingMethod(self, request, context):
|
||
5 years ago
|
"""服务端流模式(在一次调用中, 客户端只能一次向服务器传输数据, 但是服务器可以多次返回响应)
|
||
5 years ago
|
unary-stream (In a single call, the client can only transmit data to the server at one time,
|
||
5 years ago
|
but the server can return the response many times.)
|
||
5 years ago
|
"""
|
||
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||
|
context.set_details('Method not implemented!')
|
||
|
raise NotImplementedError('Method not implemented!')
|
||
|
|
||
5 years ago
|
def BidirectionalStreamingMethod(self, request_iterator, context):
|
||
|
"""双向流模式 (在一次调用中, 客户端和服务器都可以向对方多次收发数据)
|
||
5 years ago
|
stream-stream (In a single call, both client and server can send and receive data
|
||
5 years ago
|
to each other multiple times.)
|
||
5 years ago
|
"""
|
||
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||
|
context.set_details('Method not implemented!')
|
||
|
raise NotImplementedError('Method not implemented!')
|
||
|
|
||
|
|
||
|
def add_GRPCDemoServicer_to_server(servicer, server):
|
||
|
rpc_method_handlers = {
|
||
|
'SimpleMethod': grpc.unary_unary_rpc_method_handler(
|
||
|
servicer.SimpleMethod,
|
||
|
request_deserializer=demo__pb2.Request.FromString,
|
||
|
response_serializer=demo__pb2.Response.SerializeToString,
|
||
|
),
|
||
5 years ago
|
'ClientStreamingMethod': grpc.stream_unary_rpc_method_handler(
|
||
|
servicer.ClientStreamingMethod,
|
||
5 years ago
|
request_deserializer=demo__pb2.Request.FromString,
|
||
|
response_serializer=demo__pb2.Response.SerializeToString,
|
||
|
),
|
||
5 years ago
|
'ServerStreamingMethod': grpc.unary_stream_rpc_method_handler(
|
||
|
servicer.ServerStreamingMethod,
|
||
5 years ago
|
request_deserializer=demo__pb2.Request.FromString,
|
||
|
response_serializer=demo__pb2.Response.SerializeToString,
|
||
|
),
|
||
5 years ago
|
'BidirectionalStreamingMethod': grpc.stream_stream_rpc_method_handler(
|
||
|
servicer.BidirectionalStreamingMethod,
|
||
5 years ago
|
request_deserializer=demo__pb2.Request.FromString,
|
||
|
response_serializer=demo__pb2.Response.SerializeToString,
|
||
|
),
|
||
|
}
|
||
|
generic_handler = grpc.method_handlers_generic_handler(
|
||
|
'demo.GRPCDemo', rpc_method_handlers)
|
||
|
server.add_generic_rpc_handlers((generic_handler,))
|