route_guide.grpc.swift 7.2 KB

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