route_guide.grpc.swift 9.4 KB

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