blob: f3c4b6755a983dabb673996a976086bc9414ea8c [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
4import Foundation
5import GRPC
6import NIO
7import NIOHTTP1
8import FlatBuffers
9
10public protocol GRPCFlatBufPayload: GRPCPayload, FlatBufferGRPCMessage {}
11public 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}
20extension Message: GRPCFlatBufPayload {}
21
22/// Usage: instantiate GreeterServiceClient, then call methods of this protocol to make API calls.
23public 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
28public 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
46public 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
51public 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