Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 1 | // Generated GRPC code for FlatBuffers swift! |
| 2 | /// The following code is generated by the Flatbuffers library which might not be in sync with grpc-swift |
| 3 | /// in case of an issue please open github issue, though it would be maintained |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 4 | |
| 5 | // swiftlint:disable all |
| 6 | // swiftformat:disable all |
| 7 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 8 | import Foundation |
| 9 | import GRPC |
| 10 | import NIO |
| 11 | import NIOHTTP1 |
| 12 | import FlatBuffers |
| 13 | |
| 14 | public protocol GRPCFlatBufPayload: GRPCPayload, FlatBufferGRPCMessage {} |
| 15 | public extension GRPCFlatBufPayload { |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 16 | init(serializedByteBuffer: inout NIO.ByteBuffer) throws { |
| 17 | self.init(byteBuffer: FlatBuffers.ByteBuffer(contiguousBytes: serializedByteBuffer.readableBytesView, count: serializedByteBuffer.readableBytes)) |
| 18 | } |
| 19 | func serialize(into buffer: inout NIO.ByteBuffer) throws { |
| 20 | let buf = UnsafeRawBufferPointer(start: self.rawPointer, count: Int(self.size)) |
| 21 | buffer.writeBytes(buf) |
| 22 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 23 | } |
| 24 | extension Message: GRPCFlatBufPayload {} |
| 25 | |
| 26 | /// Usage: instantiate GreeterServiceClient, then call methods of this protocol to make API calls. |
| 27 | public protocol GreeterService { |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 28 | func SayHello(_ request: Message<HelloRequest>, callOptions: CallOptions?) -> UnaryCall<Message<HelloRequest>,Message<HelloReply>> |
| 29 | func SayManyHellos(_ request: Message<ManyHellosRequest>, callOptions: CallOptions?, handler: @escaping (Message<HelloReply>) -> Void) -> ServerStreamingCall<Message<ManyHellosRequest>, Message<HelloReply>> |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | public final class GreeterServiceClient: GRPCClient, GreeterService { |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 33 | public let channel: GRPCChannel |
| 34 | public var defaultCallOptions: CallOptions |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 35 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 36 | public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) { |
| 37 | self.channel = channel |
| 38 | self.defaultCallOptions = defaultCallOptions |
| 39 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 40 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 41 | public func SayHello(_ request: Message<HelloRequest>, callOptions: CallOptions? = nil) -> UnaryCall<Message<HelloRequest>,Message<HelloReply>> { |
| 42 | return self.makeUnaryCall(path: "/Greeter/SayHello", request: request, callOptions: callOptions ?? self.defaultCallOptions) |
| 43 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 44 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 45 | public func SayManyHellos(_ request: Message<ManyHellosRequest>, callOptions: CallOptions? = nil, handler: @escaping (Message<HelloReply>) -> Void) -> ServerStreamingCall<Message<ManyHellosRequest>, Message<HelloReply>> { |
| 46 | return self.makeServerStreamingCall(path: "/Greeter/SayManyHellos", request: request, callOptions: callOptions ?? self.defaultCallOptions, handler: handler) |
| 47 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | public protocol GreeterProvider: CallHandlerProvider { |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 51 | func SayHello(_ request: Message<HelloRequest>, context: StatusOnlyCallContext) -> EventLoopFuture<Message<HelloReply>> |
| 52 | func SayManyHellos(request: Message<ManyHellosRequest>, context: StreamingResponseCallContext<Message<HelloReply>>) -> EventLoopFuture<GRPCStatus> |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public extension GreeterProvider { |
| 56 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 57 | var serviceName: Substring { return "Greeter" } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 58 | |
Austin Schuh | 58b9b47 | 2020-11-25 19:12:44 -0800 | [diff] [blame^] | 59 | func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? { |
| 60 | switch methodName { |
| 61 | case "SayHello": |
| 62 | return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in |
| 63 | return { request in |
| 64 | self.SayHello(request, context: context) |
| 65 | } |
| 66 | } |
| 67 | case "SayManyHellos": |
| 68 | return CallHandlerFactory.makeServerStreaming(callHandlerContext: callHandlerContext) { context in |
| 69 | return { request in |
| 70 | self.SayManyHellos(request: request, context: context) |
| 71 | } |
| 72 | } |
| 73 | default: return nil; |
| 74 | } |
| 75 | } |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 76 | |
| 77 | } |