echo.grpc.swift 7.0 KB

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