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 |
| 4 | import Foundation |
| 5 | import GRPC |
| 6 | import NIO |
| 7 | import NIOHTTP1 |
| 8 | import FlatBuffers |
| 9 | |
| 10 | public protocol GRPCFlatBufPayload: GRPCPayload, FlatBufferGRPCMessage {} |
| 11 | public extension GRPCFlatBufPayload { |
| 12 | init(serializedByteBuffer: inout NIO.ByteBuffer) throws { |
| 13 | self.init(byteBuffer: FlatBuffers.ByteBuffer(contiguousBytes: serializedByteBuffer.readableBytesView, count: serializedByteBuffer.readableBytes)) |
| 14 | } |
| 15 | func serialize(into buffer: inout NIO.ByteBuffer) throws { |
| 16 | let buf = UnsafeRawBufferPointer(start: self.rawPointer, count: Int(self.size)) |
| 17 | buffer.writeBytes(buf) |
| 18 | } |
| 19 | } |
| 20 | extension Message: GRPCFlatBufPayload {} |
| 21 | |
| 22 | /// Usage: instantiate GreeterServiceClient, then call methods of this protocol to make API calls. |
| 23 | public protocol GreeterService { |
| 24 | func SayHello(_ request: Message<HelloRequest>, callOptions: CallOptions?) -> UnaryCall<Message<HelloRequest>,Message<HelloReply>> |
| 25 | func SayManyHellos(_ request: Message<ManyHellosRequest>, callOptions: CallOptions?, handler: @escaping (Message<HelloReply>) -> Void) -> ServerStreamingCall<Message<ManyHellosRequest>, Message<HelloReply>> |
| 26 | } |
| 27 | |
| 28 | public final class GreeterServiceClient: GRPCClient, GreeterService { |
| 29 | public let channel: GRPCChannel |
| 30 | public var defaultCallOptions: CallOptions |
| 31 | |
| 32 | public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) { |
| 33 | self.channel = channel |
| 34 | self.defaultCallOptions = defaultCallOptions |
| 35 | } |
| 36 | |
| 37 | public func SayHello(_ request: Message<HelloRequest>, callOptions: CallOptions? = nil) -> UnaryCall<Message<HelloRequest>,Message<HelloReply>> { |
| 38 | return self.makeUnaryCall(path: "/Greeter/SayHello", request: request, callOptions: callOptions ?? self.defaultCallOptions) |
| 39 | } |
| 40 | |
| 41 | public func SayManyHellos(_ request: Message<ManyHellosRequest>, callOptions: CallOptions? = nil, handler: @escaping (Message<HelloReply>) -> Void) -> ServerStreamingCall<Message<ManyHellosRequest>, Message<HelloReply>> { |
| 42 | return self.makeServerStreamingCall(path: "/Greeter/SayManyHellos", request: request, callOptions: callOptions ?? self.defaultCallOptions, handler: handler) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | public protocol GreeterProvider: CallHandlerProvider { |
| 47 | func SayHello(_ request: Message<HelloRequest>, context: StatusOnlyCallContext) -> EventLoopFuture<Message<HelloReply>> |
| 48 | func SayManyHellos(request: Message<ManyHellosRequest>, context: StreamingResponseCallContext<Message<HelloReply>>) -> EventLoopFuture<GRPCStatus> |
| 49 | } |
| 50 | |
| 51 | public extension GreeterProvider { |
| 52 | |
| 53 | var serviceName: Substring { return "Greeter" } |
| 54 | |
| 55 | func handleMethod(_ methodName: Substring, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? { |
| 56 | switch methodName { |
| 57 | case "SayHello": |
| 58 | return CallHandlerFactory.makeUnary(callHandlerContext: callHandlerContext) { context in |
| 59 | return { request in |
| 60 | self.SayHello(request, context: context) |
| 61 | } |
| 62 | } |
| 63 | case "SayManyHellos": |
| 64 | return CallHandlerFactory.makeServerStreaming(callHandlerContext: callHandlerContext) { context in |
| 65 | return { request in |
| 66 | self.SayManyHellos(request: request, context: context) |
| 67 | } |
| 68 | } |
| 69 | default: return nil; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } |
| 74 | |
| 75 | |