demo_pb2_grpc.py 4.5 KB

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