echo.grpc.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_EchoServiceClient, then call methods of this protocol to make API calls.
  28. public protocol Echo_EchoService {
  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_EchoServiceClient: GRPCServiceClient, Echo_EchoService {
  35. public let connection: ClientConnection
  36. public var serviceName: String { return "echo.Echo" }
  37. public var defaultCallOptions: CallOptions
  38. /// Creates a client for the echo.Echo service.
  39. ///
  40. /// - Parameters:
  41. /// - connection: `ClientConnection` to the service host.
  42. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  43. public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
  44. self.connection = connection
  45. self.defaultCallOptions = defaultCallOptions
  46. }
  47. /// Asynchronous unary call to Get.
  48. ///
  49. /// - Parameters:
  50. /// - request: Request to send to Get.
  51. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  52. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  53. public func get(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil) -> UnaryCall<Echo_EchoRequest, Echo_EchoResponse> {
  54. return self.makeUnaryCall(path: self.path(forMethod: "Get"),
  55. request: request,
  56. callOptions: callOptions ?? self.defaultCallOptions)
  57. }
  58. /// Asynchronous server-streaming call to Expand.
  59. ///
  60. /// - Parameters:
  61. /// - request: Request to send to Expand.
  62. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  63. /// - handler: A closure called when each response is received from the server.
  64. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  65. public func expand(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  66. return self.makeServerStreamingCall(path: self.path(forMethod: "Expand"),
  67. request: request,
  68. callOptions: callOptions ?? self.defaultCallOptions,
  69. handler: handler)
  70. }
  71. /// Asynchronous client-streaming call to Collect.
  72. ///
  73. /// Callers should use the `send` method on the returned object to send messages
  74. /// to the server. The caller should send an `.end` after the final message has been sent.
  75. ///
  76. /// - Parameters:
  77. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  78. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  79. public func collect(callOptions: CallOptions? = nil) -> ClientStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  80. return self.makeClientStreamingCall(path: self.path(forMethod: "Collect"),
  81. callOptions: callOptions ?? self.defaultCallOptions)
  82. }
  83. /// Asynchronous bidirectional-streaming call to Update.
  84. ///
  85. /// Callers should use the `send` method on the returned object to send messages
  86. /// to the server. The caller should send an `.end` after the final message has been sent.
  87. ///
  88. /// - Parameters:
  89. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  90. /// - handler: A closure called when each response is received from the server.
  91. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  92. public func update(callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingCall<Echo_EchoRequest, Echo_EchoResponse> {
  93. return self.makeBidirectionalStreamingCall(path: self.path(forMethod: "Update"),
  94. callOptions: callOptions ?? self.defaultCallOptions,
  95. handler: handler)
  96. }
  97. }
  98. /// To build a server, implement a class that conforms to this protocol.
  99. public protocol Echo_EchoProvider: CallHandlerProvider {
  100. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Echo_EchoResponse>
  101. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<GRPCStatus>
  102. func collect(context: UnaryResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  103. func update(context: StreamingResponseCallContext<Echo_EchoResponse>) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void>
  104. }
  105. extension Echo_EchoProvider {
  106. public var serviceName: String { return "echo.Echo" }
  107. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  108. /// Returns nil for methods not handled by this service.
  109. public func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  110. switch methodName {
  111. case "Get":
  112. return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
  113. return { request in
  114. self.get(request: request, context: context)
  115. }
  116. }
  117. case "Expand":
  118. return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  119. return { request in
  120. self.expand(request: request, context: context)
  121. }
  122. }
  123. case "Collect":
  124. return ClientStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  125. return self.collect(context: context)
  126. }
  127. case "Update":
  128. return BidirectionalStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  129. return self.update(context: context)
  130. }
  131. default: return nil
  132. }
  133. }
  134. }