route_guide.grpc.swift 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // DO NOT EDIT.
  3. //
  4. // Generated by the protocol buffer compiler.
  5. // Source: route_guide.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 Routeguide_RouteGuideClient, then call methods of this protocol to make API calls.
  28. public protocol Routeguide_RouteGuideClientProtocol: GRPCClient {
  29. func getFeature(
  30. _ request: Routeguide_Point,
  31. callOptions: CallOptions?
  32. ) -> UnaryCall<Routeguide_Point, Routeguide_Feature>
  33. func listFeatures(
  34. _ request: Routeguide_Rectangle,
  35. callOptions: CallOptions?,
  36. handler: @escaping (Routeguide_Feature) -> Void
  37. ) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature>
  38. func recordRoute(
  39. callOptions: CallOptions?
  40. ) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary>
  41. func routeChat(
  42. callOptions: CallOptions?,
  43. handler: @escaping (Routeguide_RouteNote) -> Void
  44. ) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote>
  45. }
  46. extension Routeguide_RouteGuideClientProtocol {
  47. /// A simple RPC.
  48. ///
  49. /// Obtains the feature at a given position.
  50. ///
  51. /// A feature with an empty name is returned if there's no feature at the given
  52. /// position.
  53. ///
  54. /// - Parameters:
  55. /// - request: Request to send to GetFeature.
  56. /// - callOptions: Call options.
  57. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  58. public func getFeature(
  59. _ request: Routeguide_Point,
  60. callOptions: CallOptions? = nil
  61. ) -> UnaryCall<Routeguide_Point, Routeguide_Feature> {
  62. return self.makeUnaryCall(
  63. path: "/routeguide.RouteGuide/GetFeature",
  64. request: request,
  65. callOptions: callOptions ?? self.defaultCallOptions
  66. )
  67. }
  68. /// A server-to-client streaming RPC.
  69. ///
  70. /// Obtains the Features available within the given Rectangle. Results are
  71. /// streamed rather than returned at once (e.g. in a response message with a
  72. /// repeated field), as the rectangle may cover a large area and contain a
  73. /// huge number of features.
  74. ///
  75. /// - Parameters:
  76. /// - request: Request to send to ListFeatures.
  77. /// - callOptions: Call options.
  78. /// - handler: A closure called when each response is received from the server.
  79. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  80. public func listFeatures(
  81. _ request: Routeguide_Rectangle,
  82. callOptions: CallOptions? = nil,
  83. handler: @escaping (Routeguide_Feature) -> Void
  84. ) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature> {
  85. return self.makeServerStreamingCall(
  86. path: "/routeguide.RouteGuide/ListFeatures",
  87. request: request,
  88. callOptions: callOptions ?? self.defaultCallOptions,
  89. handler: handler
  90. )
  91. }
  92. /// A client-to-server streaming RPC.
  93. ///
  94. /// Accepts a stream of Points on a route being traversed, returning a
  95. /// RouteSummary when traversal is completed.
  96. ///
  97. /// Callers should use the `send` method on the returned object to send messages
  98. /// to the server. The caller should send an `.end` after the final message has been sent.
  99. ///
  100. /// - Parameters:
  101. /// - callOptions: Call options.
  102. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  103. public func recordRoute(
  104. callOptions: CallOptions? = nil
  105. ) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary> {
  106. return self.makeClientStreamingCall(
  107. path: "/routeguide.RouteGuide/RecordRoute",
  108. callOptions: callOptions ?? self.defaultCallOptions
  109. )
  110. }
  111. /// A Bidirectional streaming RPC.
  112. ///
  113. /// Accepts a stream of RouteNotes sent while a route is being traversed,
  114. /// while receiving other RouteNotes (e.g. from other users).
  115. ///
  116. /// Callers should use the `send` method on the returned object to send messages
  117. /// to the server. The caller should send an `.end` after the final message has been sent.
  118. ///
  119. /// - Parameters:
  120. /// - callOptions: Call options.
  121. /// - handler: A closure called when each response is received from the server.
  122. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  123. public func routeChat(
  124. callOptions: CallOptions? = nil,
  125. handler: @escaping (Routeguide_RouteNote) -> Void
  126. ) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote> {
  127. return self.makeBidirectionalStreamingCall(
  128. path: "/routeguide.RouteGuide/RouteChat",
  129. callOptions: callOptions ?? self.defaultCallOptions,
  130. handler: handler
  131. )
  132. }
  133. }
  134. public final class Routeguide_RouteGuideClient: Routeguide_RouteGuideClientProtocol {
  135. public let channel: GRPCChannel
  136. public var defaultCallOptions: CallOptions
  137. /// Creates a client for the routeguide.RouteGuide service.
  138. ///
  139. /// - Parameters:
  140. /// - channel: `GRPCChannel` to the service host.
  141. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  142. public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
  143. self.channel = channel
  144. self.defaultCallOptions = defaultCallOptions
  145. }
  146. }
  147. /// To build a server, implement a class that conforms to this protocol.
  148. public protocol Routeguide_RouteGuideProvider: CallHandlerProvider {
  149. /// A simple RPC.
  150. ///
  151. /// Obtains the feature at a given position.
  152. ///
  153. /// A feature with an empty name is returned if there's no feature at the given
  154. /// position.
  155. func getFeature(request: Routeguide_Point, context: StatusOnlyCallContext) -> EventLoopFuture<Routeguide_Feature>
  156. /// A server-to-client streaming RPC.
  157. ///
  158. /// Obtains the Features available within the given Rectangle. Results are
  159. /// streamed rather than returned at once (e.g. in a response message with a
  160. /// repeated field), as the rectangle may cover a large area and contain a
  161. /// huge number of features.
  162. func listFeatures(request: Routeguide_Rectangle, context: StreamingResponseCallContext<Routeguide_Feature>) -> EventLoopFuture<GRPCStatus>
  163. /// A client-to-server streaming RPC.
  164. ///
  165. /// Accepts a stream of Points on a route being traversed, returning a
  166. /// RouteSummary when traversal is completed.
  167. func recordRoute(context: UnaryResponseCallContext<Routeguide_RouteSummary>) -> EventLoopFuture<(StreamEvent<Routeguide_Point>) -> Void>
  168. /// A Bidirectional streaming RPC.
  169. ///
  170. /// Accepts a stream of RouteNotes sent while a route is being traversed,
  171. /// while receiving other RouteNotes (e.g. from other users).
  172. func routeChat(context: StreamingResponseCallContext<Routeguide_RouteNote>) -> EventLoopFuture<(StreamEvent<Routeguide_RouteNote>) -> Void>
  173. }
  174. extension Routeguide_RouteGuideProvider {
  175. public var serviceName: Substring { return "routeguide.RouteGuide" }
  176. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  177. /// Returns nil for methods not handled by this service.
  178. public func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  179. switch methodName {
  180. case "GetFeature":
  181. return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in
  182. return { request in
  183. self.getFeature(request: request, context: context)
  184. }
  185. }
  186. case "ListFeatures":
  187. return CallHandlerFactory.makeServerStreaming(callHandlerContext: callHandlerContext) { context in
  188. return { request in
  189. self.listFeatures(request: request, context: context)
  190. }
  191. }
  192. case "RecordRoute":
  193. return CallHandlerFactory.makeClientStreaming(callHandlerContext: callHandlerContext) { context in
  194. return self.recordRoute(context: context)
  195. }
  196. case "RouteChat":
  197. return CallHandlerFactory.makeBidirectionalStreaming(callHandlerContext: callHandlerContext) { context in
  198. return self.routeChat(context: context)
  199. }
  200. default: return nil
  201. }
  202. }
  203. }