2
0

echo.grpc.swift 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //
  2. // DO NOT EDIT.
  3. // swift-format-ignore-file
  4. //
  5. // Generated by the protocol buffer compiler.
  6. // Source: echo.proto
  7. //
  8. import GRPC
  9. import NIO
  10. import SwiftProtobuf
  11. /// Usage: instantiate `Echo_EchoClient`, then call methods of this protocol to make API calls.
  12. internal protocol Echo_EchoClientProtocol: GRPCClient {
  13. var serviceName: String { get }
  14. var interceptors: Echo_EchoClientInterceptorFactoryProtocol? { get }
  15. func get(
  16. _ request: Echo_EchoRequest,
  17. callOptions: CallOptions?
  18. ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse>
  19. func expand(
  20. _ request: Echo_EchoRequest,
  21. callOptions: CallOptions?,
  22. handler: @escaping (Echo_EchoResponse) -> Void
  23. ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  24. func collect(
  25. callOptions: CallOptions?
  26. ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  27. func update(
  28. callOptions: CallOptions?,
  29. handler: @escaping (Echo_EchoResponse) -> Void
  30. ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse>
  31. }
  32. extension Echo_EchoClientProtocol {
  33. internal var serviceName: String {
  34. return "echo.Echo"
  35. }
  36. /// Immediately returns an echo of a request.
  37. ///
  38. /// - Parameters:
  39. /// - request: Request to send to Get.
  40. /// - callOptions: Call options.
  41. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  42. internal func get(
  43. _ request: Echo_EchoRequest,
  44. callOptions: CallOptions? = nil
  45. ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  46. return self.makeUnaryCall(
  47. path: "/echo.Echo/Get",
  48. request: request,
  49. callOptions: callOptions ?? self.defaultCallOptions,
  50. interceptors: self.interceptors?.makeGetInterceptors() ?? []
  51. )
  52. }
  53. /// Splits a request into words and returns each word in a stream of messages.
  54. ///
  55. /// - Parameters:
  56. /// - request: Request to send to Expand.
  57. /// - callOptions: Call options.
  58. /// - handler: A closure called when each response is received from the server.
  59. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  60. internal func expand(
  61. _ request: Echo_EchoRequest,
  62. callOptions: CallOptions? = nil,
  63. handler: @escaping (Echo_EchoResponse) -> Void
  64. ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  65. return self.makeServerStreamingCall(
  66. path: "/echo.Echo/Expand",
  67. request: request,
  68. callOptions: callOptions ?? self.defaultCallOptions,
  69. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  70. handler: handler
  71. )
  72. }
  73. /// Collects a stream of messages and returns them concatenated when the caller closes.
  74. ///
  75. /// Callers should use the `send` method on the returned object to send messages
  76. /// to the server. The caller should send an `.end` after the final message has been sent.
  77. ///
  78. /// - Parameters:
  79. /// - callOptions: Call options.
  80. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  81. internal func collect(
  82. callOptions: CallOptions? = nil
  83. ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  84. return self.makeClientStreamingCall(
  85. path: "/echo.Echo/Collect",
  86. callOptions: callOptions ?? self.defaultCallOptions,
  87. interceptors: self.interceptors?.makeCollectInterceptors() ?? []
  88. )
  89. }
  90. /// Streams back messages as they are received in an input stream.
  91. ///
  92. /// Callers should use the `send` method on the returned object to send messages
  93. /// to the server. The caller should send an `.end` after the final message has been sent.
  94. ///
  95. /// - Parameters:
  96. /// - callOptions: Call options.
  97. /// - handler: A closure called when each response is received from the server.
  98. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  99. internal func update(
  100. callOptions: CallOptions? = nil,
  101. handler: @escaping (Echo_EchoResponse) -> Void
  102. ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  103. return self.makeBidirectionalStreamingCall(
  104. path: "/echo.Echo/Update",
  105. callOptions: callOptions ?? self.defaultCallOptions,
  106. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  107. handler: handler
  108. )
  109. }
  110. }
  111. internal protocol Echo_EchoClientInterceptorFactoryProtocol {
  112. /// - Returns: Interceptors to use when invoking 'get'.
  113. func makeGetInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  114. /// - Returns: Interceptors to use when invoking 'expand'.
  115. func makeExpandInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  116. /// - Returns: Interceptors to use when invoking 'collect'.
  117. func makeCollectInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  118. /// - Returns: Interceptors to use when invoking 'update'.
  119. func makeUpdateInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  120. }
  121. internal final class Echo_EchoClient: Echo_EchoClientProtocol {
  122. internal let channel: GRPCChannel
  123. internal var defaultCallOptions: CallOptions
  124. internal var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  125. /// Creates a client for the echo.Echo service.
  126. ///
  127. /// - Parameters:
  128. /// - channel: `GRPCChannel` to the service host.
  129. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  130. /// - interceptors: A factory providing interceptors for each RPC.
  131. internal init(
  132. channel: GRPCChannel,
  133. defaultCallOptions: CallOptions = CallOptions(),
  134. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  135. ) {
  136. self.channel = channel
  137. self.defaultCallOptions = defaultCallOptions
  138. self.interceptors = interceptors
  139. }
  140. }
  141. /// To build a server, implement a class that conforms to this protocol.
  142. internal protocol Echo_EchoProvider: CallHandlerProvider {
  143. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  144. /// Immediately returns an echo of a request.
  145. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  146. /// Splits a request into words and returns each word in a stream of messages.
  147. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  148. /// Collects a stream of messages and returns them concatenated when the caller closes.
  149. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  150. /// Streams back messages as they are received in an input stream.
  151. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  152. }
  153. extension Echo_EchoProvider {
  154. internal var serviceName: Substring { return "echo.Echo" }
  155. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  156. /// Returns nil for methods not handled by this service.
  157. internal func handle(
  158. method name: Substring,
  159. context: CallHandlerContext
  160. ) -> GRPCServerHandlerProtocol? {
  161. switch name {
  162. case "Get":
  163. return UnaryServerHandler(
  164. context: context,
  165. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  166. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  167. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  168. userFunction: self.get(request:context:)
  169. )
  170. case "Expand":
  171. return ServerStreamingServerHandler(
  172. context: context,
  173. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  174. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  175. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  176. userFunction: self.expand(request:context:)
  177. )
  178. case "Collect":
  179. return ClientStreamingServerHandler(
  180. context: context,
  181. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  182. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  183. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  184. observerFactory: self.collect(context:)
  185. )
  186. case "Update":
  187. return BidirectionalStreamingServerHandler(
  188. context: context,
  189. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  190. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  191. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  192. observerFactory: self.update(context:)
  193. )
  194. default:
  195. return nil
  196. }
  197. }
  198. }
  199. internal protocol Echo_EchoServerInterceptorFactoryProtocol {
  200. /// - Returns: Interceptors to use when handling 'get'.
  201. /// Defaults to calling `self.makeInterceptors()`.
  202. func makeGetInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  203. /// - Returns: Interceptors to use when handling 'expand'.
  204. /// Defaults to calling `self.makeInterceptors()`.
  205. func makeExpandInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  206. /// - Returns: Interceptors to use when handling 'collect'.
  207. /// Defaults to calling `self.makeInterceptors()`.
  208. func makeCollectInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  209. /// - Returns: Interceptors to use when handling 'update'.
  210. /// Defaults to calling `self.makeInterceptors()`.
  211. func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  212. }