route_guide.grpc.swift 8.3 KB

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