// // DO NOT EDIT. // // Generated by the protocol buffer compiler. // Source: route_guide.proto // // // Copyright 2018, gRPC Authors All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // import Foundation import GRPC import NIO import NIOHTTP1 import SwiftProtobuf /// Usage: instantiate Routeguide_RouteGuideClient, then call methods of this protocol to make API calls. public protocol Routeguide_RouteGuideClientProtocol: GRPCClient { func getFeature( _ request: Routeguide_Point, callOptions: CallOptions? ) -> UnaryCall func listFeatures( _ request: Routeguide_Rectangle, callOptions: CallOptions?, handler: @escaping (Routeguide_Feature) -> Void ) -> ServerStreamingCall func recordRoute( callOptions: CallOptions? ) -> ClientStreamingCall func routeChat( callOptions: CallOptions?, handler: @escaping (Routeguide_RouteNote) -> Void ) -> BidirectionalStreamingCall } extension Routeguide_RouteGuideClientProtocol { /// A simple RPC. /// /// Obtains the feature at a given position. /// /// A feature with an empty name is returned if there's no feature at the given /// position. /// /// - Parameters: /// - request: Request to send to GetFeature. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. public func getFeature( _ request: Routeguide_Point, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: "/routeguide.RouteGuide/GetFeature", request: request, callOptions: callOptions ?? self.defaultCallOptions ) } /// A server-to-client streaming RPC. /// /// Obtains the Features available within the given Rectangle. Results are /// streamed rather than returned at once (e.g. in a response message with a /// repeated field), as the rectangle may cover a large area and contain a /// huge number of features. /// /// - Parameters: /// - request: Request to send to ListFeatures. /// - callOptions: Call options. /// - handler: A closure called when each response is received from the server. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. public func listFeatures( _ request: Routeguide_Rectangle, callOptions: CallOptions? = nil, handler: @escaping (Routeguide_Feature) -> Void ) -> ServerStreamingCall { return self.makeServerStreamingCall( path: "/routeguide.RouteGuide/ListFeatures", request: request, callOptions: callOptions ?? self.defaultCallOptions, handler: handler ) } /// A client-to-server streaming RPC. /// /// Accepts a stream of Points on a route being traversed, returning a /// RouteSummary when traversal is completed. /// /// Callers should use the `send` method on the returned object to send messages /// to the server. The caller should send an `.end` after the final message has been sent. /// /// - Parameters: /// - callOptions: Call options. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response. public func recordRoute( callOptions: CallOptions? = nil ) -> ClientStreamingCall { return self.makeClientStreamingCall( path: "/routeguide.RouteGuide/RecordRoute", callOptions: callOptions ?? self.defaultCallOptions ) } /// A Bidirectional streaming RPC. /// /// Accepts a stream of RouteNotes sent while a route is being traversed, /// while receiving other RouteNotes (e.g. from other users). /// /// Callers should use the `send` method on the returned object to send messages /// to the server. The caller should send an `.end` after the final message has been sent. /// /// - Parameters: /// - callOptions: Call options. /// - handler: A closure called when each response is received from the server. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status. public func routeChat( callOptions: CallOptions? = nil, handler: @escaping (Routeguide_RouteNote) -> Void ) -> BidirectionalStreamingCall { return self.makeBidirectionalStreamingCall( path: "/routeguide.RouteGuide/RouteChat", callOptions: callOptions ?? self.defaultCallOptions, handler: handler ) } } public final class Routeguide_RouteGuideClient: Routeguide_RouteGuideClientProtocol { public let channel: GRPCChannel public var defaultCallOptions: CallOptions /// Creates a client for the routeguide.RouteGuide service. /// /// - Parameters: /// - channel: `GRPCChannel` to the service host. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) { self.channel = channel self.defaultCallOptions = defaultCallOptions } } /// To build a server, implement a class that conforms to this protocol. public protocol Routeguide_RouteGuideProvider: CallHandlerProvider { /// A simple RPC. /// /// Obtains the feature at a given position. /// /// A feature with an empty name is returned if there's no feature at the given /// position. func getFeature(request: Routeguide_Point, context: StatusOnlyCallContext) -> EventLoopFuture /// A server-to-client streaming RPC. /// /// Obtains the Features available within the given Rectangle. Results are /// streamed rather than returned at once (e.g. in a response message with a /// repeated field), as the rectangle may cover a large area and contain a /// huge number of features. func listFeatures(request: Routeguide_Rectangle, context: StreamingResponseCallContext) -> EventLoopFuture /// A client-to-server streaming RPC. /// /// Accepts a stream of Points on a route being traversed, returning a /// RouteSummary when traversal is completed. func recordRoute(context: UnaryResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> /// A Bidirectional streaming RPC. /// /// Accepts a stream of RouteNotes sent while a route is being traversed, /// while receiving other RouteNotes (e.g. from other users). func routeChat(context: StreamingResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> } extension Routeguide_RouteGuideProvider { public var serviceName: Substring { return "routeguide.RouteGuide" } /// Determines, calls and returns the appropriate request handler, depending on the request's method. /// Returns nil for methods not handled by this service. public func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? { switch methodName { case "GetFeature": return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in return { request in self.getFeature(request: request, context: context) } } case "ListFeatures": return CallHandlerFactory.makeServerStreaming(callHandlerContext: callHandlerContext) { context in return { request in self.listFeatures(request: request, context: context) } } case "RecordRoute": return CallHandlerFactory.makeClientStreaming(callHandlerContext: callHandlerContext) { context in return self.recordRoute(context: context) } case "RouteChat": return CallHandlerFactory.makeBidirectionalStreaming(callHandlerContext: callHandlerContext) { context in return self.routeChat(context: context) } default: return nil } } }