// // DO NOT EDIT. // // Generated by the protocol buffer compiler. // Source: echo.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 Echo_EchoServiceClient, then call methods of this protocol to make API calls. public protocol Echo_EchoService { func get(_ request: Echo_EchoRequest, callOptions: CallOptions?) -> UnaryCall func expand(_ request: Echo_EchoRequest, callOptions: CallOptions?, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingCall func collect(callOptions: CallOptions?) -> ClientStreamingCall func update(callOptions: CallOptions?, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingCall } public final class Echo_EchoServiceClient: GRPCServiceClient, Echo_EchoService { public let connection: ClientConnection public var serviceName: String { return "echo.Echo" } public var defaultCallOptions: CallOptions /// Creates a client for the echo.Echo service. /// /// - Parameters: /// - connection: `ClientConnection` to the service host. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) { self.connection = connection self.defaultCallOptions = defaultCallOptions } /// Asynchronous unary call to Get. /// /// - Parameters: /// - request: Request to send to Get. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. public func get(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil) -> UnaryCall { return self.makeUnaryCall(path: self.path(forMethod: "Get"), request: request, callOptions: callOptions ?? self.defaultCallOptions) } /// Asynchronous server-streaming call to Expand. /// /// - Parameters: /// - request: Request to send to Expand. /// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`. /// - handler: A closure called when each response is received from the server. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. public func expand(_ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> ServerStreamingCall { return self.makeServerStreamingCall(path: self.path(forMethod: "Expand"), request: request, callOptions: callOptions ?? self.defaultCallOptions, handler: handler) } /// Asynchronous client-streaming call to Collect. /// /// 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; `self.defaultCallOptions` is used if `nil`. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response. public func collect(callOptions: CallOptions? = nil) -> ClientStreamingCall { return self.makeClientStreamingCall(path: self.path(forMethod: "Collect"), callOptions: callOptions ?? self.defaultCallOptions) } /// Asynchronous bidirectional-streaming call to Update. /// /// 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; `self.defaultCallOptions` is used if `nil`. /// - handler: A closure called when each response is received from the server. /// - Returns: A `ClientStreamingCall` with futures for the metadata and status. public func update(callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void) -> BidirectionalStreamingCall { return self.makeBidirectionalStreamingCall(path: self.path(forMethod: "Update"), callOptions: callOptions ?? self.defaultCallOptions, handler: handler) } } /// To build a server, implement a class that conforms to this protocol. public protocol Echo_EchoProvider: CallHandlerProvider { func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext) -> EventLoopFuture func collect(context: UnaryResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> func update(context: StreamingResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> } extension Echo_EchoProvider { public var serviceName: String { return "echo.Echo" } /// 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: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? { switch methodName { case "Get": return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in return { request in self.get(request: request, context: context) } } case "Expand": return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in return { request in self.expand(request: request, context: context) } } case "Collect": return ClientStreamingCallHandler(callHandlerContext: callHandlerContext) { context in return self.collect(context: context) } case "Update": return BidirectionalStreamingCallHandler(callHandlerContext: callHandlerContext) { context in return self.update(context: context) } default: return nil } } }