echo.grpc.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. public 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. public 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. public 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. public 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. public 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. public 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. public 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. public final class Echo_EchoClient: Echo_EchoClientProtocol {
  136. public let channel: GRPCChannel
  137. public var defaultCallOptions: CallOptions
  138. public 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. public 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. public final class Echo_EchoTestClient: Echo_EchoClientProtocol {
  156. private let fakeChannel: FakeChannel
  157. public var defaultCallOptions: CallOptions
  158. public var interceptors: Echo_EchoClientInterceptorFactoryProtocol?
  159. public var channel: GRPCChannel {
  160. return self.fakeChannel
  161. }
  162. public init(
  163. fakeChannel: FakeChannel = FakeChannel(),
  164. defaultCallOptions callOptions: CallOptions = CallOptions(),
  165. interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil
  166. ) {
  167. self.fakeChannel = fakeChannel
  168. self.defaultCallOptions = callOptions
  169. self.interceptors = interceptors
  170. }
  171. /// Make a unary response for the Get RPC. This must be called
  172. /// before calling 'get'. See also 'FakeUnaryResponse'.
  173. ///
  174. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  175. public func makeGetResponseStream(
  176. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  177. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  178. return self.fakeChannel.makeFakeUnaryResponse(path: "/echo.Echo/Get", requestHandler: requestHandler)
  179. }
  180. public func enqueueGetResponse(
  181. _ response: Echo_EchoResponse,
  182. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  183. ) {
  184. let stream = self.makeGetResponseStream(requestHandler)
  185. // This is the only operation on the stream; try! is fine.
  186. try! stream.sendMessage(response)
  187. }
  188. /// Returns true if there are response streams enqueued for 'Get'
  189. public var hasGetResponsesRemaining: Bool {
  190. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Get")
  191. }
  192. /// Make a streaming response for the Expand RPC. This must be called
  193. /// before calling 'expand'. See also 'FakeStreamingResponse'.
  194. ///
  195. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  196. public func makeExpandResponseStream(
  197. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  198. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  199. return self.fakeChannel.makeFakeStreamingResponse(path: "/echo.Echo/Expand", requestHandler: requestHandler)
  200. }
  201. public func enqueueExpandResponses(
  202. _ responses: [Echo_EchoResponse],
  203. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  204. ) {
  205. let stream = self.makeExpandResponseStream(requestHandler)
  206. // These are the only operation on the stream; try! is fine.
  207. responses.forEach { try! stream.sendMessage($0) }
  208. try! stream.sendEnd()
  209. }
  210. /// Returns true if there are response streams enqueued for 'Expand'
  211. public var hasExpandResponsesRemaining: Bool {
  212. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Expand")
  213. }
  214. /// Make a unary response for the Collect RPC. This must be called
  215. /// before calling 'collect'. See also 'FakeUnaryResponse'.
  216. ///
  217. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  218. public func makeCollectResponseStream(
  219. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  220. ) -> FakeUnaryResponse<Echo_EchoRequest, Echo_EchoResponse> {
  221. return self.fakeChannel.makeFakeUnaryResponse(path: "/echo.Echo/Collect", requestHandler: requestHandler)
  222. }
  223. public func enqueueCollectResponse(
  224. _ response: Echo_EchoResponse,
  225. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  226. ) {
  227. let stream = self.makeCollectResponseStream(requestHandler)
  228. // This is the only operation on the stream; try! is fine.
  229. try! stream.sendMessage(response)
  230. }
  231. /// Returns true if there are response streams enqueued for 'Collect'
  232. public var hasCollectResponsesRemaining: Bool {
  233. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Collect")
  234. }
  235. /// Make a streaming response for the Update RPC. This must be called
  236. /// before calling 'update'. See also 'FakeStreamingResponse'.
  237. ///
  238. /// - Parameter requestHandler: a handler for request parts sent by the RPC.
  239. public func makeUpdateResponseStream(
  240. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  241. ) -> FakeStreamingResponse<Echo_EchoRequest, Echo_EchoResponse> {
  242. return self.fakeChannel.makeFakeStreamingResponse(path: "/echo.Echo/Update", requestHandler: requestHandler)
  243. }
  244. public func enqueueUpdateResponses(
  245. _ responses: [Echo_EchoResponse],
  246. _ requestHandler: @escaping (FakeRequestPart<Echo_EchoRequest>) -> () = { _ in }
  247. ) {
  248. let stream = self.makeUpdateResponseStream(requestHandler)
  249. // These are the only operation on the stream; try! is fine.
  250. responses.forEach { try! stream.sendMessage($0) }
  251. try! stream.sendEnd()
  252. }
  253. /// Returns true if there are response streams enqueued for 'Update'
  254. public var hasUpdateResponsesRemaining: Bool {
  255. return self.fakeChannel.hasFakeResponseEnqueued(forPath: "/echo.Echo/Update")
  256. }
  257. }
  258. /// To build a server, implement a class that conforms to this protocol.
  259. public protocol Echo_EchoProvider: CallHandlerProvider {
  260. var interceptors: Echo_EchoServerInterceptorFactoryProtocol? { get }
  261. /// Immediately returns an echo of a request.
  262. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  263. /// Splits a request into words and returns each word in a stream of messages.
  264. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  265. /// Collects a stream of messages and returns them concatenated when the caller closes.
  266. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  267. /// Streams back messages as they are received in an input stream.
  268. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  269. }
  270. extension Echo_EchoProvider {
  271. public var serviceName: Substring { return "echo.Echo" }
  272. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  273. /// Returns nil for methods not handled by this service.
  274. public func handle(
  275. method name: Substring,
  276. context: CallHandlerContext
  277. ) -> GRPCServerHandlerProtocol? {
  278. switch name {
  279. case "Get":
  280. return UnaryServerHandler(
  281. context: context,
  282. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  283. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  284. interceptors: self.interceptors?.makeGetInterceptors() ?? [],
  285. userFunction: self.get(request:context:)
  286. )
  287. case "Expand":
  288. return ServerStreamingServerHandler(
  289. context: context,
  290. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  291. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  292. interceptors: self.interceptors?.makeExpandInterceptors() ?? [],
  293. userFunction: self.expand(request:context:)
  294. )
  295. case "Collect":
  296. return ClientStreamingServerHandler(
  297. context: context,
  298. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  299. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  300. interceptors: self.interceptors?.makeCollectInterceptors() ?? [],
  301. observerFactory: self.collect(context:)
  302. )
  303. case "Update":
  304. return BidirectionalStreamingServerHandler(
  305. context: context,
  306. requestDeserializer: ProtobufDeserializer<Echo_EchoRequest>(),
  307. responseSerializer: ProtobufSerializer<Echo_EchoResponse>(),
  308. interceptors: self.interceptors?.makeUpdateInterceptors() ?? [],
  309. observerFactory: self.update(context:)
  310. )
  311. default:
  312. return nil
  313. }
  314. }
  315. }
  316. public protocol Echo_EchoServerInterceptorFactoryProtocol {
  317. /// - Returns: Interceptors to use when handling 'get'.
  318. /// Defaults to calling `self.makeInterceptors()`.
  319. func makeGetInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  320. /// - Returns: Interceptors to use when handling 'expand'.
  321. /// Defaults to calling `self.makeInterceptors()`.
  322. func makeExpandInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  323. /// - Returns: Interceptors to use when handling 'collect'.
  324. /// Defaults to calling `self.makeInterceptors()`.
  325. func makeCollectInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  326. /// - Returns: Interceptors to use when handling 'update'.
  327. /// Defaults to calling `self.makeInterceptors()`.
  328. func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>]
  329. }