blob: e4605e03d631fd613cdf01811a9178c91548d9fc [file] [log] [blame]
Austin Schuh272c6132020-11-14 16:37:52 -08001// 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 Schuh58b9b472020-11-25 19:12:44 -08004
5// swiftlint:disable all
6// swiftformat:disable all
7
Austin Schuh272c6132020-11-14 16:37:52 -08008import Foundation
9import GRPC
10import NIO
11import NIOHTTP1
12import FlatBuffers
13
14public protocol GRPCFlatBufPayload: GRPCPayload, FlatBufferGRPCMessage {}
15public extension GRPCFlatBufPayload {
Austin Schuh58b9b472020-11-25 19:12:44 -080016 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 Schuh272c6132020-11-14 16:37:52 -080023}
24extension Message: GRPCFlatBufPayload {}
25
26/// Usage: instantiate GreeterServiceClient, then call methods of this protocol to make API calls.
27public protocol GreeterService {
Austin Schuh58b9b472020-11-25 19:12:44 -080028 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 Schuh272c6132020-11-14 16:37:52 -080030}
31
32public final class GreeterServiceClient: GRPCClient, GreeterService {
Austin Schuh58b9b472020-11-25 19:12:44 -080033 public let channel: GRPCChannel
34 public var defaultCallOptions: CallOptions
Austin Schuh272c6132020-11-14 16:37:52 -080035
Austin Schuh58b9b472020-11-25 19:12:44 -080036 public init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {
37 self.channel = channel
38 self.defaultCallOptions = defaultCallOptions
39 }
Austin Schuh272c6132020-11-14 16:37:52 -080040
Austin Schuh58b9b472020-11-25 19:12:44 -080041 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 Schuh272c6132020-11-14 16:37:52 -080044
Austin Schuh58b9b472020-11-25 19:12:44 -080045 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 Schuh272c6132020-11-14 16:37:52 -080048}
49
50public protocol GreeterProvider: CallHandlerProvider {
Austin Schuh58b9b472020-11-25 19:12:44 -080051 func SayHello(_ request: Message<HelloRequest>, context: StatusOnlyCallContext) -> EventLoopFuture<Message<HelloReply>>
52 func SayManyHellos(request: Message<ManyHellosRequest>, context: StreamingResponseCallContext<Message<HelloReply>>) -> EventLoopFuture<GRPCStatus>
Austin Schuh272c6132020-11-14 16:37:52 -080053}
54
55public extension GreeterProvider {
56
Austin Schuh58b9b472020-11-25 19:12:44 -080057 var serviceName: Substring { return "Greeter" }
Austin Schuh272c6132020-11-14 16:37:52 -080058
Austin Schuh58b9b472020-11-25 19:12:44 -080059 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 Schuh272c6132020-11-14 16:37:52 -080076
77}