echo.grpc.swift 7.1 KB

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