route_guide.grpc.swift 8.9 KB

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