echo.grpc.swift 9.5 KB

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