diff options
-rw-r--r-- | grpc/examples/generate.sh | 12 | ||||
-rw-r--r-- | grpc/examples/swift/Greeter/Package.swift (renamed from tests/FlatBuffers.GRPC.Swift/Package.swift) | 4 | ||||
-rw-r--r-- | grpc/examples/swift/Greeter/README.md (renamed from tests/FlatBuffers.GRPC.Swift/README.md) | 0 | ||||
-rw-r--r-- | grpc/examples/swift/Greeter/Sources/Model/greeter.grpc.swift (renamed from tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.grpc.swift) | 72 | ||||
-rw-r--r-- | grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift | 70 | ||||
-rw-r--r-- | grpc/examples/swift/Greeter/Sources/client/main.swift (renamed from tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift) | 25 | ||||
-rw-r--r-- | grpc/examples/swift/Greeter/Sources/server/main.swift (renamed from tests/FlatBuffers.GRPC.Swift/Sources/server/main.swift) | 38 | ||||
-rw-r--r-- | tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.fbs | 17 | ||||
-rw-r--r-- | tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter_generated.swift | 107 | ||||
-rwxr-xr-x | tests/FlatBuffers.Test.Swift/SwiftTest.sh | 4 | ||||
-rwxr-xr-x | tests/generate_code.sh | 4 |
11 files changed, 147 insertions, 206 deletions
diff --git a/grpc/examples/generate.sh b/grpc/examples/generate.sh index e70f28d6..0d2a900d 100644 --- a/grpc/examples/generate.sh +++ b/grpc/examples/generate.sh @@ -15,12 +15,18 @@ cd go/ cd greeter fbc --go ${generator} -cd ../.. +cd ${current_dir} + +cd swift/ + +cd Greeter/Sources/Model +fbc --swift ${generator} + +cd ${current_dir} cd ts/ cd greeter/src fbc --ts ${generator} -cd .. -cd ../..
\ No newline at end of file +cd ${current_dir}
\ No newline at end of file diff --git a/tests/FlatBuffers.GRPC.Swift/Package.swift b/grpc/examples/swift/Greeter/Package.swift index 5692439d..385b56fc 100644 --- a/tests/FlatBuffers.GRPC.Swift/Package.swift +++ b/grpc/examples/swift/Greeter/Package.swift @@ -18,13 +18,13 @@ import PackageDescription let package = Package( - name: "FlatBuffers.GRPC.Swift", + name: "Greeter", platforms: [ .iOS(.v11), .macOS(.v10_14), ], dependencies: [ - .package(path: "../../swift"), + .package(path: "../../../../swift"), .package(url: "https://github.com/grpc/grpc-swift.git", .exact("1.0.0-alpha.24")), ], targets: [ diff --git a/tests/FlatBuffers.GRPC.Swift/README.md b/grpc/examples/swift/Greeter/README.md index 1632b783..1632b783 100644 --- a/tests/FlatBuffers.GRPC.Swift/README.md +++ b/grpc/examples/swift/Greeter/README.md diff --git a/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.grpc.swift b/grpc/examples/swift/Greeter/Sources/Model/greeter.grpc.swift index aacffe5c..0f29f195 100644 --- a/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.grpc.swift +++ b/grpc/examples/swift/Greeter/Sources/Model/greeter.grpc.swift @@ -23,36 +23,36 @@ public extension GRPCFlatBufPayload { } extension Message: GRPCFlatBufPayload {} -/// Usage: instantiate GreeterServiceClient, then call methods of this protocol to make API calls. -public protocol GreeterClientProtocol: GRPCClient { +/// Usage: instantiate models_GreeterServiceClient, then call methods of this protocol to make API calls. +public protocol models_GreeterClientProtocol: GRPCClient { var serviceName: String { get } - var interceptors: GreeterClientInterceptorFactoryProtocol? { get } + var interceptors: models_GreeterClientInterceptorFactoryProtocol? { get } func SayHello( - _ request: Message<HelloRequest> + _ request: Message<models_HelloRequest> , callOptions: CallOptions? - ) -> UnaryCall<Message<HelloRequest>, Message<HelloReply>> + ) -> UnaryCall<Message<models_HelloRequest>, Message<models_HelloReply>> func SayManyHellos( - _ request: Message<ManyHellosRequest> + _ request: Message<models_HelloRequest> , callOptions: CallOptions?, - handler: @escaping (Message<HelloReply>) -> Void - ) -> ServerStreamingCall<Message<ManyHellosRequest>, Message<HelloReply>> + handler: @escaping (Message<models_HelloReply>) -> Void + ) -> ServerStreamingCall<Message<models_HelloRequest>, Message<models_HelloReply>> } -extension GreeterClientProtocol { +extension models_GreeterClientProtocol { - public var serviceName: String { "Greeter" } + public var serviceName: String { "models.Greeter" } public func SayHello( - _ request: Message<HelloRequest> + _ request: Message<models_HelloRequest> , callOptions: CallOptions? = nil - ) -> UnaryCall<Message<HelloRequest>, Message<HelloReply>> { + ) -> UnaryCall<Message<models_HelloRequest>, Message<models_HelloReply>> { return self.makeUnaryCall( - path: "/Greeter/SayHello", + path: "/models.Greeter/SayHello", request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeSayHelloInterceptors() ?? [] @@ -60,12 +60,12 @@ extension GreeterClientProtocol { } public func SayManyHellos( - _ request: Message<ManyHellosRequest> + _ request: Message<models_HelloRequest> , callOptions: CallOptions? = nil, - handler: @escaping (Message<HelloReply>) -> Void - ) -> ServerStreamingCall<Message<ManyHellosRequest>, Message<HelloReply>> { + handler: @escaping (Message<models_HelloReply>) -> Void + ) -> ServerStreamingCall<Message<models_HelloRequest>, Message<models_HelloReply>> { return self.makeServerStreamingCall( - path: "/Greeter/SayManyHellos", + path: "/models.Greeter/SayManyHellos", request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeSayManyHellosInterceptors() ?? [], @@ -74,24 +74,24 @@ extension GreeterClientProtocol { } } -public protocol GreeterClientInterceptorFactoryProtocol { +public protocol models_GreeterClientInterceptorFactoryProtocol { /// - Returns: Interceptors to use when invoking 'SayHello'. - func makeSayHelloInterceptors() -> [ClientInterceptor<Message<HelloRequest>, Message<HelloReply>>] + func makeSayHelloInterceptors() -> [ClientInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>] /// - Returns: Interceptors to use when invoking 'SayManyHellos'. - func makeSayManyHellosInterceptors() -> [ClientInterceptor<Message<ManyHellosRequest>, Message<HelloReply>>] + func makeSayManyHellosInterceptors() -> [ClientInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>] } -public final class GreeterServiceClient: GreeterClientProtocol { +public final class models_GreeterServiceClient: models_GreeterClientProtocol { public let channel: GRPCChannel public var defaultCallOptions: CallOptions - public var interceptors: GreeterClientInterceptorFactoryProtocol? + public var interceptors: models_GreeterClientInterceptorFactoryProtocol? public init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), - interceptors: GreeterClientInterceptorFactoryProtocol? = nil + interceptors: models_GreeterClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self.defaultCallOptions = defaultCallOptions @@ -99,31 +99,31 @@ public final class GreeterServiceClient: GreeterClientProtocol { } } -public protocol GreeterProvider: CallHandlerProvider { - var interceptors: GreeterServerInterceptorFactoryProtocol? { get } - func SayHello(request: Message<HelloRequest>, context: StatusOnlyCallContext) -> EventLoopFuture<Message<HelloReply>> - func SayManyHellos(request: Message<ManyHellosRequest>, context: StreamingResponseCallContext<Message<HelloReply>>) -> EventLoopFuture<GRPCStatus> +public protocol models_GreeterProvider: CallHandlerProvider { + var interceptors: models_GreeterServerInterceptorFactoryProtocol? { get } + func SayHello(request: Message<models_HelloRequest>, context: StatusOnlyCallContext) -> EventLoopFuture<Message<models_HelloReply>> + func SayManyHellos(request: Message<models_HelloRequest>, context: StreamingResponseCallContext<Message<models_HelloReply>>) -> EventLoopFuture<GRPCStatus> } -public extension GreeterProvider { +public extension models_GreeterProvider { - var serviceName: Substring { return "Greeter" } + var serviceName: Substring { return "models.Greeter" } func handle(method name: Substring, context: CallHandlerContext) -> GRPCServerHandlerProtocol? { switch name { case "SayHello": return UnaryServerHandler( context: context, - requestDeserializer: GRPCPayloadDeserializer<Message<HelloRequest>>(), - responseSerializer: GRPCPayloadSerializer<Message<HelloReply>>(), + requestDeserializer: GRPCPayloadDeserializer<Message<models_HelloRequest>>(), + responseSerializer: GRPCPayloadSerializer<Message<models_HelloReply>>(), interceptors: self.interceptors?.makeSayHelloInterceptors() ?? [], userFunction: self.SayHello(request:context:)) case "SayManyHellos": return ServerStreamingServerHandler( context: context, - requestDeserializer: GRPCPayloadDeserializer<Message<ManyHellosRequest>>(), - responseSerializer: GRPCPayloadSerializer<Message<HelloReply>>(), + requestDeserializer: GRPCPayloadDeserializer<Message<models_HelloRequest>>(), + responseSerializer: GRPCPayloadSerializer<Message<models_HelloReply>>(), interceptors: self.interceptors?.makeSayManyHellosInterceptors() ?? [], userFunction: self.SayManyHellos(request:context:)) @@ -133,13 +133,13 @@ public extension GreeterProvider { } -public protocol GreeterServerInterceptorFactoryProtocol { +public protocol models_GreeterServerInterceptorFactoryProtocol { /// - Returns: Interceptors to use when handling 'SayHello'. /// Defaults to calling `self.makeInterceptors()`. - func makeSayHelloInterceptors() -> [ServerInterceptor<Message<HelloRequest>, Message<HelloReply>>] + func makeSayHelloInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>] /// - Returns: Interceptors to use when handling 'SayManyHellos'. /// Defaults to calling `self.makeInterceptors()`. - func makeSayManyHellosInterceptors() -> [ServerInterceptor<Message<ManyHellosRequest>, Message<HelloReply>>] + func makeSayManyHellosInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>] } diff --git a/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift b/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift new file mode 100644 index 00000000..4021e958 --- /dev/null +++ b/grpc/examples/swift/Greeter/Sources/Model/greeter_generated.swift @@ -0,0 +1,70 @@ +// automatically generated by the FlatBuffers compiler, do not modify +// swiftlint:disable all +// swiftformat:disable all + +import FlatBuffers + +public struct models_HelloReply: FlatBufferObject { + + static func validateVersion() { FlatBuffersVersion_1_12_0() } + public var __buffer: ByteBuffer! { return _accessor.bb } + private var _accessor: Table + + public static func getRootAsHelloReply(bb: ByteBuffer) -> models_HelloReply { return models_HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } + + private init(_ t: Table) { _accessor = t } + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } + + private enum VTOFFSET: VOffset { + case message = 4 + var v: Int32 { Int32(self.rawValue) } + var p: VOffset { self.rawValue } + } + + public var message: String? { let o = _accessor.offset(VTOFFSET.message.v); return o == 0 ? nil : _accessor.string(at: o) } + public var messageSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.message.v) } + public static func startHelloReply(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } + public static func add(message: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: message, at: VTOFFSET.message.p) } + public static func endHelloReply(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } + public static func createHelloReply( + _ fbb: inout FlatBufferBuilder, + messageOffset message: Offset<String> = Offset() + ) -> Offset<UOffset> { + let __start = models_HelloReply.startHelloReply(&fbb) + models_HelloReply.add(message: message, &fbb) + return models_HelloReply.endHelloReply(&fbb, start: __start) + } +} + +public struct models_HelloRequest: FlatBufferObject { + + static func validateVersion() { FlatBuffersVersion_1_12_0() } + public var __buffer: ByteBuffer! { return _accessor.bb } + private var _accessor: Table + + public static func getRootAsHelloRequest(bb: ByteBuffer) -> models_HelloRequest { return models_HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } + + private init(_ t: Table) { _accessor = t } + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } + + private enum VTOFFSET: VOffset { + case name = 4 + var v: Int32 { Int32(self.rawValue) } + var p: VOffset { self.rawValue } + } + + public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) } + public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) } + public static func startHelloRequest(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } + public static func add(name: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) } + public static func endHelloRequest(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } + public static func createHelloRequest( + _ fbb: inout FlatBufferBuilder, + nameOffset name: Offset<String> = Offset() + ) -> Offset<UOffset> { + let __start = models_HelloRequest.startHelloRequest(&fbb) + models_HelloRequest.add(name: name, &fbb) + return models_HelloRequest.endHelloRequest(&fbb, start: __start) + } +} + diff --git a/tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift b/grpc/examples/swift/Greeter/Sources/client/main.swift index dac26a32..a6b11300 100644 --- a/tests/FlatBuffers.GRPC.Swift/Sources/client/main.swift +++ b/grpc/examples/swift/Greeter/Sources/client/main.swift @@ -27,33 +27,34 @@ LoggingSystem.bootstrap { return handler } -func greet(name: String, client greeter: GreeterServiceClient) { +func greet(name: String, client greeter: models_GreeterServiceClient) { // Form the request with the name, if one was provided. var builder = FlatBufferBuilder() - let name = builder.create(string: name) - let root = HelloRequest.createHelloRequest(&builder, offsetOfName: name) + let nameOff = builder.create(string: name) + let root = models_HelloRequest.createHelloRequest( + &builder, + nameOffset: nameOff) builder.finish(offset: root) // Make the RPC call to the server. - let sayHello = greeter.SayHello(Message<HelloRequest>(builder: &builder)) + let sayHello = greeter.SayHello(Message<models_HelloRequest>(builder: &builder)) // wait() on the response to stop the program from exiting before the response is received. do { let response = try sayHello.response.wait() - print("Greeter received: \(response.object.message)") + print("Greeter SayHello received: \(response.object.message ?? "Unknown")") } catch { print("Greeter failed: \(error)") } - let surname = builder.create(string: "Name") - let manyRoot = ManyHellosRequest.createManyHellosRequest( + let surname = builder.create(string: name) + let manyRoot = models_HelloRequest.createHelloRequest( &builder, - offsetOfName: surname, - numGreetings: 2) + nameOffset: surname) builder.finish(offset: manyRoot) let call = greeter.SayManyHellos(Message(builder: &builder)) { message in - print(message.object.message) + print("Greeter SayManyHellos received: \(message.object.message ?? "Unknown")") } let status = try! call.status.recover { _ in .processingError }.wait() @@ -94,10 +95,10 @@ func main(args: [String]) { } // Provide the connection to the generated client. - let greeter = GreeterServiceClient(channel: channel) + let greeter = models_GreeterServiceClient(channel: channel) // Do the greeting. - greet(name: name ?? "Hello FlatBuffers!", client: greeter) + greet(name: name ?? "FlatBuffers!", client: greeter) } } diff --git a/tests/FlatBuffers.GRPC.Swift/Sources/server/main.swift b/grpc/examples/swift/Greeter/Sources/server/main.swift index d5274c1b..af1c5557 100644 --- a/tests/FlatBuffers.GRPC.Swift/Sources/server/main.swift +++ b/grpc/examples/swift/Greeter/Sources/server/main.swift @@ -20,43 +20,39 @@ import Logging import Model import NIO -class Greeter: GreeterProvider { +class Greeter: models_GreeterProvider { - var interceptors: GreeterServerInterceptorFactoryProtocol? + var interceptors: models_GreeterServerInterceptorFactoryProtocol? - var hellos: [Message<HelloReply>] = [] + let greetings: [String] init() { - let names = ["Stranger1", "Stranger2", "Stranger4", "Stranger3", "Stranger5", "Stranger6"] - for name in names { - var builder = FlatBufferBuilder() - let off = builder.create(string: name) - let root = HelloReply.createHelloReply(&builder, offsetOfMessage: off) - builder.finish(offset: root) - hellos.append(Message(builder: &builder)) - } + greetings = ["Hi", "Hallo", "Ciao"] } func SayHello( - request: Message<HelloRequest>, - context: StatusOnlyCallContext) -> EventLoopFuture<Message<HelloReply>> + request: Message<models_HelloRequest>, + context: StatusOnlyCallContext) -> EventLoopFuture<Message<models_HelloReply>> { let recipient = request.object.name ?? "Stranger" var builder = FlatBufferBuilder() - let off = builder.create(string: recipient) - let root = HelloReply.createHelloReply(&builder, offsetOfMessage: off) + let off = builder.create(string: "Hello \(recipient)") + let root = models_HelloReply.createHelloReply(&builder, messageOffset: off) builder.finish(offset: root) - return context.eventLoop.makeSucceededFuture(Message<HelloReply>(builder: &builder)) + return context.eventLoop.makeSucceededFuture(Message<models_HelloReply>(builder: &builder)) } func SayManyHellos( - request: Message<ManyHellosRequest>, - context: StreamingResponseCallContext<Message<HelloReply>>) -> EventLoopFuture<GRPCStatus> + request: Message<models_HelloRequest>, + context: StreamingResponseCallContext<Message<models_HelloReply>>) -> EventLoopFuture<GRPCStatus> { - for _ in 0..<Int(request.object.numGreetings) { - let index = Int.random(in: 0..<hellos.count) - _ = context.sendResponse(hellos[index]) + for name in greetings { + var builder = FlatBufferBuilder() + let off = builder.create(string: "\(name) \(request.object.name ?? "Unknown")") + let root = models_HelloReply.createHelloReply(&builder, messageOffset: off) + builder.finish(offset: root) + _ = context.sendResponse(Message<models_HelloReply>(builder: &builder)) } return context.eventLoop.makeSucceededFuture(.ok) } diff --git a/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.fbs b/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.fbs deleted file mode 100644 index 811303c9..00000000 --- a/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter.fbs +++ /dev/null @@ -1,17 +0,0 @@ -table HelloReply { - message:string; -} - -table HelloRequest { - name:string; -} - -table ManyHellosRequest { - name:string; - num_greetings:int; -} - -rpc_service Greeter { - SayHello(HelloRequest):HelloReply; - SayManyHellos(ManyHellosRequest):HelloReply (streaming: "server"); -} diff --git a/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter_generated.swift b/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter_generated.swift deleted file mode 100644 index 11664f5e..00000000 --- a/tests/FlatBuffers.GRPC.Swift/Sources/Model/greeter_generated.swift +++ /dev/null @@ -1,107 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify -// swiftlint:disable all -// swiftformat:disable all - -import FlatBuffers - -public struct HelloReply: FlatBufferObject { - - static func validateVersion() { FlatBuffersVersion_1_12_0() } - public var __buffer: ByteBuffer! { return _accessor.bb } - private var _accessor: Table - - public static func getRootAsHelloReply(bb: ByteBuffer) -> HelloReply { return HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } - - private init(_ t: Table) { _accessor = t } - public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } - - private enum VTOFFSET: VOffset { - case message = 4 - var v: Int32 { Int32(self.rawValue) } - var p: VOffset { self.rawValue } - } - - public var message: String? { let o = _accessor.offset(VTOFFSET.message.v); return o == 0 ? nil : _accessor.string(at: o) } - public var messageSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.message.v) } - public static func startHelloReply(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } - public static func add(message: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: message, at: VTOFFSET.message.p) } - public static func endHelloReply(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } - public static func createHelloReply( - _ fbb: inout FlatBufferBuilder, - messageOffset message: Offset<String> = Offset() - ) -> Offset<UOffset> { - let __start = HelloReply.startHelloReply(&fbb) - HelloReply.add(message: message, &fbb) - return HelloReply.endHelloReply(&fbb, start: __start) - } -} - -public struct HelloRequest: FlatBufferObject { - - static func validateVersion() { FlatBuffersVersion_1_12_0() } - public var __buffer: ByteBuffer! { return _accessor.bb } - private var _accessor: Table - - public static func getRootAsHelloRequest(bb: ByteBuffer) -> HelloRequest { return HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } - - private init(_ t: Table) { _accessor = t } - public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } - - private enum VTOFFSET: VOffset { - case name = 4 - var v: Int32 { Int32(self.rawValue) } - var p: VOffset { self.rawValue } - } - - public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) } - public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) } - public static func startHelloRequest(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } - public static func add(name: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) } - public static func endHelloRequest(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } - public static func createHelloRequest( - _ fbb: inout FlatBufferBuilder, - nameOffset name: Offset<String> = Offset() - ) -> Offset<UOffset> { - let __start = HelloRequest.startHelloRequest(&fbb) - HelloRequest.add(name: name, &fbb) - return HelloRequest.endHelloRequest(&fbb, start: __start) - } -} - -public struct ManyHellosRequest: FlatBufferObject { - - static func validateVersion() { FlatBuffersVersion_1_12_0() } - public var __buffer: ByteBuffer! { return _accessor.bb } - private var _accessor: Table - - public static func getRootAsManyHellosRequest(bb: ByteBuffer) -> ManyHellosRequest { return ManyHellosRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } - - private init(_ t: Table) { _accessor = t } - public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } - - private enum VTOFFSET: VOffset { - case name = 4 - case numGreetings = 6 - var v: Int32 { Int32(self.rawValue) } - var p: VOffset { self.rawValue } - } - - public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) } - public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) } - public var numGreetings: Int32 { let o = _accessor.offset(VTOFFSET.numGreetings.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) } - public static func startManyHellosRequest(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) } - public static func add(name: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) } - public static func add(numGreetings: Int32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: numGreetings, def: 0, at: VTOFFSET.numGreetings.p) } - public static func endManyHellosRequest(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } - public static func createManyHellosRequest( - _ fbb: inout FlatBufferBuilder, - nameOffset name: Offset<String> = Offset(), - numGreetings: Int32 = 0 - ) -> Offset<UOffset> { - let __start = ManyHellosRequest.startManyHellosRequest(&fbb) - ManyHellosRequest.add(name: name, &fbb) - ManyHellosRequest.add(numGreetings: numGreetings, &fbb) - return ManyHellosRequest.endManyHellosRequest(&fbb, start: __start) - } -} - diff --git a/tests/FlatBuffers.Test.Swift/SwiftTest.sh b/tests/FlatBuffers.Test.Swift/SwiftTest.sh index 7b907be5..06b2d6f1 100755 --- a/tests/FlatBuffers.Test.Swift/SwiftTest.sh +++ b/tests/FlatBuffers.Test.Swift/SwiftTest.sh @@ -3,10 +3,6 @@ cd .. test_dir=`pwd` alias fbc='${test_dir}/../flatc' -cd FlatBuffers.GRPC.Swift/Sources/Model -fbc --swift --grpc greeter.fbs -cd ${test_dir} - cd ${swift_dir}/Tests/FlatBuffers.Test.SwiftTests fbc --swift --gen-mutable --grpc --gen-object-api -I ${test_dir}/include_test ${test_dir}/monster_test.fbs ${test_dir}/union_vector/union_vector.fbs fbc --swift ${test_dir}/optional_scalars.fbs diff --git a/tests/generate_code.sh b/tests/generate_code.sh index a308611c..baa70e72 100755 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -75,10 +75,6 @@ $working_dir/../flatc --swift ${working_dir}/optional_scalars.fbs $working_dir/../flatc --swift --gen-object-api ${working_dir}/more_defaults.fbs cd $working_dir -cd FlatBuffers.GRPC.Swift/Sources/Model -$working_dir/../flatc --swift --grpc greeter.fbs -cd $working_dir - # Tests if the --filename-suffix and --filename-ext works and produces the same # outputs. ../flatc --cpp --filename-suffix _suffix --filename-ext hpp $TEST_NOINCL_FLAGS $TEST_CPP_FLAGS -I include_test monster_test.fbs |