route_guide.grpc.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 GRPC
  23. import NIO
  24. import SwiftProtobuf
  25. /// Interface exported by the server.
  26. ///
  27. /// Usage: instantiate `Routeguide_RouteGuideClient`, then call methods of this protocol to make API calls.
  28. public protocol Routeguide_RouteGuideClientProtocol: GRPCClient {
  29. var serviceName: String { get }
  30. var interceptors: Routeguide_RouteGuideClientInterceptorFactoryProtocol? { get }
  31. func getFeature(
  32. _ request: Routeguide_Point,
  33. callOptions: CallOptions?
  34. ) -> UnaryCall<Routeguide_Point, Routeguide_Feature>
  35. func listFeatures(
  36. _ request: Routeguide_Rectangle,
  37. callOptions: CallOptions?,
  38. handler: @escaping (Routeguide_Feature) -> Void
  39. ) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature>
  40. func recordRoute(
  41. callOptions: CallOptions?
  42. ) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary>
  43. func routeChat(
  44. callOptions: CallOptions?,
  45. handler: @escaping (Routeguide_RouteNote) -> Void
  46. ) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote>
  47. }
  48. extension Routeguide_RouteGuideClientProtocol {
  49. public var serviceName: String {
  50. return "routeguide.RouteGuide"
  51. }
  52. /// A simple RPC.
  53. ///
  54. /// Obtains the feature at a given position.
  55. ///
  56. /// A feature with an empty name is returned if there's no feature at the given
  57. /// position.
  58. ///
  59. /// - Parameters:
  60. /// - request: Request to send to GetFeature.
  61. /// - callOptions: Call options.
  62. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  63. public func getFeature(
  64. _ request: Routeguide_Point,
  65. callOptions: CallOptions? = nil
  66. ) -> UnaryCall<Routeguide_Point, Routeguide_Feature> {
  67. return self.makeUnaryCall(
  68. path: "/routeguide.RouteGuide/GetFeature",
  69. request: request,
  70. callOptions: callOptions ?? self.defaultCallOptions,
  71. interceptors: self.interceptors?.makeGetFeatureInterceptors() ?? []
  72. )
  73. }
  74. /// A server-to-client streaming RPC.
  75. ///
  76. /// Obtains the Features available within the given Rectangle. Results are
  77. /// streamed rather than returned at once (e.g. in a response message with a
  78. /// repeated field), as the rectangle may cover a large area and contain a
  79. /// huge number of features.
  80. ///
  81. /// - Parameters:
  82. /// - request: Request to send to ListFeatures.
  83. /// - callOptions: Call options.
  84. /// - handler: A closure called when each response is received from the server.
  85. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  86. public func listFeatures(
  87. _ request: Routeguide_Rectangle,
  88. callOptions: CallOptions? = nil,
  89. handler: @escaping (Routeguide_Feature) -> Void
  90. ) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature> {
  91. return self.makeServerStreamingCall(
  92. path: "/routeguide.RouteGuide/ListFeatures",
  93. request: request,
  94. callOptions: callOptions ?? self.defaultCallOptions,
  95. interceptors: self.interceptors?.makeListFeaturesInterceptors() ?? [],
  96. handler: handler
  97. )
  98. }
  99. /// A client-to-server streaming RPC.
  100. ///
  101. /// Accepts a stream of Points on a route being traversed, returning a
  102. /// RouteSummary when traversal is completed.
  103. ///
  104. /// Callers should use the `send` method on the returned object to send messages
  105. /// to the server. The caller should send an `.end` after the final message has been sent.
  106. ///
  107. /// - Parameters:
  108. /// - callOptions: Call options.
  109. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  110. public func recordRoute(
  111. callOptions: CallOptions? = nil
  112. ) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary> {
  113. return self.makeClientStreamingCall(
  114. path: "/routeguide.RouteGuide/RecordRoute",
  115. callOptions: callOptions ?? self.defaultCallOptions,
  116. interceptors: self.interceptors?.makeRecordRouteInterceptors() ?? []
  117. )
  118. }
  119. /// A Bidirectional streaming RPC.
  120. ///
  121. /// Accepts a stream of RouteNotes sent while a route is being traversed,
  122. /// while receiving other RouteNotes (e.g. from other users).
  123. ///
  124. /// Callers should use the `send` method on the returned object to send messages
  125. /// to the server. The caller should send an `.end` after the final message has been sent.
  126. ///
  127. /// - Parameters:
  128. /// - callOptions: Call options.
  129. /// - handler: A closure called when each response is received from the server.
  130. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  131. public func routeChat(
  132. callOptions: CallOptions? = nil,
  133. handler: @escaping (Routeguide_RouteNote) -> Void
  134. ) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote> {
  135. return self.makeBidirectionalStreamingCall(
  136. path: "/routeguide.RouteGuide/RouteChat",
  137. callOptions: callOptions ?? self.defaultCallOptions,
  138. interceptors: self.interceptors?.makeRouteChatInterceptors() ?? [],
  139. handler: handler
  140. )
  141. }
  142. }
  143. public protocol Routeguide_RouteGuideClientInterceptorFactoryProtocol {
  144. /// - Returns: Interceptors to use when invoking 'getFeature'.
  145. func makeGetFeatureInterceptors() -> [ClientInterceptor<Routeguide_Point, Routeguide_Feature>]
  146. /// - Returns: Interceptors to use when invoking 'listFeatures'.
  147. func makeListFeaturesInterceptors() -> [ClientInterceptor<Routeguide_Rectangle, Routeguide_Feature>]
  148. /// - Returns: Interceptors to use when invoking 'recordRoute'.
  149. func makeRecordRouteInterceptors() -> [ClientInterceptor<Routeguide_Point, Routeguide_RouteSummary>]
  150. /// - Returns: Interceptors to use when invoking 'routeChat'.
  151. func makeRouteChatInterceptors() -> [ClientInterceptor<Routeguide_RouteNote, Routeguide_RouteNote>]
  152. }
  153. public final class Routeguide_RouteGuideClient: Routeguide_RouteGuideClientProtocol {
  154. public let channel: GRPCChannel
  155. public var defaultCallOptions: CallOptions
  156. public var interceptors: Routeguide_RouteGuideClientInterceptorFactoryProtocol?
  157. /// Creates a client for the routeguide.RouteGuide service.
  158. ///
  159. /// - Parameters:
  160. /// - channel: `GRPCChannel` to the service host.
  161. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  162. /// - interceptors: A factory providing interceptors for each RPC.
  163. public init(
  164. channel: GRPCChannel,
  165. defaultCallOptions: CallOptions = CallOptions(),
  166. interceptors: Routeguide_RouteGuideClientInterceptorFactoryProtocol? = nil
  167. ) {
  168. self.channel = channel
  169. self.defaultCallOptions = defaultCallOptions
  170. self.interceptors = interceptors
  171. }
  172. }
  173. /// Interface exported by the server.
  174. ///
  175. /// To build a server, implement a class that conforms to this protocol.
  176. public protocol Routeguide_RouteGuideProvider: CallHandlerProvider {
  177. var interceptors: Routeguide_RouteGuideServerInterceptorFactoryProtocol? { get }
  178. /// A simple RPC.
  179. ///
  180. /// Obtains the feature at a given position.
  181. ///
  182. /// A feature with an empty name is returned if there's no feature at the given
  183. /// position.
  184. func getFeature(request: Routeguide_Point, context: StatusOnlyCallContext) -> EventLoopFuture<Routeguide_Feature>
  185. /// A server-to-client streaming RPC.
  186. ///
  187. /// Obtains the Features available within the given Rectangle. Results are
  188. /// streamed rather than returned at once (e.g. in a response message with a
  189. /// repeated field), as the rectangle may cover a large area and contain a
  190. /// huge number of features.
  191. func listFeatures(request: Routeguide_Rectangle, context: StreamingResponseCallContext<Routeguide_Feature>) -> EventLoopFuture<GRPCStatus>
  192. /// A client-to-server streaming RPC.
  193. ///
  194. /// Accepts a stream of Points on a route being traversed, returning a
  195. /// RouteSummary when traversal is completed.
  196. func recordRoute(context: UnaryResponseCallContext<Routeguide_RouteSummary>) -> EventLoopFuture<(StreamEvent<Routeguide_Point>) -> Void>
  197. /// A Bidirectional streaming RPC.
  198. ///
  199. /// Accepts a stream of RouteNotes sent while a route is being traversed,
  200. /// while receiving other RouteNotes (e.g. from other users).
  201. func routeChat(context: StreamingResponseCallContext<Routeguide_RouteNote>) -> EventLoopFuture<(StreamEvent<Routeguide_RouteNote>) -> Void>
  202. }
  203. extension Routeguide_RouteGuideProvider {
  204. public var serviceName: Substring { return "routeguide.RouteGuide" }
  205. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  206. /// Returns nil for methods not handled by this service.
  207. public func handle(
  208. method name: Substring,
  209. context: CallHandlerContext
  210. ) -> GRPCServerHandlerProtocol? {
  211. switch name {
  212. case "GetFeature":
  213. return UnaryServerHandler(
  214. context: context,
  215. requestDeserializer: ProtobufDeserializer<Routeguide_Point>(),
  216. responseSerializer: ProtobufSerializer<Routeguide_Feature>(),
  217. interceptors: self.interceptors?.makeGetFeatureInterceptors() ?? [],
  218. userFunction: self.getFeature(request:context:)
  219. )
  220. case "ListFeatures":
  221. return ServerStreamingServerHandler(
  222. context: context,
  223. requestDeserializer: ProtobufDeserializer<Routeguide_Rectangle>(),
  224. responseSerializer: ProtobufSerializer<Routeguide_Feature>(),
  225. interceptors: self.interceptors?.makeListFeaturesInterceptors() ?? [],
  226. userFunction: self.listFeatures(request:context:)
  227. )
  228. case "RecordRoute":
  229. return ClientStreamingServerHandler(
  230. context: context,
  231. requestDeserializer: ProtobufDeserializer<Routeguide_Point>(),
  232. responseSerializer: ProtobufSerializer<Routeguide_RouteSummary>(),
  233. interceptors: self.interceptors?.makeRecordRouteInterceptors() ?? [],
  234. observerFactory: self.recordRoute(context:)
  235. )
  236. case "RouteChat":
  237. return BidirectionalStreamingServerHandler(
  238. context: context,
  239. requestDeserializer: ProtobufDeserializer<Routeguide_RouteNote>(),
  240. responseSerializer: ProtobufSerializer<Routeguide_RouteNote>(),
  241. interceptors: self.interceptors?.makeRouteChatInterceptors() ?? [],
  242. observerFactory: self.routeChat(context:)
  243. )
  244. default:
  245. return nil
  246. }
  247. }
  248. }
  249. public protocol Routeguide_RouteGuideServerInterceptorFactoryProtocol {
  250. /// - Returns: Interceptors to use when handling 'getFeature'.
  251. /// Defaults to calling `self.makeInterceptors()`.
  252. func makeGetFeatureInterceptors() -> [ServerInterceptor<Routeguide_Point, Routeguide_Feature>]
  253. /// - Returns: Interceptors to use when handling 'listFeatures'.
  254. /// Defaults to calling `self.makeInterceptors()`.
  255. func makeListFeaturesInterceptors() -> [ServerInterceptor<Routeguide_Rectangle, Routeguide_Feature>]
  256. /// - Returns: Interceptors to use when handling 'recordRoute'.
  257. /// Defaults to calling `self.makeInterceptors()`.
  258. func makeRecordRouteInterceptors() -> [ServerInterceptor<Routeguide_Point, Routeguide_RouteSummary>]
  259. /// - Returns: Interceptors to use when handling 'routeChat'.
  260. /// Defaults to calling `self.makeInterceptors()`.
  261. func makeRouteChatInterceptors() -> [ServerInterceptor<Routeguide_RouteNote, Routeguide_RouteNote>]
  262. }