2
0

echo.grpc.swift 9.9 KB

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