diff options
author | mustiikhalil <mustii@mmk.one> | 2020-01-09 23:12:10 +0300 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-01-09 12:12:10 -0800 |
commit | 04d80f255d1c2fa7a466e8465a119c0eaef26d59 (patch) | |
tree | 3bbb6d92e6d006a733ba04c638d6eecce228ad9a /tests/FlatBuffers.Test.Swift | |
parent | 55686100aa6f8b4867e8de62768d8fc0ecc5a541 (diff) | |
download | flatbuffers-04d80f255d1c2fa7a466e8465a119c0eaef26d59.tar.gz flatbuffers-04d80f255d1c2fa7a466e8465a119c0eaef26d59.tar.bz2 flatbuffers-04d80f255d1c2fa7a466e8465a119c0eaef26d59.zip |
[Swift] Swift implementation 🎉🎉 (#5603)
* Implemented the swift version of Flatbuffers
Implemented serailzing, reading, and mutating data from object monster
Fixes mis-aligned pointer issue
Fixes issue when shared strings are removed from table
Adds swift enum, structs code gen
Fixed namespace issues + started implementing the table gen
Added Mutate function to the code generator
Generated linux test cases
Fixed an issue with bools, and structs readers in table writer
Swift docker image added
Updated the test cases, and removed a method parameters in swift
Fixed createVector api when called with scalars
Fixed issues with scalar arrays, and fixed the code gen namespaces, added sample_binary.swift
Cleaned up project
Added enum vectors, and their readers
Refactored code
Added swift into the support document
Added documentation in docs, and fixed a small issue with Data() not being returned correctly
Fixes Lowercase issue, and prevents generating lookups for deprecated keys
* Made all the required funcs to have const + removed unneeded code + fix lowercase func
* Removed transform from lowercased and moved it to function
* Fixes an issue with iOS allocation from read
* Refactored cpp code to be more readable
* casts position into int for position
* Fix enums issue, moves scalar writer code to use memcpy
* Removed c_str from struct function
* Fixed script to generate new objects when ran on travis ci: fix
* Handles deallocating space allocated for structs
* Updated the test cases to adhere to the fileprivate lookup, no mutation for unions, and updated the names of the vector functions
Diffstat (limited to 'tests/FlatBuffers.Test.Swift')
13 files changed, 1597 insertions, 0 deletions
diff --git a/tests/FlatBuffers.Test.Swift/Package.swift b/tests/FlatBuffers.Test.Swift/Package.swift new file mode 100644 index 00000000..bbe5a6ab --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Package.swift @@ -0,0 +1,20 @@ +// swift-tools-version:5.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "FlatBuffers.Test.Swift", + platforms: [ + .iOS(.v11), + .macOS(.v10_14), + ], + dependencies: [ + .package(path: "../../swift/") + ], + targets: [ + .testTarget( + name: "FlatBuffers.Test.SwiftTests", + dependencies: ["FlatBuffers"]), + ] +) diff --git a/tests/FlatBuffers.Test.Swift/SwiftTest.sh b/tests/FlatBuffers.Test.Swift/SwiftTest.sh new file mode 100644 index 00000000..aa8b5aca --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/SwiftTest.sh @@ -0,0 +1,10 @@ +swift_dir=`pwd` +cd .. +test_dir=`pwd` + +${test_dir}/../flatc --swift --gen-mutable -I ${test_dir}/include_test ${test_dir}/monster_test.fbs ${test_dir}/union_vector/union_vector.fbs +cd ${test_dir} +mv *_generated.swift ${swift_dir}/Tests/FlatBuffers.Test.SwiftTests +cd ${swift_dir} +swift build --build-tests +swift test
\ No newline at end of file diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift new file mode 100644 index 00000000..486cd1a4 --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift @@ -0,0 +1,190 @@ +import XCTest +import Foundation +@testable import FlatBuffers + +typealias Test1 = MyGame.Example.Test +typealias Monster1 = MyGame.Example.Monster +typealias Vec3 = MyGame.Example.Vec3 + +class FlatBuffersMonsterWriterTests: XCTestCase { + + func testData() { + let data = Data([48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]) + let _data = ByteBuffer(data: data) + readMonster(fb: _data) + } + + func testReadFromOtherLangagues() { + let path = FileManager.default.currentDirectoryPath + let url = URL(fileURLWithPath: path, isDirectory: true).appendingPathComponent("monsterdata_test").appendingPathExtension("mon") + guard let data = try? Data(contentsOf: url) else { return } + let _data = ByteBuffer(data: data) + readMonster(fb: _data) + } + + func testCreateMonster() { + let bytes = createMonster(withPrefix: false) + XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]) + readMonster(fb: bytes.buffer) + mutateMonster(fb: bytes.buffer) + readMonster(fb: bytes.buffer) + } + + func testCreateMonsterResizedBuffer() { + let bytes = createMonster(withPrefix: false) + XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]) + readMonster(fb: ByteBuffer(data: bytes.data)) + } + + func testCreateMonsterPrefixed() { + let bytes = createMonster(withPrefix: true) + XCTAssertEqual(bytes.sizedByteArray, [44, 1, 0, 0, 44, 0, 0, 0, 77, 79, 78, 83, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]) + + let newBuf = FlatBuffersUtils.removeSizePrefix(bb: bytes.buffer) + readMonster(fb: newBuf) + } + + func createMonster(withPrefix prefix: Bool) -> FlatBufferBuilder { + let fbb = FlatBufferBuilder(initialSize: 1) + let names = [fbb.create(string: "Frodo"), fbb.create(string: "Barney"), fbb.create(string: "Wilma")] + var offsets: [Offset<UOffset>] = [] + let start1 = Monster1.startMonster(fbb) + Monster1.add(name: names[0], fbb) + offsets.append(Monster1.endMonster(fbb, start: start1)) + let start2 = Monster1.startMonster(fbb) + Monster1.add(name: names[1], fbb) + offsets.append(Monster1.endMonster(fbb, start: start2)) + let start3 = Monster1.startMonster(fbb) + Monster1.add(name: names[2], fbb) + offsets.append(Monster1.endMonster(fbb, start: start3)) + + let sortedArray = Monster1.sortVectorOfMonster(offsets: offsets, fbb) + + let str = fbb.create(string: "MyMonster") + let test1 = fbb.create(string: "test1") + let test2 = fbb.create(string: "test2") + let _inv: [Byte] = [0, 1, 2, 3, 4] + let inv = fbb.createVector(_inv) + + let fred = fbb.create(string: "Fred") + let mon1Start = Monster1.startMonster(fbb) + Monster1.add(name: fred, fbb) + let mon2 = Monster1.endMonster(fbb, start: mon1Start) + let test4 = fbb.createVector(structs: [MyGame.Example.createTest(a: 30, b: 40), + MyGame.Example.createTest(a: 10, b: 20)], + type: Test1.self) + + let stringTestVector = fbb.createVector(ofOffsets: [test1, test2]) + + let mStart = Monster1.startMonster(fbb) + let posOffset = fbb.create(struct: MyGame.Example.createVec3(x: 1, y: 2, z: 3, test1: 3, test2: .green, test3a: 5, test3b: 6), type: Vec3.self) + Monster1.add(pos: posOffset, fbb) + Monster1.add(hp: 80, fbb) + Monster1.add(name: str, fbb) + Monster1.addVectorOf(inventory: inv, fbb) + Monster1.add(testType: .monster, fbb) + Monster1.add(test: mon2, fbb) + Monster1.addVectorOf(test4: test4, fbb) + Monster1.addVectorOf(testarrayofstring: stringTestVector, fbb) + Monster1.add(testbool: true, fbb) + Monster1.addVectorOf(testarrayoftables: sortedArray, fbb) + let end = Monster1.endMonster(fbb, start: mStart) + Monster1.finish(fbb, end: end, prefix: prefix) + return fbb + } + + func mutateMonster(fb: ByteBuffer) { + let monster = Monster1.getRootAsMonster(bb: fb) + XCTAssertFalse(monster.mutate(mana: 10)) + XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney") + XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo") + XCTAssertEqual(monster.testarrayoftables(at: 2)?.name, "Wilma") + + // Example of searching for a table by the key + XCTAssertNotNil(monster.testarrayoftablesBy(key: "Frodo")) + XCTAssertNotNil(monster.testarrayoftablesBy(key: "Barney")) + XCTAssertNotNil(monster.testarrayoftablesBy(key: "Wilma")) + + XCTAssertEqual(monster.testType, .monster) + + XCTAssertEqual(monster.mutate(inventory: 1, at: 0), true) + XCTAssertEqual(monster.mutate(inventory: 2, at: 1), true) + XCTAssertEqual(monster.mutate(inventory: 3, at: 2), true) + XCTAssertEqual(monster.mutate(inventory: 4, at: 3), true) + XCTAssertEqual(monster.mutate(inventory: 5, at: 4), true) + + for i in 0..<monster.inventoryCount { + XCTAssertEqual(monster.inventory(at: i), Byte(i + 1)) + } + + XCTAssertEqual(monster.mutate(inventory: 0, at: 0), true) + XCTAssertEqual(monster.mutate(inventory: 1, at: 1), true) + XCTAssertEqual(monster.mutate(inventory: 2, at: 2), true) + XCTAssertEqual(monster.mutate(inventory: 3, at: 3), true) + XCTAssertEqual(monster.mutate(inventory: 4, at: 4), true) + + let vec = monster.pos + XCTAssertEqual(vec?.x, 1) + XCTAssertTrue(vec?.mutate(x: 55.0) ?? false) + XCTAssertTrue(vec?.mutate(test1: 55) ?? false) + XCTAssertEqual(vec?.x, 55.0) + XCTAssertEqual(vec?.test1, 55.0) + XCTAssertTrue(vec?.mutate(x: 1) ?? false) + XCTAssertEqual(vec?.x, 1) + XCTAssertTrue(vec?.mutate(test1: 3) ?? false) + } + + func readMonster(fb: ByteBuffer) { + let monster = Monster1.getRootAsMonster(bb: fb) + XCTAssertEqual(monster.hp, 80) + XCTAssertEqual(monster.mana, 150) + XCTAssertEqual(monster.name, "MyMonster") + let pos = monster.pos + XCTAssertEqual(pos?.x, 1) + XCTAssertEqual(pos?.y, 2) + XCTAssertEqual(pos?.z, 3) + XCTAssertEqual(pos?.test1, 3) + XCTAssertEqual(pos?.test2, .green) + let test = pos?.test3 + XCTAssertEqual(test?.a, 5) + XCTAssertEqual(test?.b, 6) + XCTAssertEqual(monster.testType, .monster) + let monster2 = monster.test(type: Monster1.self) + XCTAssertEqual(monster2?.name, "Fred") + + XCTAssertEqual(monster.mutate(mana: 10), false) + + XCTAssertEqual(monster.mana, 150) + XCTAssertEqual(monster.inventoryCount, 5) + var sum: Byte = 0 + for i in 0...monster.inventoryCount { + sum += monster.inventory(at: i) + } + XCTAssertEqual(sum, 10) + XCTAssertEqual(monster.test4Count, 2) + let test0 = monster.test4(at: 0) + let test1 = monster.test4(at: 1) + var sum0 = 0 + var sum1 = 0 + if let a = test0?.a, let b = test0?.b { + sum0 = Int(a) + Int(b) + } + if let a = test1?.a, let b = test1?.b { + sum1 = Int(a) + Int(b) + } + XCTAssertEqual(sum0 + sum1, 100) + XCTAssertEqual(monster.testarrayofstringCount, 2) + XCTAssertEqual(monster.testarrayofstring(at: 0), "test1") + XCTAssertEqual(monster.testarrayofstring(at: 1), "test2") + XCTAssertEqual(monster.testbool, true) + + let array = monster.nameSegmentArray + XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster") + + if 0 == monster.testarrayofboolsCount { + XCTAssertEqual(monster.testarrayofbools.isEmpty, true) + } else { + XCTAssertEqual(monster.testarrayofbools.isEmpty, false) + } + } +} diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift new file mode 100644 index 00000000..4115706f --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift @@ -0,0 +1,183 @@ +import XCTest +@testable import FlatBuffers + +final class FlatBuffersStructsTests: XCTestCase { + + func testCreatingStruct() { + let v = createVecWrite(x: 1.0, y: 2.0, z: 3.0) + let b = FlatBufferBuilder(initialSize: 20) + let o = b.create(struct: v, type: Vec.self) + let end = VPointerVec.createVPointer(b: b, o: o) + b.finish(offset: end) + XCTAssertEqual(b.sizedByteArray, [12, 0, 0, 0, 0, 0, 6, 0, 4, 0, 4, 0, 6, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]) + } + + func testReadingStruct() { + let v = createVecWrite(x: 1.0, y: 2.0, z: 3.0) + let b = FlatBufferBuilder(initialSize: 20) + let o = b.create(struct: v, type: Vec.self) + let end = VPointerVec.createVPointer(b: b, o: o) + b.finish(offset: end) + let buffer = b.sizedByteArray + XCTAssertEqual(buffer, [12, 0, 0, 0, 0, 0, 6, 0, 4, 0, 4, 0, 6, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64]) + let point = VPointerVec.getRootAsCountry(ByteBuffer(bytes: buffer)) + XCTAssertEqual(point.vec?.z, 3.0) + } + + func testCreatingVectorStruct() { + let b = FlatBufferBuilder(initialSize: 20) + let path = b.createVector(structs: [createVecWrite(x: 1, y: 2, z: 3), createVecWrite(x: 4.0, y: 5.0, z: 6)], type: Vec.self) + let end = VPointerVectorVec.createVPointer(b: b, v: path) + b.finish(offset: end) + XCTAssertEqual(b.sizedByteArray, [12, 0, 0, 0, 8, 0, 8, 0, 0, 0, 4, 0, 8, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64]) + } + + func testCreatingVectorStructWithForcedDefaults() { + let b = FlatBufferBuilder(initialSize: 20, serializeDefaults: true) + let path = b.createVector(structs: [createVecWrite(x: 1, y: 2, z: 3), createVecWrite(x: 4.0, y: 5.0, z: 6)], type: Vec.self) + let end = VPointerVectorVec.createVPointer(b: b, v: path) + b.finish(offset: end) + XCTAssertEqual(b.sizedByteArray, [12, 0, 0, 0, 8, 0, 12, 0, 4, 0, 8, 0, 8, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64]) + } + + func testCreatingEnums() { + let b = FlatBufferBuilder(initialSize: 20) + let path = b.createVector(structs: [createVecWrite(x: 1, y: 2, z: 3), createVecWrite(x: 4, y: 5, z: 6)], type: Vec.self) + let end = VPointerVectorVec.createVPointer(b: b, color: .blue, v: path) + b.finish(offset: end) + XCTAssertEqual(b.sizedByteArray, [12, 0, 0, 0, 8, 0, 12, 0, 4, 0, 8, 0, 8, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64]) + } + + func testReadingStructWithEnums() { + let b = FlatBufferBuilder(initialSize: 20) + let vec = createVec2(x: 1, y: 2, z: 3, color: .red) + let o = b.create(struct: vec, type: Vec2.self) + let end = VPointerVec2.createVPointer(b: b, o: o, type: .vec) + b.finish(offset: end) + let buffer = b.sizedByteArray + XCTAssertEqual(buffer, [16, 0, 0, 0, 0, 0, 10, 0, 12, 0, 12, 0, 11, 0, 4, 0, 10, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 1, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0]) + let point = VPointerVec2.getRootAsCountry(ByteBuffer(bytes: buffer)) + XCTAssertEqual(point.vec?.c, Color2.red) + XCTAssertEqual(point.vec?.x, 1.0) + XCTAssertEqual(point.vec?.y, 2.0) + XCTAssertEqual(point.vec?.z, 3.0) + XCTAssertEqual(point.UType, Test.vec) + } + +} + +func createVecWrite(x: Float32, y: Float32, z: Float32) -> UnsafeMutableRawPointer{ + let memory = UnsafeMutableRawPointer.allocate(byteCount: Vec.size, alignment: Vec.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: Vec.size) + memory.storeBytes(of: x, toByteOffset: 0, as: Float32.self) + memory.storeBytes(of: y, toByteOffset: 4, as: Float32.self) + memory.storeBytes(of: z, toByteOffset: 8, as: Float32.self) + return memory +} + +struct Vec: Readable { + static var size = 12 + static var alignment = 4 + private var __p: Struct + init(_ fb: ByteBuffer, o: Int32) { __p = Struct(bb: fb, position: o) } + var x: Float32 { return __p.readBuffer(of: Float32.self, at: 0)} + var y: Float32 { return __p.readBuffer(of: Float32.self, at: 4)} + var z: Float32 { return __p.readBuffer(of: Float32.self, at: 8)} +} + +struct VPointerVec { + + private var __t: Table + + private init(_ t: Table) { + __t = t + } + + var vec: Vec? { let o = __t.offset(4); return o == 0 ? nil : Vec(__t.bb, o: o + __t.postion) } + + @inlinable static func getRootAsCountry(_ bb: ByteBuffer) -> VPointerVec { + return VPointerVec(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: 0)))) + } + + static func startVPointer(b: FlatBufferBuilder) -> UOffset { b.startTable(with: 1) } + static func finish(b: FlatBufferBuilder, s: UOffset) -> Offset<UOffset> { return Offset(offset: b.endTable(at: s)) } + + static func createVPointer(b: FlatBufferBuilder, o: Offset<UOffset>) -> Offset<UOffset> { + let s = VPointerVec.startVPointer(b: b) + b.add(structOffset: 0) + return VPointerVec.finish(b: b, s: s) + } +} + +enum Color: UInt32 { case red = 0, green = 1, blue = 2 } + +private let VPointerVectorVecOffsets: (color: VOffset, vector: VOffset) = (0, 1) + +struct VPointerVectorVec { + + static func startVPointer(b: FlatBufferBuilder) -> UOffset { b.startTable(with: 2) } + + static func addVector(b: FlatBufferBuilder, v: Offset<UOffset>) { b.add(offset: v, at: VPointerVectorVecOffsets.vector) } + + static func addColor(b: FlatBufferBuilder, color: Color) { b.add(element: color.rawValue, def: 1, at: VPointerVectorVecOffsets.color) } + + static func finish(b: FlatBufferBuilder, s: UOffset) -> Offset<UOffset> { return Offset(offset: b.endTable(at: s)) } + + static func createVPointer(b: FlatBufferBuilder, color: Color = .green, v: Offset<UOffset>) -> Offset<UOffset> { + let s = VPointerVectorVec.startVPointer(b: b) + VPointerVectorVec.addVector(b: b, v: v) + VPointerVectorVec.addColor(b: b, color: color) + return VPointerVectorVec.finish(b: b, s: s) + } +} + +enum Color2: Int32 { case red = 0, green = 1, blue = 2 } +enum Test: Byte { case none = 0, vec = 1 } + +func createVec2(x: Float32 = 0, y: Float32 = 0, z: Float32 = 0, color: Color2) -> UnsafeMutableRawPointer { + let memory = UnsafeMutableRawPointer.allocate(byteCount: Vec2.size, alignment: Vec2.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: Vec2.size) + memory.storeBytes(of: x, toByteOffset: 0, as: Float32.self) + memory.storeBytes(of: y, toByteOffset: 4, as: Float32.self) + memory.storeBytes(of: z, toByteOffset: 8, as: Float32.self) + return memory +} + +struct Vec2: Readable { + static var size = 13 + static var alignment = 4 + private var __p: Struct + + init(_ fb: ByteBuffer, o: Int32) { __p = Struct(bb: fb, position: o) } + var c: Color2 { return Color2(rawValue: __p.readBuffer(of: Int32.self, at: 12)) ?? .red } + var x: Float32 { return __p.readBuffer(of: Float32.self, at: 0)} + var y: Float32 { return __p.readBuffer(of: Float32.self, at: 4)} + var z: Float32 { return __p.readBuffer(of: Float32.self, at: 8)} +} + +struct VPointerVec2 { + + private var __t: Table + + private init(_ t: Table) { + __t = t + } + + var vec: Vec2? { let o = __t.offset(4); return o == 0 ? nil : Vec2( __t.bb, o: o + __t.postion) } + var UType: Test? { let o = __t.offset(6); return o == 0 ? Test.none : Test(rawValue: __t.readBuffer(of: Byte.self, at: o)) } + + @inlinable static func getRootAsCountry(_ bb: ByteBuffer) -> VPointerVec2 { + return VPointerVec2(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: 0)))) + } + + static func startVPointer(b: FlatBufferBuilder) -> UOffset { b.startTable(with: 3) } + static func finish(b: FlatBufferBuilder, s: UOffset) -> Offset<UOffset> { return Offset(offset: b.endTable(at: s)) } + + static func createVPointer(b: FlatBufferBuilder, o: Offset<UOffset>, type: Test) -> Offset<UOffset> { + let s = VPointerVec2.startVPointer(b: b) + b.add(structOffset: 0) + b.add(element: type.rawValue, def: Test.none.rawValue, at: 1) + b.add(offset: o, at: 2) + return VPointerVec2.finish(b: b, s: s) + } +} diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift new file mode 100644 index 00000000..e8e737e2 --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift @@ -0,0 +1,118 @@ +import XCTest +@testable import FlatBuffers + +final class FlatBuffersTests: XCTestCase { + + let country = "Norway" + + func testEndian() { XCTAssertEqual(isLitteEndian, true) } + + func testOffset() { + let o = Offset<Int>() + let b = Offset<Int>(offset: 1) + XCTAssertEqual(o.isEmpty, true) + XCTAssertEqual(b.isEmpty, false) + } + + func testCreateString() { + let helloWorld = "Hello, world!" + let b = FlatBufferBuilder(initialSize: 16) + XCTAssertEqual(b.create(string: country).o, 12) + XCTAssertEqual(b.create(string: helloWorld).o, 32) + b.clear() + XCTAssertEqual(b.create(string: helloWorld).o, 20) + XCTAssertEqual(b.create(string: country).o, 32) + } + + func testStartTable() { + let b = FlatBufferBuilder(initialSize: 16) + XCTAssertNoThrow(b.startTable(with: 0)) + b.clear() + XCTAssertEqual(b.create(string: country).o, 12) + XCTAssertEqual(b.startTable(with: 0), 12) + } + + func testCreate() { + var b = FlatBufferBuilder(initialSize: 16) + _ = Country.createCountry(builder: &b, name: country, log: 200, lan: 100) + let v: [UInt8] = [10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + XCTAssertEqual(b.sizedByteArray, v) + } + + func testCreateFinish() { + var b = FlatBufferBuilder(initialSize: 16) + let countryOff = Country.createCountry(builder: &b, name: country, log: 200, lan: 100) + b.finish(offset: countryOff) + let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + XCTAssertEqual(b.sizedByteArray, v) + } + + func testCreateFinishWithPrefix() { + var b = FlatBufferBuilder(initialSize: 16) + let countryOff = Country.createCountry(builder: &b, name: country, log: 200, lan: 100) + b.finish(offset: countryOff, addPrefix: true) + let v: [UInt8] = [44, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + XCTAssertEqual(b.sizedByteArray, v) + } + + func testReadCountry() { + let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + let buffer = ByteBuffer(bytes: v) + let c = Country.getRootAsCountry(buffer) + XCTAssertEqual(c.lan, 100) + XCTAssertEqual(c.log, 200) + XCTAssertEqual(c.nameVector, [78, 111, 114, 119, 97, 121]) + XCTAssertEqual(c.name, country) + } +} + +class Country { + + static let offsets: (name: VOffset, lan: VOffset, lng: VOffset) = (0, 1, 2) + private var __t: Table + + private init(_ t: Table) { + __t = t + } + + var lan: Int32 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(of: Int32.self, at: o) } + var log: Int32 { let o = __t.offset(8); return o == 0 ? 0 : __t.readBuffer(of: Int32.self, at: o) } + var nameVector: [UInt8]? { return __t.getVector(at: 4) } + var name: String? { let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) } + + @inlinable static func getRootAsCountry(_ bb: ByteBuffer) -> Country { + return Country(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: 0)))) + } + + @inlinable static func createCountry(builder: inout FlatBufferBuilder, name: String, log: Int32, lan: Int32) -> Offset<Country> { + return createCountry(builder: &builder, offset: builder.create(string: name), log: log, lan: lan) + } + + @inlinable static func createCountry(builder: inout FlatBufferBuilder, offset: Offset<String>, log: Int32, lan: Int32) -> Offset<Country> { + let _start = builder.startTable(with: 3) + Country.add(builder: &builder, lng: log) + Country.add(builder: &builder, lan: lan) + Country.add(builder: &builder, name: offset) + return Country.end(builder: &builder, startOffset: _start) + } + + @inlinable static func end(builder: inout FlatBufferBuilder, startOffset: UOffset) -> Offset<Country> { + return Offset(offset: builder.endTable(at: startOffset)) + } + + @inlinable static func add(builder: inout FlatBufferBuilder, name: String) { + add(builder: &builder, name: builder.create(string: name)) + } + + @inlinable static func add(builder: inout FlatBufferBuilder, name: Offset<String>) { + builder.add(offset: name, at: Country.offsets.name) + } + + @inlinable static func add(builder: inout FlatBufferBuilder, lan: Int32) { + builder.add(element: lan, def: 0, at: Country.offsets.lan) + } + + @inlinable static func add(builder: inout FlatBufferBuilder, lng: Int32) { + builder.add(element: lng, def: 0, at: Country.offsets.lng) + } +} diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift new file mode 100644 index 00000000..d6524293 --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift @@ -0,0 +1,229 @@ +import XCTest +@testable import FlatBuffers + +final class FlatBuffersUnionTests: XCTestCase { + + func testCreateMonstor() { + + var b = FlatBufferBuilder(initialSize: 20) + let dmg: Int16 = 5 + let str = "Axe" + let axe = b.create(string: str) + let weapon = Weapon.createWeapon(builder: &b, offset: axe, dmg: dmg) + let weapons = b.createVector(ofOffsets: [weapon]) + let root = Monster.createMonster(builder: &b, + offset: weapons, + equipment: .Weapon, + equippedOffset: weapon.o) + b.finish(offset: root) + let buffer = b.sizedByteArray + XCTAssertEqual(buffer, [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 8, 0, 7, 0, 12, 0, 10, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 0, 20, 0, 0, 0, 1, 0, 0, 0, 12, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 5, 0, 4, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0]) + let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buffer)) + XCTAssertEqual(monster.weapon(at: 0)?.dmg, dmg) + XCTAssertEqual(monster.weapon(at: 0)?.name, str) + XCTAssertEqual(monster.weapon(at: 0)?.nameVector, [65, 120, 101]) + let p: Weapon? = monster.equiped() + XCTAssertEqual(p?.dmg, dmg) + XCTAssertEqual(p?.name, str) + XCTAssertEqual(p?.nameVector, [65, 120, 101]) + } + + func testEndTableFinish() { + var builder = FlatBufferBuilder(initialSize: 20) + let sword = builder.create(string: "Sword") + let axe = builder.create(string: "Axe") + let weaponOne = Weapon.createWeapon(builder: &builder, offset: sword, dmg: 3) + let weaponTwo = Weapon.createWeapon(builder: &builder, offset: axe, dmg: 5) + let name = builder.create(string: "Orc") + let inventory: [UInt8] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + let inv = builder.createVector(inventory, size: 10) + let weapons = builder.createVector(ofOffsets: [weaponOne, weaponTwo]) + var vecArray: [UnsafeMutableRawPointer] = [] + vecArray.append(createVecWrite(x: 4.0, y: 5.0, z: 6.0)) + vecArray.append(createVecWrite(x: 1.0, y: 2.0, z: 3.0)) + let path = builder.createVector(structs: vecArray, type: Vec.self) + let orc = FinalMonster.createMonster(builder: &builder, + position: builder.create(struct: createVecWrite(x: 1.0, y: 2.0, z: 3.0), type: Vec.self), + hp: 300, + name: name, + inventory: inv, + color: .red, + weapons: weapons, + equipment: .Weapon, + equippedOffset: weaponTwo, + path: path) + builder.finish(offset: orc) + XCTAssertEqual(builder.sizedByteArray, [32, 0, 0, 0, 0, 0, 26, 0, 36, 0, 36, 0, 0, 0, 34, 0, 28, 0, 0, 0, 24, 0, 23, 0, 16, 0, 15, 0, 8, 0, 4, 0, 26, 0, 0, 0, 44, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 76, 0, 0, 0, 0, 0, 44, 1, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0, 52, 0, 0, 0, 28, 0, 0, 0, 10, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 3, 0, 0, 0, 79, 114, 99, 0, 244, 255, 255, 255, 0, 0, 5, 0, 24, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 3, 0, 12, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0, 5, 0, 0, 0, 83, 119, 111, 114, 100, 0, 0, 0]) + } + + func testEnumVector() { + let vectorOfEnums: [ColorsNameSpace.RGB] = [.blue, .green] + + let builder = FlatBufferBuilder(initialSize: 1) + let off = builder.createVector(vectorOfEnums) + let start = ColorsNameSpace.Monster.startMonster(builder) + ColorsNameSpace.Monster.add(colors: off, builder) + let end = ColorsNameSpace.Monster.endMonster(builder, start: start) + builder.finish(offset: end) + XCTAssertEqual(builder.sizedByteArray, [12, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0]) + let monster = ColorsNameSpace.Monster.getRootAsMonster(bb: builder.buffer) + XCTAssertEqual(monster.colorsCount, 2) + XCTAssertEqual(monster.colors(at: 0), .blue) + XCTAssertEqual(monster.colors(at: 1), .green) + } + + func testUnionVector() { + let fb = FlatBufferBuilder() + + let swordDmg: Int32 = 8 + let attackStart = Attacker.startAttacker(fb) + Attacker.add(swordAttackDamage: swordDmg, fb) + let attack = Attacker.endAttacker(fb, start: attackStart) + + let characterType: [Character] = [.belle, .mulan, .bookfan] + let characters = [ + fb.create(struct: createBookReader(booksRead: 7), type: BookReader.self), + attack, + fb.create(struct: createBookReader(booksRead: 2), type: BookReader.self), + ] + let types = fb.createVector(characterType) + let characterVector = fb.createVector(ofOffsets: characters) + + let movieStart = Movie.startMovie(fb) + Movie.addVectorOf(charactersType: types, fb) + Movie.addVectorOf(characters: characterVector, fb) + let end = Movie.endMovie(fb, start: movieStart) + Movie.finish(fb, end: end) + + let movie = Movie.getRootAsMovie(bb: fb.buffer) + XCTAssertEqual(movie.charactersTypeCount, Int32(characterType.count)) + XCTAssertEqual(movie.charactersCount, Int32(characters.count)) + + for i in 0..<movie.charactersTypeCount { + XCTAssertEqual(movie.charactersType(at: i), characterType[Int(i)]) + } + + XCTAssertEqual(movie.characters(at: 0, type: BookReader.self)?.booksRead, 7) + XCTAssertEqual(movie.characters(at: 1, type: Attacker.self)?.swordAttackDamage, swordDmg) + XCTAssertEqual(movie.characters(at: 2, type: BookReader.self)?.booksRead, 2) + } +} + +public enum ColorsNameSpace { + +enum RGB: Int32, Enum { + typealias T = Int32 + static var byteSize: Int { return MemoryLayout<Int32>.size } + var value: Int32 { return self.rawValue } + case red = 0, green = 1, blue = 2 +} + +struct Monster: FlatBufferObject { + private var _accessor: Table + static func getRootAsMonster(bb: ByteBuffer) -> Monster { return Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) } + + init(_ t: Table) { _accessor = t } + init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) } + + public var colorsCount: Int32 { let o = _accessor.offset(4); return o == 0 ? 0 : _accessor.vector(count: o) } + public func colors(at index: Int32) -> ColorsNameSpace.RGB? { let o = _accessor.offset(4); return o == 0 ? ColorsNameSpace.RGB(rawValue: 0)! : ColorsNameSpace.RGB(rawValue: _accessor.directRead(of: Int32.self, offset: _accessor.vector(at: o) + index * 4)) } + static func startMonster(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } + static func add(colors: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: colors, at: 0) } + static func endMonster(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} +} + + +enum Equipment: Byte { case none, Weapon } + +enum Color3: Int8 { case red = 0, green, blue } + +struct FinalMonster { + + @inlinable static func createMonster(builder: inout FlatBufferBuilder, + position: Offset<UOffset>, + hp: Int16, + name: Offset<String>, + inventory: Offset<UOffset>, + color: Color3, + weapons: Offset<UOffset>, + equipment: Equipment = .none, + equippedOffset: Offset<Weapon>, + path: Offset<UOffset>) -> Offset<Monster> { + let start = builder.startTable(with: 11) + builder.add(structOffset: 0) + builder.add(element: hp, def: 100, at: 2) + builder.add(offset: name, at: 3) + builder.add(offset: inventory, at: 5) + builder.add(element: color.rawValue, def: Color3.green.rawValue, at: 6) + builder.add(offset: weapons, at: 7) + builder.add(element: equipment.rawValue, def: Equipment.none.rawValue, at: 8) + builder.add(offset: equippedOffset, at: 9) + builder.add(offset: path, at: 10) + return Offset(offset: builder.endTable(at: start)) + } +} + +struct Monster { + + private var __t: Table + + init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o) } + init(_ t: Table) { __t = t } + + func weapon(at index: Int32) -> Weapon? { let o = __t.offset(4); return o == 0 ? nil : Weapon.assign(__t.indirect(__t.vector(at: o) + (index * 4)), __t.bb) } + + func equiped<T: FlatBufferObject>() -> T? { + let o = __t.offset(8); return o == 0 ? nil : __t.union(o) + } + + static func getRootAsMonster(bb: ByteBuffer) -> Monster { + return Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: 0)))) + } + + @inlinable static func createMonster(builder: inout FlatBufferBuilder, + offset: Offset<UOffset>, + equipment: Equipment = .none, + equippedOffset: UOffset) -> Offset<Monster> { + let start = builder.startTable(with: 3) + builder.add(element: equippedOffset, def: 0, at: 2) + builder.add(offset: offset, at: 0) + builder.add(element: equipment.rawValue, def: Equipment.none.rawValue, at: 1) + return Offset(offset: builder.endTable(at: start)) + } +} + + +struct Weapon: FlatBufferObject { + + static let offsets: (name: VOffset, dmg: VOffset) = (0, 1) + private var __t: Table + + init(_ t: Table) { __t = t } + init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o)} + + var dmg: Int16 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(of: Int16.self, at: o) } + var nameVector: [UInt8]? { return __t.getVector(at: 4) } + var name: String? { let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) } + + static func assign(_ i: Int32, _ bb: ByteBuffer) -> Weapon { return Weapon(Table(bb: bb, position: i)) } + + @inlinable static func createWeapon(builder: inout FlatBufferBuilder, offset: Offset<String>, dmg: Int16) -> Offset<Weapon> { + let _start = builder.startTable(with: 2) + Weapon.add(builder: &builder, name: offset) + Weapon.add(builder: &builder, dmg: dmg) + return Weapon.end(builder: &builder, startOffset: _start) + } + + @inlinable static func end(builder: inout FlatBufferBuilder, startOffset: UOffset) -> Offset<Weapon> { + return Offset(offset: builder.endTable(at: startOffset)) + } + + @inlinable static func add(builder: inout FlatBufferBuilder, name: Offset<String>) { + builder.add(offset: name, at: Weapon.offsets.name) + } + + @inlinable static func add(builder: inout FlatBufferBuilder, dmg: Int16) { + builder.add(element: dmg, def: 0, at: Weapon.offsets.dmg) + } +} diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift new file mode 100644 index 00000000..5e6301ff --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift @@ -0,0 +1,108 @@ +import XCTest +@testable import FlatBuffers + +final class FlatBuffersVectors: XCTestCase { + + func testCreatingTwoCountries() { + let norway = "Norway" + let denmark = "Denmark" + var b = FlatBufferBuilder(initialSize: 20) + let noStr = b.create(string: norway) + let deStr = b.create(string: denmark) + let n = Country.createCountry(builder: &b, offset: noStr, log: 888, lan: 700) + let d = Country.createCountry(builder: &b, offset: deStr, log: 200, lan: 100) + let vector = [n, d] + let vectorOffset = b.createVector(ofOffsets: vector) + b.finish(offset: vectorOffset) + XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 2, 0, 0, 0, 48, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 18, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 40, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 24, 0, 0, 0, 188, 2, 0, 0, 120, 3, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]) + } + + func testCreateIntArray() { + let numbers: [Int32] = [1, 2, 3, 4, 5] + let b = FlatBufferBuilder(initialSize: 20) + let o = b.createVector(numbers, size: numbers.count) + b.finish(offset: o) + XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0]) + } + + func testCreateVectorOfStrings() { + let strs = ["Denmark", "Norway"] + let b = FlatBufferBuilder(initialSize: 20) + let o = b.createVector(ofStrings: strs) + b.finish(offset: o) + XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 2, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0]) + } + func testCreateSharedStringVector() { + let norway = "Norway" + let denmark = "Denmark" + let b = FlatBufferBuilder(initialSize: 20) + let noStr = b.createShared(string: norway) + let deStr = b.createShared(string: denmark) + let _noStr = b.createShared(string: norway) + let _deStr = b.createShared(string: denmark) + let v = [noStr, deStr, _noStr, _deStr] + let end = b.createVector(ofOffsets: v) + b.finish(offset: end) + XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 4, 0, 0, 0, 28, 0, 0, 0, 12, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]) + } + + func testReadInt32Array() { + let data: [Int32] = [1, 2, 3, 4, 5] + let b = FlatBufferBuilder(initialSize: 20) + let v = Numbers.createNumbersVector(b: b, array: data) + let end = Numbers.createNumbers(b: b, o: v) + b.finish(offset: end) + let number = Numbers.getRootAsNumbers(ByteBuffer(bytes: b.sizedByteArray)) + XCTAssertEqual(number.vArrayInt32, [1, 2, 3, 4, 5]) + } + + func testReadDoubleArray() { + let data: [Double] = [1, 2, 3, 4, 5] + let b = FlatBufferBuilder(initialSize: 20) + let v = Numbers.createNumbersVector(b: b, array: data) + let end = Numbers.createNumbers(b: b, o: v) + b.finish(offset: end) + let number = Numbers.getRootAsNumbers(ByteBuffer(bytes: b.sizedByteArray)) + XCTAssertEqual(number.vArrayDouble, [1, 2, 3, 4, 5]) + } +} + +struct Numbers { + + private var __t: Table + + private init(_ t: Table) { + __t = t + } + + @inlinable static func getRootAsNumbers(_ bb: ByteBuffer) -> Numbers { + return Numbers(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: 0)))) + } + + var vArrayInt: [Int]? { return __t.getVector(at: 4) } + var vArrayInt32: [Int32]? { return __t.getVector(at: 4) } + var vArrayDouble: [Double]? { return __t.getVector(at: 4) } + var vArrayFloat: [Float32]? { return __t.getVector(at: 4) } + + static func createNumbersVector(b: FlatBufferBuilder, array: [Int]) -> Offset<UOffset> { + return b.createVector(array, size: array.count) + } + + static func createNumbersVector(b: FlatBufferBuilder, array: [Int32]) -> Offset<UOffset> { + return b.createVector(array, size: array.count) + } + + static func createNumbersVector(b: FlatBufferBuilder, array: [Double]) -> Offset<UOffset> { + return b.createVector(array, size: array.count) + } + + static func createNumbersVector(b: FlatBufferBuilder, array: [Float32]) -> Offset<UOffset> { + return b.createVector(array, size: array.count) + } + + static func createNumbers(b: FlatBufferBuilder, o: Offset<UOffset>) -> Offset<UOffset> { + let start = b.startTable(with: 1) + b.add(offset: o, at: 0) + return Offset(offset: b.endTable(at: start)) + } +} diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift new file mode 100644 index 00000000..c044c5ca --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift @@ -0,0 +1,76 @@ +import XCTest +@testable import FlatBuffers + +final class FlatBuffersDoubleTests: XCTestCase { + + let country = "Norway" + + func testCreateCountry() { + var b = FlatBufferBuilder(initialSize: 16) + _ = CountryDouble.createCountry(builder: &b, name: country, log: 200, lan: 100) + let v: [UInt8] = [10, 0, 28, 0, 4, 0, 8, 0, 16, 0, 10, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 64, 0, 0, 0, 0, 0, 0, 105, 64, 0, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + XCTAssertEqual(b.sizedByteArray, v) + } + + func testCreateFinish() { + var b = FlatBufferBuilder(initialSize: 16) + let countryOff = CountryDouble.createCountry(builder: &b, name: country, log: 200, lan: 100) + b.finish(offset: countryOff) + let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 28, 0, 4, 0, 8, 0, 16, 0, 10, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 64, 0, 0, 0, 0, 0, 0, 105, 64, 0, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + XCTAssertEqual(b.sizedByteArray, v) + } + + func testCreateFinishWithPrefix() { + var b = FlatBufferBuilder(initialSize: 16) + let countryOff = CountryDouble.createCountry(builder: &b, name: country, log: 200, lan: 100) + b.finish(offset: countryOff, addPrefix: true) + let v: [UInt8] = [60, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 28, 0, 4, 0, 8, 0, 16, 0, 10, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 64, 0, 0, 0, 0, 0, 0, 105, 64, 0, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0] + XCTAssertEqual(b.sizedByteArray, v) + } +} + +class CountryDouble { + + static let offsets: (name: VOffset, lan: VOffset, lng: VOffset) = (4,6,8) + + private var table: Table + + private init(table t: Table) { table = t } + + static func getRootAsCountry(_ bb: ByteBuffer) -> CountryDouble { + let pos = bb.read(def: Int32.self, position: Int(bb.size)) + return CountryDouble(table: Table(bb: bb, position: Int32(pos))) + } + + static func createCountry(builder: inout FlatBufferBuilder, name: String, log: Double, lan: Double) -> Offset<Country> { + return createCountry(builder: &builder, offset: builder.create(string: name), log: log, lan: lan) + } + + static func createCountry(builder: inout FlatBufferBuilder, offset: Offset<String>, log: Double, lan: Double) -> Offset<Country> { + let _start = builder.startTable(with: 3) + CountryDouble.add(builder: &builder, lng: log) + CountryDouble.add(builder: &builder, lan: lan) + CountryDouble.add(builder: &builder, name: offset) + return CountryDouble.end(builder: &builder, startOffset: _start) + } + + static func end(builder: inout FlatBufferBuilder, startOffset: UOffset) -> Offset<Country> { + return Offset(offset: builder.endTable(at: startOffset)) + } + + static func add(builder: inout FlatBufferBuilder, name: String) { + add(builder: &builder, name: builder.create(string: name)) + } + + static func add(builder: inout FlatBufferBuilder, name: Offset<String>) { + builder.add(offset: name, at: Country.offsets.name) + } + + static func add(builder: inout FlatBufferBuilder, lan: Double) { + builder.add(element: lan, def: 0, at: Country.offsets.lan) + } + + static func add(builder: inout FlatBufferBuilder, lng: Double) { + builder.add(element: lng, def: 0, at: Country.offsets.lng) + } +} diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift new file mode 100644 index 00000000..d53a7a6c --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift @@ -0,0 +1,94 @@ +#if !canImport(ObjectiveC) +import XCTest + +extension FlatBuffersDoubleTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FlatBuffersDoubleTests = [ + ("testCreateCountry", testCreateCountry), + ("testCreateFinish", testCreateFinish), + ("testCreateFinishWithPrefix", testCreateFinishWithPrefix), + ] +} + +extension FlatBuffersMonsterWriterTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FlatBuffersMonsterWriterTests = [ + ("testCreateMonster", testCreateMonster), + ("testCreateMonsterPrefixed", testCreateMonsterPrefixed), + ("testCreateMonsterResizedBuffer", testCreateMonsterResizedBuffer), + ("testData", testData), + ("testReadFromOtherLangagues", testReadFromOtherLangagues), + ] +} + +extension FlatBuffersStructsTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FlatBuffersStructsTests = [ + ("testCreatingEnums", testCreatingEnums), + ("testCreatingStruct", testCreatingStruct), + ("testCreatingVectorStruct", testCreatingVectorStruct), + ("testCreatingVectorStructWithForcedDefaults", testCreatingVectorStructWithForcedDefaults), + ("testReadingStruct", testReadingStruct), + ("testReadingStructWithEnums", testReadingStructWithEnums), + ] +} + +extension FlatBuffersTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FlatBuffersTests = [ + ("testCreate", testCreate), + ("testCreateFinish", testCreateFinish), + ("testCreateFinishWithPrefix", testCreateFinishWithPrefix), + ("testCreateString", testCreateString), + ("testEndian", testEndian), + ("testOffset", testOffset), + ("testReadCountry", testReadCountry), + ("testStartTable", testStartTable), + ] +} + +extension FlatBuffersUnionTests { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FlatBuffersUnionTests = [ + ("testCreateMonstor", testCreateMonstor), + ("testEndTableFinish", testEndTableFinish), + ("testEnumVector", testEnumVector), + ("testUnionVector", testUnionVector), + ] +} + +extension FlatBuffersVectors { + // DO NOT MODIFY: This is autogenerated, use: + // `swift test --generate-linuxmain` + // to regenerate. + static let __allTests__FlatBuffersVectors = [ + ("testCreateIntArray", testCreateIntArray), + ("testCreateSharedStringVector", testCreateSharedStringVector), + ("testCreateVectorOfStrings", testCreateVectorOfStrings), + ("testCreatingTwoCountries", testCreatingTwoCountries), + ("testReadDoubleArray", testReadDoubleArray), + ("testReadInt32Array", testReadInt32Array), + ] +} + +public func __allTests() -> [XCTestCaseEntry] { + return [ + testCase(FlatBuffersDoubleTests.__allTests__FlatBuffersDoubleTests), + testCase(FlatBuffersMonsterWriterTests.__allTests__FlatBuffersMonsterWriterTests), + testCase(FlatBuffersStructsTests.__allTests__FlatBuffersStructsTests), + testCase(FlatBuffersTests.__allTests__FlatBuffersTests), + testCase(FlatBuffersUnionTests.__allTests__FlatBuffersUnionTests), + testCase(FlatBuffersVectors.__allTests__FlatBuffersVectors), + ] +} +#endif diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift new file mode 100644 index 00000000..aa6675d7 --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/monster_test_generated.swift @@ -0,0 +1,479 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +import FlatBuffers + +public enum MyGame { +public enum Example { + +public enum Color: UInt8, Enum { + public typealias T = UInt8 + public static var byteSize: Int { return MemoryLayout<UInt8>.size } + public var value: UInt8 { return self.rawValue } + case red = 1, green = 2, blue = 8 +} + +public enum Race: Int8, Enum { + public typealias T = Int8 + public static var byteSize: Int { return MemoryLayout<Int8>.size } + public var value: Int8 { return self.rawValue } + case none = -1, human = 0, dwarf = 1, elf = 2 +} + +public enum Any_: UInt8, Enum { + public typealias T = UInt8 + public static var byteSize: Int { return MemoryLayout<UInt8>.size } + public var value: UInt8 { return self.rawValue } + case none = 0, monster = 1, testsimpletablewithenum = 2, mygame_example2_monster = 3 +} + +public enum AnyUniqueAliases: UInt8, Enum { + public typealias T = UInt8 + public static var byteSize: Int { return MemoryLayout<UInt8>.size } + public var value: UInt8 { return self.rawValue } + case none = 0, m = 1, ts = 2, m2 = 3 +} + +public enum AnyAmbiguousAliases: UInt8, Enum { + public typealias T = UInt8 + public static var byteSize: Int { return MemoryLayout<UInt8>.size } + public var value: UInt8 { return self.rawValue } + case none = 0, m1 = 1, m2 = 2, m3 = 3 +} + +public struct Test: Readable { + private var _accessor: Struct + public static var size = 4 + public static var alignment = 2 + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) } + + public var a: Int16 { return _accessor.readBuffer(of: Int16.self, at: 0) } + public func mutate(a: Int16) -> Bool { return _accessor.mutate(a, index: 0) } + public var b: Int8 { return _accessor.readBuffer(of: Int8.self, at: 2) } + public func mutate(b: Int8) -> Bool { return _accessor.mutate(b, index: 2) } +} + +public struct Vec3: Readable { + private var _accessor: Struct + public static var size = 32 + public static var alignment = 8 + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) } + + public var x: Float32 { return _accessor.readBuffer(of: Float32.self, at: 0) } + public func mutate(x: Float32) -> Bool { return _accessor.mutate(x, index: 0) } + public var y: Float32 { return _accessor.readBuffer(of: Float32.self, at: 4) } + public func mutate(y: Float32) -> Bool { return _accessor.mutate(y, index: 4) } + public var z: Float32 { return _accessor.readBuffer(of: Float32.self, at: 8) } + public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) } + public var test1: Double { return _accessor.readBuffer(of: Double.self, at: 16) } + public func mutate(test1: Double) -> Bool { return _accessor.mutate(test1, index: 16) } + public var test2: MyGame.Example.Color { return MyGame.Example.Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: 24)) ?? MyGame.Example.Color.red } + public var test3: MyGame.Example.Test { return MyGame.Example.Test(_accessor.bb, o: _accessor.postion + 26) } +} + +public struct Ability: Readable { + private var _accessor: Struct + public static var size = 8 + public static var alignment = 4 + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) } + + public var id: UInt32 { return _accessor.readBuffer(of: UInt32.self, at: 0) } + public func mutate(id: UInt32) -> Bool { return _accessor.mutate(id, index: 0) } + public var distance: UInt32 { return _accessor.readBuffer(of: UInt32.self, at: 4) } + public func mutate(distance: UInt32) -> Bool { return _accessor.mutate(distance, index: 4) } +} + +public static func createTest(a: Int16, b: Int8) -> UnsafeMutableRawPointer { + let memory = UnsafeMutableRawPointer.allocate(byteCount: Test.size, alignment: Test.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: Test.size) + memory.storeBytes(of: a, toByteOffset: 0, as: Int16.self) + memory.storeBytes(of: b, toByteOffset: 2, as: Int8.self) + return memory +} + +public static func createVec3(x: Float32, y: Float32, z: Float32, test1: Double, test2: MyGame.Example.Color, test3a: Int16, test3b: Int8) -> UnsafeMutableRawPointer { + let memory = UnsafeMutableRawPointer.allocate(byteCount: Vec3.size, alignment: Vec3.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: Vec3.size) + memory.storeBytes(of: x, toByteOffset: 0, as: Float32.self) + memory.storeBytes(of: y, toByteOffset: 4, as: Float32.self) + memory.storeBytes(of: z, toByteOffset: 8, as: Float32.self) + memory.storeBytes(of: test1, toByteOffset: 16, as: Double.self) + memory.storeBytes(of: test2.rawValue, toByteOffset: 24, as: UInt8.self) + memory.storeBytes(of: test3a, toByteOffset: 26, as: Int16.self) + memory.storeBytes(of: test3b, toByteOffset: 28, as: Int8.self) + return memory +} + +public static func createAbility(id: UInt32, distance: UInt32) -> UnsafeMutableRawPointer { + let memory = UnsafeMutableRawPointer.allocate(byteCount: Ability.size, alignment: Ability.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: Ability.size) + memory.storeBytes(of: id, toByteOffset: 0, as: UInt32.self) + memory.storeBytes(of: distance, toByteOffset: 4, as: UInt32.self) + return memory +} + +} + +// MARK: - Example + + +public struct InParentNamespace: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsInParentNamespace(bb: ByteBuffer) -> InParentNamespace { return InParentNamespace(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) } + + public static func startInParentNamespace(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 0) } + public static func endInParentNamespace(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + +public enum Example2 { + +public struct Monster: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsMonster(bb: ByteBuffer) -> Monster { return Monster(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) } + + public static func startMonster(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 0) } + public static func endMonster(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + +} + +// MARK: - Example2 + + +} +extension MyGame.Example { + +public struct TestSimpleTableWithEnum: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsTestSimpleTableWithEnum(bb: ByteBuffer) -> TestSimpleTableWithEnum { return TestSimpleTableWithEnum(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) } + + public var color: MyGame.Example.Color { let o = _accessor.offset(4); return o == 0 ? MyGame.Example.Color.green : MyGame.Example.Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? MyGame.Example.Color.green } + public func mutate(color: MyGame.Example.Color) -> Bool {let o = _accessor.offset(4); return _accessor.mutate(color.rawValue, index: o) } + public static func startTestSimpleTableWithEnum(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } + public static func add(color: MyGame.Example.Color, _ fbb: FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 2, at: 0) } + public static func endTestSimpleTableWithEnum(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + +public struct Stat: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsStat(bb: ByteBuffer) -> Stat { return Stat(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) } + + public var id: String? { let o = _accessor.offset(4); return o == 0 ? nil : _accessor.string(at: o) } + public var idSegmentArray: [UInt8]? { return _accessor.getVector(at: 4) } + public var val: Int64 { let o = _accessor.offset(6); return o == 0 ? 0 : _accessor.readBuffer(of: Int64.self, at: o) } + public func mutate(val: Int64) -> Bool {let o = _accessor.offset(6); return _accessor.mutate(val, index: o) } + public var count: UInt16 { let o = _accessor.offset(8); return o == 0 ? 0 : _accessor.readBuffer(of: UInt16.self, at: o) } + public func mutate(count: UInt16) -> Bool {let o = _accessor.offset(8); return _accessor.mutate(count, index: o) } + public static func startStat(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 3) } + public static func add(id: Offset<String>, _ fbb: FlatBufferBuilder) { fbb.add(offset: id, at: 0) } + public static func add(val: Int64, _ fbb: FlatBufferBuilder) { fbb.add(element: val, def: 0, at: 1) } + public static func add(count: UInt16, _ fbb: FlatBufferBuilder) { fbb.add(element: count, def: 0, at: 2) } + public static func endStat(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + +public struct Referrable: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsReferrable(bb: ByteBuffer) -> Referrable { return Referrable(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) } + + public var id: UInt64 { let o = _accessor.offset(4); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(id: UInt64) -> Bool {let o = _accessor.offset(4); return _accessor.mutate(id, index: o) } + public static func startReferrable(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } + public static func add(id: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: id, def: 0, at: 0) } + public static func endReferrable(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } + public static func sortVectorOfReferrable(offsets:[Offset<UOffset>], _ fbb: FlatBufferBuilder) -> Offset<UOffset> { + var off = offsets + off.sort { Table.compare(Table.offset(Int32($1.o), vOffset: 4, fbb: fbb.buffer), Table.offset(Int32($0.o), vOffset: 4, fbb: fbb.buffer), fbb: fbb.buffer) < 0 } + return fbb.createVector(ofOffsets: off) + } + fileprivate static func lookupByKey(vector: Int32, key: UInt64, fbb: ByteBuffer) -> Referrable? { + var span = fbb.read(def: Int32.self, position: Int(vector - 4)) + var start: Int32 = 0 + while span != 0 { + var middle = span / 2 + let tableOffset = Table.indirect(vector + 4 * (start + middle), fbb) + let comp = fbb.read(def: UInt64.self, position: Int(Table.offset(Int32(fbb.capacity) - tableOffset, vOffset: 4, fbb: fbb))) + if comp > 0 { + span = middle + } else if comp < 0 { + middle += 1 + start += middle + span -= middle + } else { + return Referrable(fbb, o: tableOffset) + } + } + return nil + } +} + +public struct Monster: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsMonster(bb: ByteBuffer) -> Monster { return Monster(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) } + + public var pos: MyGame.Example.Vec3? { let o = _accessor.offset(4); return o == 0 ? nil : MyGame.Example.Vec3(_accessor.bb, o: o + _accessor.postion) } + public var mana: Int16 { let o = _accessor.offset(6); return o == 0 ? 150 : _accessor.readBuffer(of: Int16.self, at: o) } + public func mutate(mana: Int16) -> Bool {let o = _accessor.offset(6); return _accessor.mutate(mana, index: o) } + public var hp: Int16 { let o = _accessor.offset(8); return o == 0 ? 100 : _accessor.readBuffer(of: Int16.self, at: o) } + public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(8); return _accessor.mutate(hp, index: o) } + public var name: String? { let o = _accessor.offset(10); return o == 0 ? nil : _accessor.string(at: o) } + public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: 10) } + public var inventoryCount: Int32 { let o = _accessor.offset(14); return o == 0 ? 0 : _accessor.vector(count: o) } + public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(14); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) } + public var inventory: [UInt8] { return _accessor.getVector(at: 14) ?? [] } + public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(14); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) } + public var color: MyGame.Example.Color { let o = _accessor.offset(16); return o == 0 ? MyGame.Example.Color.blue : MyGame.Example.Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? MyGame.Example.Color.blue } + public func mutate(color: MyGame.Example.Color) -> Bool {let o = _accessor.offset(16); return _accessor.mutate(color.rawValue, index: o) } + public var testType: MyGame.Example.Any_ { let o = _accessor.offset(18); return o == 0 ? MyGame.Example.Any_.none : MyGame.Example.Any_(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? MyGame.Example.Any_.none } + public func test<T: FlatBufferObject>(type: T.Type) -> T? { let o = _accessor.offset(20); return o == 0 ? nil : _accessor.union(o) } + public var test4Count: Int32 { let o = _accessor.offset(22); return o == 0 ? 0 : _accessor.vector(count: o) } + public func test4(at index: Int32) -> MyGame.Example.Test? { let o = _accessor.offset(22); return o == 0 ? nil : MyGame.Example.Test(_accessor.bb, o: _accessor.vector(at: o) + index * 4) } + public var testarrayofstringCount: Int32 { let o = _accessor.offset(24); return o == 0 ? 0 : _accessor.vector(count: o) } + public func testarrayofstring(at index: Int32) -> String? { let o = _accessor.offset(24); return o == 0 ? nil : _accessor.directString(at: _accessor.vector(at: o) + index * 4) } + public var testarrayoftablesCount: Int32 { let o = _accessor.offset(26); return o == 0 ? 0 : _accessor.vector(count: o) } + public func testarrayoftables(at index: Int32) -> MyGame.Example.Monster? { let o = _accessor.offset(26); return o == 0 ? nil : MyGame.Example.Monster(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) } + public func testarrayoftablesBy(key: String) -> MyGame.Example.Monster? { let o = _accessor.offset(26); return o == 0 ? nil : MyGame.Example.Monster.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb) } + public var enemy: MyGame.Example.Monster? { let o = _accessor.offset(28); return o == 0 ? nil : MyGame.Example.Monster(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public var testnestedflatbufferCount: Int32 { let o = _accessor.offset(30); return o == 0 ? 0 : _accessor.vector(count: o) } + public func testnestedflatbuffer(at index: Int32) -> UInt8 { let o = _accessor.offset(30); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) } + public var testnestedflatbuffer: [UInt8] { return _accessor.getVector(at: 30) ?? [] } + public func mutate(testnestedflatbuffer: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(30); return _accessor.directMutate(testnestedflatbuffer, index: _accessor.vector(at: o) + index * 1) } + public var testempty: MyGame.Example.Stat? { let o = _accessor.offset(32); return o == 0 ? nil : MyGame.Example.Stat(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public var testbool: Bool { let o = _accessor.offset(34); return o == 0 ? false : 0 != _accessor.readBuffer(of: Byte.self, at: o) } + public func mutate(testbool: Byte) -> Bool {let o = _accessor.offset(34); return _accessor.mutate(testbool, index: o) } + public var testhashs32Fnv1: Int32 { let o = _accessor.offset(36); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) } + public func mutate(testhashs32Fnv1: Int32) -> Bool {let o = _accessor.offset(36); return _accessor.mutate(testhashs32Fnv1, index: o) } + public var testhashu32Fnv1: UInt32 { let o = _accessor.offset(38); return o == 0 ? 0 : _accessor.readBuffer(of: UInt32.self, at: o) } + public func mutate(testhashu32Fnv1: UInt32) -> Bool {let o = _accessor.offset(38); return _accessor.mutate(testhashu32Fnv1, index: o) } + public var testhashs64Fnv1: Int64 { let o = _accessor.offset(40); return o == 0 ? 0 : _accessor.readBuffer(of: Int64.self, at: o) } + public func mutate(testhashs64Fnv1: Int64) -> Bool {let o = _accessor.offset(40); return _accessor.mutate(testhashs64Fnv1, index: o) } + public var testhashu64Fnv1: UInt64 { let o = _accessor.offset(42); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(testhashu64Fnv1: UInt64) -> Bool {let o = _accessor.offset(42); return _accessor.mutate(testhashu64Fnv1, index: o) } + public var testhashs32Fnv1a: Int32 { let o = _accessor.offset(44); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) } + public func mutate(testhashs32Fnv1a: Int32) -> Bool {let o = _accessor.offset(44); return _accessor.mutate(testhashs32Fnv1a, index: o) } + public var testhashu32Fnv1a: UInt32 { let o = _accessor.offset(46); return o == 0 ? 0 : _accessor.readBuffer(of: UInt32.self, at: o) } + public func mutate(testhashu32Fnv1a: UInt32) -> Bool {let o = _accessor.offset(46); return _accessor.mutate(testhashu32Fnv1a, index: o) } + public var testhashs64Fnv1a: Int64 { let o = _accessor.offset(48); return o == 0 ? 0 : _accessor.readBuffer(of: Int64.self, at: o) } + public func mutate(testhashs64Fnv1a: Int64) -> Bool {let o = _accessor.offset(48); return _accessor.mutate(testhashs64Fnv1a, index: o) } + public var testhashu64Fnv1a: UInt64 { let o = _accessor.offset(50); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(testhashu64Fnv1a: UInt64) -> Bool {let o = _accessor.offset(50); return _accessor.mutate(testhashu64Fnv1a, index: o) } + public var testarrayofboolsCount: Int32 { let o = _accessor.offset(52); return o == 0 ? 0 : _accessor.vector(count: o) } + public func testarrayofbools(at index: Int32) -> Bool { let o = _accessor.offset(52); return o == 0 ? true : 0 != _accessor.directRead(of: Byte.self, offset: _accessor.vector(at: o) + index * 1) } + public var testarrayofbools: [Byte] { return _accessor.getVector(at: 52) ?? [] } + public func mutate(testarrayofbools: Byte, at index: Int32) -> Bool { let o = _accessor.offset(52); return _accessor.directMutate(testarrayofbools, index: _accessor.vector(at: o) + index * 1) } + public var testf: Float32 { let o = _accessor.offset(54); return o == 0 ? 3.14159 : _accessor.readBuffer(of: Float32.self, at: o) } + public func mutate(testf: Float32) -> Bool {let o = _accessor.offset(54); return _accessor.mutate(testf, index: o) } + public var testf2: Float32 { let o = _accessor.offset(56); return o == 0 ? 3.0 : _accessor.readBuffer(of: Float32.self, at: o) } + public func mutate(testf2: Float32) -> Bool {let o = _accessor.offset(56); return _accessor.mutate(testf2, index: o) } + public var testf3: Float32 { let o = _accessor.offset(58); return o == 0 ? 0.0 : _accessor.readBuffer(of: Float32.self, at: o) } + public func mutate(testf3: Float32) -> Bool {let o = _accessor.offset(58); return _accessor.mutate(testf3, index: o) } + public var testarrayofstring2Count: Int32 { let o = _accessor.offset(60); return o == 0 ? 0 : _accessor.vector(count: o) } + public func testarrayofstring2(at index: Int32) -> String? { let o = _accessor.offset(60); return o == 0 ? nil : _accessor.directString(at: _accessor.vector(at: o) + index * 4) } + public var testarrayofsortedstructCount: Int32 { let o = _accessor.offset(62); return o == 0 ? 0 : _accessor.vector(count: o) } + public func testarrayofsortedstruct(at index: Int32) -> MyGame.Example.Ability? { let o = _accessor.offset(62); return o == 0 ? nil : MyGame.Example.Ability(_accessor.bb, o: _accessor.vector(at: o) + index * 8) } + public var flexCount: Int32 { let o = _accessor.offset(64); return o == 0 ? 0 : _accessor.vector(count: o) } + public func flex(at index: Int32) -> UInt8 { let o = _accessor.offset(64); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) } + public var flex: [UInt8] { return _accessor.getVector(at: 64) ?? [] } + public func mutate(flex: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(64); return _accessor.directMutate(flex, index: _accessor.vector(at: o) + index * 1) } + public var test5Count: Int32 { let o = _accessor.offset(66); return o == 0 ? 0 : _accessor.vector(count: o) } + public func test5(at index: Int32) -> MyGame.Example.Test? { let o = _accessor.offset(66); return o == 0 ? nil : MyGame.Example.Test(_accessor.bb, o: _accessor.vector(at: o) + index * 4) } + public var vectorOfLongsCount: Int32 { let o = _accessor.offset(68); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfLongs(at index: Int32) -> Int64 { let o = _accessor.offset(68); return o == 0 ? 0 : _accessor.directRead(of: Int64.self, offset: _accessor.vector(at: o) + index * 8) } + public var vectorOfLongs: [Int64] { return _accessor.getVector(at: 68) ?? [] } + public func mutate(vectorOfLongs: Int64, at index: Int32) -> Bool { let o = _accessor.offset(68); return _accessor.directMutate(vectorOfLongs, index: _accessor.vector(at: o) + index * 8) } + public var vectorOfDoublesCount: Int32 { let o = _accessor.offset(70); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfDoubles(at index: Int32) -> Double { let o = _accessor.offset(70); return o == 0 ? 0 : _accessor.directRead(of: Double.self, offset: _accessor.vector(at: o) + index * 8) } + public var vectorOfDoubles: [Double] { return _accessor.getVector(at: 70) ?? [] } + public func mutate(vectorOfDoubles: Double, at index: Int32) -> Bool { let o = _accessor.offset(70); return _accessor.directMutate(vectorOfDoubles, index: _accessor.vector(at: o) + index * 8) } + public var parentNamespaceTest: MyGame.InParentNamespace? { let o = _accessor.offset(72); return o == 0 ? nil : MyGame.InParentNamespace(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } + public var vectorOfReferrablesCount: Int32 { let o = _accessor.offset(74); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfReferrables(at index: Int32) -> MyGame.Example.Referrable? { let o = _accessor.offset(74); return o == 0 ? nil : MyGame.Example.Referrable(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) } + public func vectorOfReferrablesBy(key: UInt64) -> MyGame.Example.Referrable? { let o = _accessor.offset(74); return o == 0 ? nil : MyGame.Example.Referrable.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb) } + public var singleWeakReference: UInt64 { let o = _accessor.offset(76); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(singleWeakReference: UInt64) -> Bool {let o = _accessor.offset(76); return _accessor.mutate(singleWeakReference, index: o) } + public var vectorOfWeakReferencesCount: Int32 { let o = _accessor.offset(78); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfWeakReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(78); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) } + public var vectorOfWeakReferences: [UInt64] { return _accessor.getVector(at: 78) ?? [] } + public func mutate(vectorOfWeakReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(78); return _accessor.directMutate(vectorOfWeakReferences, index: _accessor.vector(at: o) + index * 8) } + public var vectorOfStrongReferrablesCount: Int32 { let o = _accessor.offset(80); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfStrongReferrables(at index: Int32) -> MyGame.Example.Referrable? { let o = _accessor.offset(80); return o == 0 ? nil : MyGame.Example.Referrable(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) } + public func vectorOfStrongReferrablesBy(key: UInt64) -> MyGame.Example.Referrable? { let o = _accessor.offset(80); return o == 0 ? nil : MyGame.Example.Referrable.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb) } + public var coOwningReference: UInt64 { let o = _accessor.offset(82); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(coOwningReference: UInt64) -> Bool {let o = _accessor.offset(82); return _accessor.mutate(coOwningReference, index: o) } + public var vectorOfCoOwningReferencesCount: Int32 { let o = _accessor.offset(84); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfCoOwningReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(84); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) } + public var vectorOfCoOwningReferences: [UInt64] { return _accessor.getVector(at: 84) ?? [] } + public func mutate(vectorOfCoOwningReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(84); return _accessor.directMutate(vectorOfCoOwningReferences, index: _accessor.vector(at: o) + index * 8) } + public var nonOwningReference: UInt64 { let o = _accessor.offset(86); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(nonOwningReference: UInt64) -> Bool {let o = _accessor.offset(86); return _accessor.mutate(nonOwningReference, index: o) } + public var vectorOfNonOwningReferencesCount: Int32 { let o = _accessor.offset(88); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfNonOwningReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(88); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) } + public var vectorOfNonOwningReferences: [UInt64] { return _accessor.getVector(at: 88) ?? [] } + public func mutate(vectorOfNonOwningReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(88); return _accessor.directMutate(vectorOfNonOwningReferences, index: _accessor.vector(at: o) + index * 8) } + public var anyUniqueType: MyGame.Example.AnyUniqueAliases { let o = _accessor.offset(90); return o == 0 ? MyGame.Example.AnyUniqueAliases.none : MyGame.Example.AnyUniqueAliases(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? MyGame.Example.AnyUniqueAliases.none } + public func anyUnique<T: FlatBufferObject>(type: T.Type) -> T? { let o = _accessor.offset(92); return o == 0 ? nil : _accessor.union(o) } + public var anyAmbiguousType: MyGame.Example.AnyAmbiguousAliases { let o = _accessor.offset(94); return o == 0 ? MyGame.Example.AnyAmbiguousAliases.none : MyGame.Example.AnyAmbiguousAliases(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? MyGame.Example.AnyAmbiguousAliases.none } + public func anyAmbiguous<T: FlatBufferObject>(type: T.Type) -> T? { let o = _accessor.offset(96); return o == 0 ? nil : _accessor.union(o) } + public var vectorOfEnumsCount: Int32 { let o = _accessor.offset(98); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vectorOfEnums(at index: Int32) -> MyGame.Example.Color? { let o = _accessor.offset(98); return o == 0 ? MyGame.Example.Color.red : MyGame.Example.Color(rawValue: _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1)) } + public var signedEnum: MyGame.Example.Race { let o = _accessor.offset(100); return o == 0 ? MyGame.Example.Race.none : MyGame.Example.Race(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? MyGame.Example.Race.none } + public func mutate(signedEnum: MyGame.Example.Race) -> Bool {let o = _accessor.offset(100); return _accessor.mutate(signedEnum.rawValue, index: o) } + public static func startMonster(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 49) } + public static func add(pos: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(structOffset: 0) } + public static func add(mana: Int16, _ fbb: FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: 1) } + public static func add(hp: Int16, _ fbb: FlatBufferBuilder) { fbb.add(element: hp, def: 100, at: 2) } + public static func add(name: Offset<String>, _ fbb: FlatBufferBuilder) { fbb.add(offset: name, at: 3) } + public static func addVectorOf(inventory: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: inventory, at: 5) } + public static func add(color: MyGame.Example.Color, _ fbb: FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 8, at: 6) } + public static func add(testType: MyGame.Example.Any_, _ fbb: FlatBufferBuilder) { fbb.add(element: testType.rawValue, def: 0, at: 7) } + public static func add(test: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: test, at: 8) } + public static func addVectorOf(test4: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: test4, at: 9) } + public static func addVectorOf(testarrayofstring: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testarrayofstring, at: 10) } + public static func addVectorOf(testarrayoftables: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testarrayoftables, at: 11) } + public static func add(enemy: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: enemy, at: 12) } + public static func addVectorOf(testnestedflatbuffer: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testnestedflatbuffer, at: 13) } + public static func add(testempty: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testempty, at: 14) } + public static func add(testbool: Bool, _ fbb: FlatBufferBuilder) { fbb.add(condition: testbool, def: false, at: 15) } + public static func add(testhashs32Fnv1: Int32, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashs32Fnv1, def: 0, at: 16) } + public static func add(testhashu32Fnv1: UInt32, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashu32Fnv1, def: 0, at: 17) } + public static func add(testhashs64Fnv1: Int64, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashs64Fnv1, def: 0, at: 18) } + public static func add(testhashu64Fnv1: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashu64Fnv1, def: 0, at: 19) } + public static func add(testhashs32Fnv1a: Int32, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashs32Fnv1a, def: 0, at: 20) } + public static func add(testhashu32Fnv1a: UInt32, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashu32Fnv1a, def: 0, at: 21) } + public static func add(testhashs64Fnv1a: Int64, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashs64Fnv1a, def: 0, at: 22) } + public static func add(testhashu64Fnv1a: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: testhashu64Fnv1a, def: 0, at: 23) } + public static func addVectorOf(testarrayofbools: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testarrayofbools, at: 24) } + public static func add(testf: Float32, _ fbb: FlatBufferBuilder) { fbb.add(element: testf, def: 3.14159, at: 25) } + public static func add(testf2: Float32, _ fbb: FlatBufferBuilder) { fbb.add(element: testf2, def: 3.0, at: 26) } + public static func add(testf3: Float32, _ fbb: FlatBufferBuilder) { fbb.add(element: testf3, def: 0.0, at: 27) } + public static func addVectorOf(testarrayofstring2: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testarrayofstring2, at: 28) } + public static func addVectorOf(testarrayofsortedstruct: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: testarrayofsortedstruct, at: 29) } + public static func addVectorOf(flex: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: flex, at: 30) } + public static func addVectorOf(test5: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: test5, at: 31) } + public static func addVectorOf(vectorOfLongs: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfLongs, at: 32) } + public static func addVectorOf(vectorOfDoubles: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfDoubles, at: 33) } + public static func add(parentNamespaceTest: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: parentNamespaceTest, at: 34) } + public static func addVectorOf(vectorOfReferrables: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfReferrables, at: 35) } + public static func add(singleWeakReference: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: singleWeakReference, def: 0, at: 36) } + public static func addVectorOf(vectorOfWeakReferences: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfWeakReferences, at: 37) } + public static func addVectorOf(vectorOfStrongReferrables: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfStrongReferrables, at: 38) } + public static func add(coOwningReference: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: coOwningReference, def: 0, at: 39) } + public static func addVectorOf(vectorOfCoOwningReferences: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfCoOwningReferences, at: 40) } + public static func add(nonOwningReference: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: nonOwningReference, def: 0, at: 41) } + public static func addVectorOf(vectorOfNonOwningReferences: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfNonOwningReferences, at: 42) } + public static func add(anyUniqueType: MyGame.Example.AnyUniqueAliases, _ fbb: FlatBufferBuilder) { fbb.add(element: anyUniqueType.rawValue, def: 0, at: 43) } + public static func add(anyUnique: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: anyUnique, at: 44) } + public static func add(anyAmbiguousType: MyGame.Example.AnyAmbiguousAliases, _ fbb: FlatBufferBuilder) { fbb.add(element: anyAmbiguousType.rawValue, def: 0, at: 45) } + public static func add(anyAmbiguous: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: anyAmbiguous, at: 46) } + public static func addVectorOf(vectorOfEnums: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vectorOfEnums, at: 47) } + public static func add(signedEnum: MyGame.Example.Race, _ fbb: FlatBufferBuilder) { fbb.add(element: signedEnum.rawValue, def: -1, at: 48) } + public static func endMonster(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); fbb.require(table: end, fields: [10]); return end } + public static func sortVectorOfMonster(offsets:[Offset<UOffset>], _ fbb: FlatBufferBuilder) -> Offset<UOffset> { + var off = offsets + off.sort { Table.compare(Table.offset(Int32($1.o), vOffset: 10, fbb: fbb.buffer), Table.offset(Int32($0.o), vOffset: 10, fbb: fbb.buffer), fbb: fbb.buffer) < 0 } + return fbb.createVector(ofOffsets: off) + } + fileprivate static func lookupByKey(vector: Int32, key: String, fbb: ByteBuffer) -> Monster? { + let key = key.utf8.map { $0 } + var span = fbb.read(def: Int32.self, position: Int(vector - 4)) + var start: Int32 = 0 + while span != 0 { + var middle = span / 2 + let tableOffset = Table.indirect(vector + 4 * (start + middle), fbb) + let comp = Table.compare(Table.offset(Int32(fbb.capacity) - tableOffset, vOffset: 10, fbb: fbb), key, fbb: fbb) + if comp > 0 { + span = middle + } else if comp < 0 { + middle += 1 + start += middle + span -= middle + } else { + return Monster(fbb, o: tableOffset) + } + } + return nil + } +} + +public struct TypeAliases: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MONS", addPrefix: prefix) } + public static func getRootAsTypeAliases(bb: ByteBuffer) -> TypeAliases { return TypeAliases(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) } + + public var i8: Int8 { let o = _accessor.offset(4); return o == 0 ? 0 : _accessor.readBuffer(of: Int8.self, at: o) } + public func mutate(i8: Int8) -> Bool {let o = _accessor.offset(4); return _accessor.mutate(i8, index: o) } + public var u8: UInt8 { let o = _accessor.offset(6); return o == 0 ? 0 : _accessor.readBuffer(of: UInt8.self, at: o) } + public func mutate(u8: UInt8) -> Bool {let o = _accessor.offset(6); return _accessor.mutate(u8, index: o) } + public var i16: Int16 { let o = _accessor.offset(8); return o == 0 ? 0 : _accessor.readBuffer(of: Int16.self, at: o) } + public func mutate(i16: Int16) -> Bool {let o = _accessor.offset(8); return _accessor.mutate(i16, index: o) } + public var u16: UInt16 { let o = _accessor.offset(10); return o == 0 ? 0 : _accessor.readBuffer(of: UInt16.self, at: o) } + public func mutate(u16: UInt16) -> Bool {let o = _accessor.offset(10); return _accessor.mutate(u16, index: o) } + public var i32: Int32 { let o = _accessor.offset(12); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) } + public func mutate(i32: Int32) -> Bool {let o = _accessor.offset(12); return _accessor.mutate(i32, index: o) } + public var u32: UInt32 { let o = _accessor.offset(14); return o == 0 ? 0 : _accessor.readBuffer(of: UInt32.self, at: o) } + public func mutate(u32: UInt32) -> Bool {let o = _accessor.offset(14); return _accessor.mutate(u32, index: o) } + public var i64: Int64 { let o = _accessor.offset(16); return o == 0 ? 0 : _accessor.readBuffer(of: Int64.self, at: o) } + public func mutate(i64: Int64) -> Bool {let o = _accessor.offset(16); return _accessor.mutate(i64, index: o) } + public var u64: UInt64 { let o = _accessor.offset(18); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public func mutate(u64: UInt64) -> Bool {let o = _accessor.offset(18); return _accessor.mutate(u64, index: o) } + public var f32: Float32 { let o = _accessor.offset(20); return o == 0 ? 0.0 : _accessor.readBuffer(of: Float32.self, at: o) } + public func mutate(f32: Float32) -> Bool {let o = _accessor.offset(20); return _accessor.mutate(f32, index: o) } + public var f64: Double { let o = _accessor.offset(22); return o == 0 ? 0.0 : _accessor.readBuffer(of: Double.self, at: o) } + public func mutate(f64: Double) -> Bool {let o = _accessor.offset(22); return _accessor.mutate(f64, index: o) } + public var v8Count: Int32 { let o = _accessor.offset(24); return o == 0 ? 0 : _accessor.vector(count: o) } + public func v8(at index: Int32) -> Int8 { let o = _accessor.offset(24); return o == 0 ? 0 : _accessor.directRead(of: Int8.self, offset: _accessor.vector(at: o) + index * 1) } + public var v8: [Int8] { return _accessor.getVector(at: 24) ?? [] } + public func mutate(v8: Int8, at index: Int32) -> Bool { let o = _accessor.offset(24); return _accessor.directMutate(v8, index: _accessor.vector(at: o) + index * 1) } + public var vf64Count: Int32 { let o = _accessor.offset(26); return o == 0 ? 0 : _accessor.vector(count: o) } + public func vf64(at index: Int32) -> Double { let o = _accessor.offset(26); return o == 0 ? 0 : _accessor.directRead(of: Double.self, offset: _accessor.vector(at: o) + index * 8) } + public var vf64: [Double] { return _accessor.getVector(at: 26) ?? [] } + public func mutate(vf64: Double, at index: Int32) -> Bool { let o = _accessor.offset(26); return _accessor.directMutate(vf64, index: _accessor.vector(at: o) + index * 8) } + public static func startTypeAliases(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 12) } + public static func add(i8: Int8, _ fbb: FlatBufferBuilder) { fbb.add(element: i8, def: 0, at: 0) } + public static func add(u8: UInt8, _ fbb: FlatBufferBuilder) { fbb.add(element: u8, def: 0, at: 1) } + public static func add(i16: Int16, _ fbb: FlatBufferBuilder) { fbb.add(element: i16, def: 0, at: 2) } + public static func add(u16: UInt16, _ fbb: FlatBufferBuilder) { fbb.add(element: u16, def: 0, at: 3) } + public static func add(i32: Int32, _ fbb: FlatBufferBuilder) { fbb.add(element: i32, def: 0, at: 4) } + public static func add(u32: UInt32, _ fbb: FlatBufferBuilder) { fbb.add(element: u32, def: 0, at: 5) } + public static func add(i64: Int64, _ fbb: FlatBufferBuilder) { fbb.add(element: i64, def: 0, at: 6) } + public static func add(u64: UInt64, _ fbb: FlatBufferBuilder) { fbb.add(element: u64, def: 0, at: 7) } + public static func add(f32: Float32, _ fbb: FlatBufferBuilder) { fbb.add(element: f32, def: 0.0, at: 8) } + public static func add(f64: Double, _ fbb: FlatBufferBuilder) { fbb.add(element: f64, def: 0.0, at: 9) } + public static func addVectorOf(v8: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: v8, at: 10) } + public static func addVectorOf(vf64: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: vf64, at: 11) } + public static func endTypeAliases(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + +} + +// MARK: - Example + + +// MARK: - MyGame + + diff --git a/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift new file mode 100644 index 00000000..c1c6aca9 --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests/union_vector_generated.swift @@ -0,0 +1,82 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +import FlatBuffers + +public enum Character: UInt8, Enum { + public typealias T = UInt8 + public static var byteSize: Int { return MemoryLayout<UInt8>.size } + public var value: UInt8 { return self.rawValue } + case none = 0, mulan = 1, rapunzel = 2, belle = 3, bookfan = 4, other = 5, unused = 6 +} + +public struct Rapunzel: Readable { + private var _accessor: Struct + public static var size = 4 + public static var alignment = 4 + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) } + + public var hairLength: Int32 { return _accessor.readBuffer(of: Int32.self, at: 0) } + public func mutate(hairLength: Int32) -> Bool { return _accessor.mutate(hairLength, index: 0) } +} + +public struct BookReader: Readable { + private var _accessor: Struct + public static var size = 4 + public static var alignment = 4 + public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) } + + public var booksRead: Int32 { return _accessor.readBuffer(of: Int32.self, at: 0) } + public func mutate(booksRead: Int32) -> Bool { return _accessor.mutate(booksRead, index: 0) } +} + +public func createRapunzel(hairLength: Int32) -> UnsafeMutableRawPointer { + let memory = UnsafeMutableRawPointer.allocate(byteCount: Rapunzel.size, alignment: Rapunzel.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: Rapunzel.size) + memory.storeBytes(of: hairLength, toByteOffset: 0, as: Int32.self) + return memory +} + +public func createBookReader(booksRead: Int32) -> UnsafeMutableRawPointer { + let memory = UnsafeMutableRawPointer.allocate(byteCount: BookReader.size, alignment: BookReader.alignment) + memory.initializeMemory(as: UInt8.self, repeating: 0, count: BookReader.size) + memory.storeBytes(of: booksRead, toByteOffset: 0, as: Int32.self) + return memory +} + +public struct Attacker: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MOVI", addPrefix: prefix) } + public static func getRootAsAttacker(bb: ByteBuffer) -> Attacker { return Attacker(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) } + + public var swordAttackDamage: Int32 { let o = _accessor.offset(4); return o == 0 ? 0 : _accessor.readBuffer(of: Int32.self, at: o) } + public func mutate(swordAttackDamage: Int32) -> Bool {let o = _accessor.offset(4); return _accessor.mutate(swordAttackDamage, index: o) } + public static func startAttacker(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) } + public static func add(swordAttackDamage: Int32, _ fbb: FlatBufferBuilder) { fbb.add(element: swordAttackDamage, def: 0, at: 0) } + public static func endAttacker(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + +public struct Movie: FlatBufferObject { + private var _accessor: Table + public static func finish(_ fbb: FlatBufferBuilder, end: Offset<UOffset>, prefix: Bool = false) { fbb.finish(offset: end, fileId: "MOVI", addPrefix: prefix) } + public static func getRootAsMovie(bb: ByteBuffer) -> Movie { return Movie(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) } + + public var mainCharacterType: Character { let o = _accessor.offset(4); return o == 0 ? Character.none : Character(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? Character.none } + public func mainCharacter<T: FlatBufferObject>(type: T.Type) -> T? { let o = _accessor.offset(6); return o == 0 ? nil : _accessor.union(o) } + public var charactersTypeCount: Int32 { let o = _accessor.offset(8); return o == 0 ? 0 : _accessor.vector(count: o) } + public func charactersType(at index: Int32) -> Character? { let o = _accessor.offset(8); return o == 0 ? Character.none : Character(rawValue: _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1)) } + public var charactersCount: Int32 { let o = _accessor.offset(10); return o == 0 ? 0 : _accessor.vector(count: o) } + public func characters<T: FlatBufferObject>(at index: Int32, type: T.Type) -> T? { let o = _accessor.offset(10); return o == 0 ? nil : _accessor.directUnion(_accessor.vector(at: o) + index * 4) } + public static func startMovie(_ fbb: FlatBufferBuilder) -> UOffset { fbb.startTable(with: 4) } + public static func add(mainCharacterType: Character, _ fbb: FlatBufferBuilder) { fbb.add(element: mainCharacterType.rawValue, def: 0, at: 0) } + public static func add(mainCharacter: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: mainCharacter, at: 1) } + public static func addVectorOf(charactersType: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: charactersType, at: 2) } + public static func addVectorOf(characters: Offset<UOffset>, _ fbb: FlatBufferBuilder) { fbb.add(offset: characters, at: 3) } + public static func endMovie(_ fbb: FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } +} + diff --git a/tests/FlatBuffers.Test.Swift/Tests/LinuxMain.swift b/tests/FlatBuffers.Test.Swift/Tests/LinuxMain.swift new file mode 100644 index 00000000..1b16a78e --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/Tests/LinuxMain.swift @@ -0,0 +1,8 @@ +import XCTest + +import FlatBuffers_Test_SwiftTests + +var tests = [XCTestCaseEntry]() +tests += FlatBuffers_Test_SwiftTests.__allTests() + +XCTMain(tests) diff --git a/tests/FlatBuffers.Test.Swift/monsterdata_test.mon b/tests/FlatBuffers.Test.Swift/monsterdata_test.mon Binary files differnew file mode 100644 index 00000000..ba6cf278 --- /dev/null +++ b/tests/FlatBuffers.Test.Swift/monsterdata_test.mon |