echo.grpc.swift 6.9 KB

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