echo.grpc.swift 9.9 KB

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