echo.grpc.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 Foundation
  23. import GRPC
  24. import NIO
  25. import NIOHTTP1
  26. import SwiftProtobuf
  27. /// Usage: instantiate Echo_EchoClient, then call methods of this protocol to make API calls.
  28. internal protocol Echo_EchoClientProtocol: GRPCClient {
  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 func get(
  48. _ request: Echo_EchoRequest
  49. ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  50. return self.get(request, callOptions: self.defaultCallOptions)
  51. }
  52. internal func expand(
  53. _ request: Echo_EchoRequest,
  54. handler: @escaping (Echo_EchoResponse) -> Void
  55. ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  56. return self.expand(request, callOptions: self.defaultCallOptions, handler: handler)
  57. }
  58. internal func collect() -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  59. return self.collect(callOptions: self.defaultCallOptions)
  60. }
  61. internal func update(
  62. handler: @escaping (Echo_EchoResponse) -> Void
  63. ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  64. return self.update(callOptions: self.defaultCallOptions, handler: handler)
  65. }
  66. }
  67. internal final class Echo_EchoClient: Echo_EchoClientProtocol {
  68. internal let channel: GRPCChannel
  69. internal var defaultCallOptions: CallOptions
  70. /// Creates a client for the echo.Echo service.
  71. ///
  72. /// - Parameters:
  73. /// - channel: `GRPCChannel` to the service host.
  74. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  75. internal init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  76. self.channel = channel
  77. self.defaultCallOptions = defaultCallOptions
  78. }
  79. /// Immediately returns an echo of a request.
  80. ///
  81. /// - Parameters:
  82. /// - request: Request to send to Get.
  83. /// - callOptions: Call options.
  84. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  85. internal func get(
  86. _ request: Echo_EchoRequest,
  87. callOptions: CallOptions
  88. ) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  89. return self.makeUnaryCall(
  90. path: "/echo.Echo/Get",
  91. request: request,
  92. callOptions: callOptions
  93. )
  94. }
  95. /// Splits a request into words and returns each word in a stream of messages.
  96. ///
  97. /// - Parameters:
  98. /// - request: Request to send to Expand.
  99. /// - callOptions: Call options.
  100. /// - handler: A closure called when each response is received from the server.
  101. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  102. internal func expand(
  103. _ request: Echo_EchoRequest,
  104. callOptions: CallOptions,
  105. handler: @escaping (Echo_EchoResponse) -> Void
  106. ) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  107. return self.makeServerStreamingCall(
  108. path: "/echo.Echo/Expand",
  109. request: request,
  110. callOptions: callOptions,
  111. handler: handler
  112. )
  113. }
  114. /// Collects a stream of messages and returns them concatenated when the caller closes.
  115. ///
  116. /// Callers should use the `send` method on the returned object to send messages
  117. /// to the server. The caller should send an `.end` after the final message has been sent.
  118. ///
  119. /// - Parameters:
  120. /// - callOptions: Call options.
  121. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  122. internal func collect(
  123. callOptions: CallOptions
  124. ) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  125. return self.makeClientStreamingCall(
  126. path: "/echo.Echo/Collect",
  127. callOptions: callOptions
  128. )
  129. }
  130. /// Streams back messages as they are received in an input stream.
  131. ///
  132. /// Callers should use the `send` method on the returned object to send messages
  133. /// to the server. The caller should send an `.end` after the final message has been sent.
  134. ///
  135. /// - Parameters:
  136. /// - callOptions: Call options.
  137. /// - handler: A closure called when each response is received from the server.
  138. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  139. internal func update(
  140. callOptions: CallOptions,
  141. handler: @escaping (Echo_EchoResponse) -> Void
  142. ) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  143. return self.makeBidirectionalStreamingCall(
  144. path: "/echo.Echo/Update",
  145. callOptions: callOptions,
  146. handler: handler
  147. )
  148. }
  149. }
  150. /// To build a server, implement a class that conforms to this protocol.
  151. internal protocol Echo_EchoProvider: CallHandlerProvider {
  152. /// Immediately returns an echo of a request.
  153. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  154. /// Splits a request into words and returns each word in a stream of messages.
  155. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  156. /// Collects a stream of messages and returns them concatenated when the caller closes.
  157. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  158. /// Streams back messages as they are received in an input stream.
  159. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  160. }
  161. extension Echo_EchoProvider {
  162. internal var serviceName: String { return "echo.Echo" }
  163. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  164. /// Returns nil for methods not handled by this service.
  165. internal func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  166. switch methodName {
  167. case "Get":
  168. return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
  169. return { request in
  170. self.get(request: request, context: context)
  171. }
  172. }
  173. case "Expand":
  174. return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  175. return { request in
  176. self.expand(request: request, context: context)
  177. }
  178. }
  179. case "Collect":
  180. return ClientStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  181. return self.collect(context: context)
  182. }
  183. case "Update":
  184. return BidirectionalStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  185. return self.update(context: context)
  186. }
  187. default: return nil
  188. }
  189. }
  190. }
  191. // Provides conformance to `GRPCPayload`
  192. extension Echo_EchoRequest: GRPCProtobufPayload {}
  193. extension Echo_EchoResponse: GRPCProtobufPayload {}