• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     }
serializenull15     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 {
SayHellonull24 	 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 connection: ClientConnection
30 	public var defaultCallOptions: CallOptions
31 
32 	public init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {
33 		self.connection = connection
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 {
SayHellonull47 	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 	var serviceName: String { return "Greeter" }
53 	func handleMethod(_ methodName: String, callHandlerContext: CallHandlerContext) -> GRPCCallHandler? {
54 		switch methodName {
55 		case "SayHello":
56 		return UnaryCallHandler(callHandlerContext: callHandlerContext) { context in
57 			return { request in
58 				self.SayHello(request, context: context)
59 			}
60 		}
61 		case "SayManyHellos":
62 		return ServerStreamingCallHandler(callHandlerContext: callHandlerContext) { context in
63 			return { request in
64 				self.SayManyHellos(request: request, context: context)
65 			}
66 		}
67 		default: return nil;
68 		}
69 	}
70 
71 }
72 
73 
74