echo.grpc.swift 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  53. return self.makeUnaryCall(path: "/echo.Echo/Get",
  54. request: request,
  55. callOptions: callOptions ?? self.defaultCallOptions)
  56. }
  57. /// Splits a request into words and returns each word in a stream of messages.
  58. ///
  59. /// - Parameters:
  60. /// - request: Request to send to Expand.
  61. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  62. /// - handler: A closure called when each response is received from the server.
  63. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  64. public func expand(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  65. return self.makeServerStreamingCall(path: "/echo.Echo/Expand",
  66. request: request,
  67. callOptions: callOptions ?? self.defaultCallOptions,
  68. handler: handler)
  69. }
  70. /// Collects a stream of messages and returns them concatenated when the caller closes.
  71. ///
  72. /// Callers should use the `send` method on the returned object to send messages
  73. /// to the server. The caller should send an `.end` after the final message has been sent.
  74. ///
  75. /// - Parameters:
  76. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  77. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  78. public func collect(callOptions: CallOptions? = nil) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  79. return self.makeClientStreamingCall(path: "/echo.Echo/Collect",
  80. callOptions: callOptions ?? self.defaultCallOptions)
  81. }
  82. /// Streams back messages as they are received in an input stream.
  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; `self.defaultCallOptions` is used if `nil`.
  89. /// - handler: A closure called when each response is received from the server.
  90. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  91. public func update(callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  92. return self.makeBidirectionalStreamingCall(path: "/echo.Echo/Update",
  93. callOptions: callOptions ?? self.defaultCallOptions,
  94. handler: handler)
  95. }
  96. }
  97. /// To build a server, implement a class that conforms to this protocol.
  98. public protocol Echo_EchoProvider: CallHandlerProvider {
  99. /// Immediately returns an echo of a request.
  100. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  101. /// Splits a request into words and returns each word in a stream of messages.
  102. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  103. /// Collects a stream of messages and returns them concatenated when the caller closes.
  104. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  105. /// Streams back messages as they are received in an input stream.
  106. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  107. }
  108. extension Echo_EchoProvider {
  109. public var serviceName: String { return "echo.Echo" }
  110. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  111. /// Returns nil for methods not handled by this service.
  112. public func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  113. switch methodName {
  114. case "Get":
  115. return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
  116. return { request in
  117. self.get(request: request, context: context)
  118. }
  119. }
  120. case "Expand":
  121. return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  122. return { request in
  123. self.expand(request: request, context: context)
  124. }
  125. }
  126. case "Collect":
  127. return ClientStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  128. return self.collect(context: context)
  129. }
  130. case "Update":
  131. return BidirectionalStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  132. return self.update(context: context)
  133. }
  134. default: return nil
  135. }
  136. }
  137. }
  138. // Provides conformance to `GRPCPayload` for request and response messages
  139. extension Echo_EchoRequest: GRPCProtobufPayload {}
  140. extension Echo_EchoResponse: GRPCProtobufPayload {}