route_guide.grpc.swift 8.3 KB

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