// // 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 GRPC import NIO import SwiftProtobuf /// Usage: instantiate Echo_EchoClient, then call methods of this protocol to make API calls. internal protocol Echo_EchoClientProtocol: GRPCClient { var interceptors: Echo_EchoClientInterceptorFactoryProtocol? { get } 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 } extension Echo_EchoClientProtocol { /// Immediately returns an echo of a request. /// /// - Parameters: /// - request: Request to send to Get. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func get( _ request: Echo_EchoRequest, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: "/echo.Echo/Get", request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeGetInterceptors() ?? [] ) } /// Splits a request into words and returns each word in a stream of messages. /// /// - Parameters: /// - request: Request to send to Expand. /// - 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. internal func expand( _ request: Echo_EchoRequest, callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void ) -> ServerStreamingCall { return self.makeServerStreamingCall( path: "/echo.Echo/Expand", request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeExpandInterceptors() ?? [], handler: handler ) } /// Collects a stream of messages and returns them concatenated when the caller closes. /// /// 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. internal func collect( callOptions: CallOptions? = nil ) -> ClientStreamingCall { return self.makeClientStreamingCall( path: "/echo.Echo/Collect", callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeCollectInterceptors() ?? [] ) } /// Streams back messages as they are received in an input stream. /// /// 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. internal func update( callOptions: CallOptions? = nil, handler: @escaping (Echo_EchoResponse) -> Void ) -> BidirectionalStreamingCall { return self.makeBidirectionalStreamingCall( path: "/echo.Echo/Update", callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeUpdateInterceptors() ?? [], handler: handler ) } } internal protocol Echo_EchoClientInterceptorFactoryProtocol { /// Makes an array of generic interceptors. The per-method interceptor /// factories default to calling this function and it therefore provides a /// convenient way of setting interceptors for all methods on a client. /// - Returns: An array of interceptors generic over `Request` and `Response`. /// Defaults to an empty array. func makeInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'get'. /// Defaults to calling `self.makeInterceptors()`. func makeGetInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'expand'. /// Defaults to calling `self.makeInterceptors()`. func makeExpandInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'collect'. /// Defaults to calling `self.makeInterceptors()`. func makeCollectInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'update'. /// Defaults to calling `self.makeInterceptors()`. func makeUpdateInterceptors() -> [ClientInterceptor] } extension Echo_EchoClientInterceptorFactoryProtocol { internal func makeInterceptors() -> [ClientInterceptor] { return [] } internal func makeGetInterceptors() -> [ClientInterceptor] { return self.makeInterceptors() } internal func makeExpandInterceptors() -> [ClientInterceptor] { return self.makeInterceptors() } internal func makeCollectInterceptors() -> [ClientInterceptor] { return self.makeInterceptors() } internal func makeUpdateInterceptors() -> [ClientInterceptor] { return self.makeInterceptors() } } internal final class Echo_EchoClient: Echo_EchoClientProtocol { internal let channel: GRPCChannel internal var defaultCallOptions: CallOptions internal var interceptors: Echo_EchoClientInterceptorFactoryProtocol? /// Creates a client for the echo.Echo service. /// /// - Parameters: /// - channel: `GRPCChannel` to the service host. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. /// - interceptors: A factory providing interceptors for each RPC. internal init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), interceptors: Echo_EchoClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self.defaultCallOptions = defaultCallOptions self.interceptors = interceptors } } /// To build a server, implement a class that conforms to this protocol. internal protocol Echo_EchoProvider: CallHandlerProvider { /// Immediately returns an echo of a request. func get(request: Echo_EchoRequest, context: StatusOnlyCallContext) -> EventLoopFuture /// Splits a request into words and returns each word in a stream of messages. func expand(request: Echo_EchoRequest, context: StreamingResponseCallContext) -> EventLoopFuture /// Collects a stream of messages and returns them concatenated when the caller closes. func collect(context: UnaryResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> /// Streams back messages as they are received in an input stream. func update(context: StreamingResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> } extension Echo_EchoProvider { internal var serviceName: Substring { 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. internal func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? { switch methodName { case "Get": return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in return { request in self.get(request: request, context: context) } } case "Expand": return CallHandlerFactory.makeServerStreaming(callHandlerContext: callHandlerContext) { context in return { request in self.expand(request: request, context: context) } } case "Collect": return CallHandlerFactory.makeClientStreaming(callHandlerContext: callHandlerContext) { context in return self.collect(context: context) } case "Update": return CallHandlerFactory.makeBidirectionalStreaming(callHandlerContext: callHandlerContext) { context in return self.update(context: context) } default: return nil } } }