route_guide.grpc.swift 11 KB

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