route_guide.grpc.swift 8.7 KB

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