route_guide.grpc.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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_RouteGuideServiceClient, then call methods of this protocol to make API calls.
  28. public protocol Routeguide_RouteGuideService {
  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_RouteGuideServiceClient: GRPCClient, Routeguide_RouteGuideService {
  35. public let connection: ClientConnection
  36. public var defaultCallOptions: CallOptions
  37. /// Creates a client for the routeguide.RouteGuide service.
  38. ///
  39. /// - Parameters:
  40. /// - connection: `ClientConnection` to the service host.
  41. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them.
  42. public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
  43. self.connection = connection
  44. self.defaultCallOptions = defaultCallOptions
  45. }
  46. /// Asynchronous unary call to GetFeature.
  47. ///
  48. /// - Parameters:
  49. /// - request: Request to send to GetFeature.
  50. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  51. /// - Returns: A `UnaryCall` with futures for the metadata, status and response.
  52. public func getFeature(_ request: Routeguide_Point, callOptions: CallOptions? = nil) -> UnaryCall<Routeguide_Point, Routeguide_Feature> {
  53. return self.makeUnaryCall(path: "/routeguide.RouteGuide/GetFeature",
  54. request: request,
  55. callOptions: callOptions ?? self.defaultCallOptions)
  56. }
  57. /// Asynchronous server-streaming call to ListFeatures.
  58. ///
  59. /// - Parameters:
  60. /// - request: Request to send to ListFeatures.
  61. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  62. /// - handler: A closure called when each response is received from the server.
  63. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
  64. public func listFeatures(_ request: Routeguide_Rectangle, callOptions: CallOptions? = nil, handler: @escaping (Routeguide_Feature) -> Void) -> ServerStreamingCall<Routeguide_Rectangle, Routeguide_Feature> {
  65. return self.makeServerStreamingCall(path: "/routeguide.RouteGuide/ListFeatures",
  66. request: request,
  67. callOptions: callOptions ?? self.defaultCallOptions,
  68. handler: handler)
  69. }
  70. /// Asynchronous client-streaming call to RecordRoute.
  71. ///
  72. /// Callers should use the `send` method on the returned object to send messages
  73. /// to the server. The caller should send an `.end` after the final message has been sent.
  74. ///
  75. /// - Parameters:
  76. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  77. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response.
  78. public func recordRoute(callOptions: CallOptions? = nil) -> ClientStreamingCall<Routeguide_Point, Routeguide_RouteSummary> {
  79. return self.makeClientStreamingCall(path: "/routeguide.RouteGuide/RecordRoute",
  80. callOptions: callOptions ?? self.defaultCallOptions)
  81. }
  82. /// Asynchronous bidirectional-streaming call to RouteChat.
  83. ///
  84. /// Callers should use the `send` method on the returned object to send messages
  85. /// to the server. The caller should send an `.end` after the final message has been sent.
  86. ///
  87. /// - Parameters:
  88. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
  89. /// - handler: A closure called when each response is received from the server.
  90. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
  91. public func routeChat(callOptions: CallOptions? = nil, handler: @escaping (Routeguide_RouteNote) -> Void) -> BidirectionalStreamingCall<Routeguide_RouteNote, Routeguide_RouteNote> {
  92. return self.makeBidirectionalStreamingCall(path: "/routeguide.RouteGuide/RouteChat",
  93. callOptions: callOptions ?? self.defaultCallOptions,
  94. handler: handler)
  95. }
  96. }
  97. /// To build a server, implement a class that conforms to this protocol.
  98. public protocol Routeguide_RouteGuideProvider: CallHandlerProvider {
  99. func getFeature(request: Routeguide_Point, context: StatusOnlyCallContext) -> EventLoopFuture<Routeguide_Feature>
  100. func listFeatures(request: Routeguide_Rectangle, context: StreamingResponseCallContext<Routeguide_Feature>) -> EventLoopFuture<GRPCStatus>
  101. func recordRoute(context: UnaryResponseCallContext<Routeguide_RouteSummary>) -> EventLoopFuture<(StreamEvent<Routeguide_Point>) -> Void>
  102. func routeChat(context: StreamingResponseCallContext<Routeguide_RouteNote>) -> EventLoopFuture<(StreamEvent<Routeguide_RouteNote>) -> Void>
  103. }
  104. extension Routeguide_RouteGuideProvider {
  105. public var serviceName: String { return "routeguide.RouteGuide" }
  106. /// Determines, calls and returns the appropriate request handler, depending on the request's method.
  107. /// Returns nil for methods not handled by this service.
  108. public func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
  109. switch methodName {
  110. case "GetFeature":
  111. return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
  112. return { request in
  113. self.getFeature(request: request, context: context)
  114. }
  115. }
  116. case "ListFeatures":
  117. return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  118. return { request in
  119. self.listFeatures(request: request, context: context)
  120. }
  121. }
  122. case "RecordRoute":
  123. return ClientStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  124. return self.recordRoute(context: context)
  125. }
  126. case "RouteChat":
  127. return BidirectionalStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
  128. return self.routeChat(context: context)
  129. }
  130. default: return nil
  131. }
  132. }
  133. }