echo.grpc.swift 6.9 KB

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