[Swift] Implements FlatbuffersVector which confirms to RandomAccessCollection (#8752)

* Implements FlatbuffersVector in swift

Implements FlatbuffersVector which confirms to RandomAccessCollection,
this would give us semi-native sugary syntax to all the arrays in swift port.

This work will also be the foundation of using arrays in swift

* Fix failing tests for Swift
This commit is contained in:
mustiikhalil
2025-11-05 00:53:59 +01:00
committed by GitHub
parent 78a3d59a65
commit 5fe90a9160
63 changed files with 1554 additions and 1650 deletions

View File

@@ -50,14 +50,14 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
func testReadFromOtherLanguages() {
let path = {
#if os(macOS)
// Gets the current path of this test file then
// strips out the nested directories.
let filePath = URL(filePath: #file)
.deletingLastPathComponent()
return filePath.absoluteString
// Gets the current path of this test file then
// strips out the nested directories.
let filePath = URL(filePath: #file)
.deletingLastPathComponent()
return filePath.absoluteString
#else
return FileManager.default.currentDirectoryPath
.appending("/tests/swift/Tests/Flatbuffers")
return FileManager.default.currentDirectoryPath
.appending("/tests/swift/Tests/Flatbuffers")
#endif
}()
@@ -230,15 +230,15 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
// swiftformat:enable all
let unpacked =
array
.withUnsafeMutableBytes { memory -> MyGame_Example_MonsterT in
var bytes = ByteBuffer(
assumingMemoryBound: memory.baseAddress!,
capacity: memory.count)
var monster: Monster = getRoot(byteBuffer: &bytes)
readFlatbufferMonster(monster: &monster)
let unpacked = monster.unpack()
return unpacked
}
.withUnsafeMutableBytes { memory -> MyGame_Example_MonsterT in
var bytes = ByteBuffer(
assumingMemoryBound: memory.baseAddress!,
capacity: memory.count)
var monster: Monster = getRoot(byteBuffer: &bytes)
readFlatbufferMonster(monster: &monster)
let unpacked = monster.unpack()
return unpacked
}
readObjectApi(monster: unpacked)
}
@@ -257,10 +257,10 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let monster: Monster = getRoot(byteBuffer: &buffer)
let values = monster.testarrayofbools
XCTAssertEqual(boolArray, values)
XCTAssertEqual(boolArray.count, values.count)
for i in 0..<monster.testarrayofboolsCount {
XCTAssertEqual(boolArray[Int(i)], monster.testarrayofbools(at: i))
for (index, bool) in monster.testarrayofbools.enumerated() {
XCTAssertEqual(bool, boolArray[index])
}
}
@@ -453,9 +453,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let monster: Monster = getRoot(byteBuffer: &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")
XCTAssertEqual(monster.testarrayoftables[0].name, "Barney")
XCTAssertEqual(monster.testarrayoftables[1].name, "Frodo")
XCTAssertEqual(monster.testarrayoftables[2].name, "Wilma")
// Example of searching for a table by the key
XCTAssertNotNil(monster.testarrayoftablesBy(key: "Frodo"))
@@ -470,8 +470,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
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))
for i in 0..<monster.inventory.count {
XCTAssertEqual(monster.inventory[i], Byte(i + 1))
}
XCTAssertEqual(monster.mutate(inventory: 0, at: 0), true)
@@ -489,6 +489,13 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertTrue(vec?.mutate(x: 1) ?? false)
XCTAssertEqual(vec?.x, 1)
XCTAssertTrue(vec?.mutate(test1: 3) ?? false)
let mutableTest4 = monster.mutableTest4
let orignalValues = mutableTest4[0].a
XCTAssertEqual(mutableTest4[0].mutate(a: 100), true)
XCTAssertNotEqual(monster.test4[0].a, orignalValues)
XCTAssertEqual(monster.test4[0].a, 100)
XCTAssertEqual(mutableTest4[0].mutate(a: orignalValues), true)
}
func readFlatbufferMonster(monster: inout MyGame_Example_Monster) {
@@ -511,14 +518,14 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertEqual(monster.mutate(mana: 10), false)
XCTAssertEqual(monster.mana, 150)
XCTAssertEqual(monster.inventoryCount, 5)
XCTAssertEqual(monster.inventory.count, 5)
var sum: Byte = 0
for i in 0...monster.inventoryCount {
sum += monster.inventory(at: i)
for inventory in monster.inventory {
sum += inventory
}
XCTAssertEqual(sum, 10)
monster.withUnsafePointerToInventory { ptr in
monster.withUnsafePointerToInventory { ptr, count in
var sum: UInt8 = 0
for pointee in ptr.startIndex..<ptr.endIndex {
sum += ptr[pointee]
@@ -526,57 +533,49 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertEqual(sum, 10)
}
XCTAssertEqual(monster.test4Count, 2)
XCTAssertEqual(monster.test4.count, 2)
let test0 = monster.test4(at: 0)
let test1 = monster.test4(at: 1)
let test4 = monster.test4
var sum0 = 0
var sum1 = 0
if let a = test0?.a, let b = test0?.b {
sum0 = Int(a) + Int(b)
for test0 in test4 {
sum0 += Int(test0.a) + Int(test0.b)
}
if let a = test1?.a, let b = test1?.b {
sum1 = Int(a) + Int(b)
}
XCTAssertEqual(sum0 + sum1, 100)
XCTAssertEqual(sum0, 100)
monster.withUnsafePointerToTest4 { ptr in
monster.withUnsafePointerToTest4 { ptr, count in
guard let ptr = ptr.baseAddress else { return }
let bindedMemory: UnsafeBufferPointer<MyGame_Example_Test> =
UnsafeBufferPointer(
start: ptr.bindMemory(
to: MyGame_Example_Test.self,
capacity: Int(monster.test4Count)),
count: Int(monster.test4Count))
capacity: count),
count: count)
var pointerSum = 0
for pointee in bindedMemory.startIndex..<bindedMemory.endIndex {
pointerSum += Int(bindedMemory[pointee].a) + Int(bindedMemory[pointee].b)
pointerSum += Int(bindedMemory[pointee].a) +
Int(bindedMemory[pointee].b)
}
XCTAssertEqual(pointerSum, 100)
}
let mutableTest0 = monster.mutableTest4(at: 0)
let mutableTest1 = monster.mutableTest4(at: 1)
let mutableTest4 = monster.mutableTest4
var sum2 = 0
var sum3 = 0
if let a = mutableTest0?.a, let b = mutableTest0?.b {
sum2 = Int(a) + Int(b)
for test0 in mutableTest4 {
sum2 += Int(test0.a) + Int(test0.b)
}
if let a = mutableTest1?.a, let b = mutableTest1?.b {
sum3 = Int(a) + Int(b)
}
XCTAssertEqual(sum2 + sum3, 100)
XCTAssertEqual(sum2, 100)
XCTAssertEqual(monster.testarrayofstringCount, 2)
XCTAssertEqual(monster.testarrayofstring(at: 0), "test1")
XCTAssertEqual(monster.testarrayofstring(at: 1), "test2")
let stringArray = monster.testarrayofstring
XCTAssertEqual(stringArray.count, 2)
XCTAssertEqual(stringArray[0], "test1")
XCTAssertEqual(stringArray[1], "test2")
XCTAssertEqual(monster.testbool, true)
let array = monster.nameSegmentArray
XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster")
if 0 == monster.testarrayofboolsCount {
if 0 == monster.testarrayofbools.count {
XCTAssertEqual(monster.testarrayofbools.isEmpty, true)
} else {
XCTAssertEqual(monster.testarrayofbools.isEmpty, false)
@@ -611,17 +610,11 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
}
XCTAssertEqual(sum, 10)
XCTAssertEqual(monster.test4.count, 2)
let test0 = monster.test4[0]
let test1 = monster.test4[1]
var sum0 = 0
var sum1 = 0
if let a = test0?.a, let b = test0?.b {
sum0 = Int(a) + Int(b)
for test in monster.test4 {
sum0 += Int(test.a) + Int(test.b)
}
if let a = test1?.a, let b = test1?.b {
sum1 = Int(a) + Int(b)
}
XCTAssertEqual(sum0 + sum1, 100)
XCTAssertEqual(sum0, 100)
XCTAssertEqual(monster.testbool, true)
}
@@ -674,8 +667,11 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let monster: Monster = getRoot(byteBuffer: &buffer)
let values = monster.inventory
monster.withUnsafePointerToInventory {
XCTAssertEqual(Array($0), values)
monster.withUnsafePointerToInventory { ptr, count in
let array = Array(ptr)
for (index, value) in values.enumerated() {
XCTAssertEqual(array[index], value)
}
}
}
}

View File

@@ -192,8 +192,8 @@ class Country {
builder: inout FlatBufferBuilder,
name: String,
log: Int32,
lan: Int32
) -> Offset {
lan: Int32) -> Offset
{
createCountry(
builder: &builder,
offset: builder.create(string: name),
@@ -206,8 +206,8 @@ class Country {
builder: inout FlatBufferBuilder,
offset: Offset,
log: Int32,
lan: Int32
) -> Offset {
lan: Int32) -> Offset
{
let _start = builder.startTable(with: 3)
Country.add(builder: &builder, lng: log)
Country.add(builder: &builder, lan: lan)
@@ -218,8 +218,8 @@ class Country {
@inlinable
static func end(
builder: inout FlatBufferBuilder,
startOffset: UOffset
) -> Offset {
startOffset: UOffset) -> Offset
{
Offset(offset: builder.endTable(at: startOffset))
}

View File

@@ -119,8 +119,9 @@ final class FlatBuffersUnionTests: XCTestCase {
let monster = ColorsNameSpace.Monster
.getRootAsMonster(bb: builder.sizedBuffer)
XCTAssertEqual(monster.colorsCount, 2)
XCTAssertEqual(monster.colors(at: 0), .blue)
XCTAssertEqual(monster.colors(at: 1), .green)
let colors = monster.colors
XCTAssertEqual(colors[0], .blue)
XCTAssertEqual(colors[1], .green)
}
func testUnionVector() {
@@ -148,11 +149,12 @@ final class FlatBuffersUnionTests: XCTestCase {
var buffer = fb.sizedBuffer
var movie: Movie = getRoot(byteBuffer: &buffer)
XCTAssertEqual(movie.charactersTypeCount, Int32(characterType.count))
XCTAssertEqual(movie.charactersCount, Int32(characters.count))
XCTAssertEqual(movie.charactersType.count, characterType.count)
XCTAssertEqual(movie.characters.count, characters.count)
for i in 0..<movie.charactersTypeCount {
XCTAssertEqual(movie.charactersType(at: i), characterType[Int(i)])
let bufferCharactersType = movie.charactersType
for (index, element) in bufferCharactersType.enumerated() {
XCTAssertEqual(element, characterType[index])
}
XCTAssertEqual(
@@ -167,8 +169,7 @@ final class FlatBuffersUnionTests: XCTestCase {
var objc: MovieT? = movie.unpack()
XCTAssertEqual(
movie.charactersTypeCount,
Int32(objc?.characters.count ?? 0))
movie.charactersType.count, objc?.characters.count ?? 0)
XCTAssertEqual(
movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
(objc?.characters[0]?.value as? BookReader)?.booksRead)
@@ -268,27 +269,33 @@ final class FlatBuffersUnionTests: XCTestCase {
let reader: Movie = try getCheckedRoot(byteBuffer: &sizedBuffer)
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
_ = try encoder.encode(reader)
encoder.outputFormatting = [.sortedKeys]
let data = try encoder.encode(reader)
XCTAssertEqual(String(data: data, encoding: .utf8), jsonData)
} catch {
XCTFail(error.localizedDescription)
}
}
var jsonData: String {
"{\"characters_type\":[\"Belle\",\"MuLan\",\"BookFan\",\"Other\"],\"characters\":[{\"books_read\":7},{\"sword_attack_damage\":8},{\"books_read\":2},\"Awesome \\\\\\\\t\\t\\nstring!\"]}"
"""
{"characters":[{"books_read":7},{"sword_attack_damage":8},{"books_read":2},"Awesome \\\\\\\\t\\t\\nstring!"],"characters_type":["Belle","MuLan","BookFan","Other"]}
"""
}
}
public enum ColorsNameSpace {
enum RGB: Int32, Enum {
enum RGB: Int32, Enum, FlatbuffersVectorInitializable {
static var min: ColorsNameSpace.RGB { .red }
typealias T = Int32
static var byteSize: Int { MemoryLayout<Int32>.size }
var value: Int32 { rawValue }
case red = 0, green = 1, blue = 2
}
struct Monster: FlatBufferObject {
struct Monster: FlatBufferTable {
var __buffer: ByteBuffer! { _accessor.bb }
private var _accessor: Table
@@ -296,7 +303,8 @@ public enum ColorsNameSpace {
Monster(
Table(
bb: bb,
position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader)))
position: Int32(bb.read(def: UOffset.self, position: bb.reader)) +
Int32(bb.reader)))
}
init(_ t: Table) { _accessor = t }
@@ -307,20 +315,13 @@ public enum ColorsNameSpace {
return o == 0
? 0
: _accessor
.vector(count: o)
.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))
public var colors: FlatbufferVector<RGB> {
_accessor.vector(at: 4, byteSize: 4)
}
static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset {
fbb
.startTable(with: 1)
@@ -332,8 +333,7 @@ public enum ColorsNameSpace {
}
static func endMonster(
_ fbb: inout FlatBufferBuilder,
start: UOffset
)
start: UOffset)
-> Offset
{
let end = Offset(offset: fbb.endTable(at: start))
@@ -362,8 +362,8 @@ struct FinalMonster {
weapons: Offset,
equipment: Equipment = .none,
equippedOffset: Offset,
path: Offset
) -> Offset {
path: Offset) -> Offset
{
let start = builder.startTable(with: 11)
builder.create(struct: position, position: 4)
builder.add(element: hp, def: 100, at: 8)
@@ -391,7 +391,7 @@ struct LocalMonster {
func weapon(at index: Int32) -> Weapon? {
let o =
__t
.offset(4)
.offset(4)
return o == 0
? nil
: Weapon.assign(
@@ -399,7 +399,7 @@ struct LocalMonster {
__t.bb)
}
func equiped<T: FlatBufferObject>() -> T? {
func equiped<T: FlatBufferTable>() -> T? {
let o = __t.offset(8)
return o == 0 ? nil : __t.union(o)
}
@@ -416,8 +416,8 @@ struct LocalMonster {
builder: inout FlatBufferBuilder,
offset: Offset,
equipment: Equipment = .none,
equippedOffset: UOffset
) -> Offset {
equippedOffset: UOffset) -> Offset
{
let start = builder.startTable(with: 3)
builder.add(element: equippedOffset, def: 0, at: 8)
builder.add(offset: offset, at: 4)
@@ -429,7 +429,7 @@ struct LocalMonster {
}
}
struct Weapon: FlatBufferObject {
struct Weapon: FlatBufferTable {
var __buffer: ByteBuffer! { __t.bb }
@@ -464,8 +464,8 @@ struct Weapon: FlatBufferObject {
static func createWeapon(
builder: inout FlatBufferBuilder,
offset: Offset,
dmg: Int16
) -> Offset {
dmg: Int16) -> Offset
{
let _start = builder.startTable(with: 2)
Weapon.add(builder: &builder, name: offset)
Weapon.add(builder: &builder, dmg: dmg)
@@ -475,8 +475,8 @@ struct Weapon: FlatBufferObject {
@inlinable
static func end(
builder: inout FlatBufferBuilder,
startOffset: UOffset
) -> Offset {
startOffset: UOffset) -> Offset
{
Offset(offset: builder.endTable(at: startOffset))
}

View File

@@ -135,7 +135,9 @@ final class FlatBuffersVectors: XCTestCase {
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])
for (index, num) in number.vArrayInt32.enumerated() {
XCTAssertEqual(num, data[index])
}
}
func testReadDoubleArray() {
@@ -145,7 +147,9 @@ final class FlatBuffersVectors: XCTestCase {
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])
for (index, num) in number.vArrayDouble.enumerated() {
XCTAssertEqual(num, data[index])
}
}
func testHasForArray() {
@@ -162,19 +166,22 @@ final class FlatBuffersVectors: XCTestCase {
var byteBuffer = ByteBuffer(bytes: builder.sizedByteArray)
let msg: Swift_Tests_Vectors = getRoot(byteBuffer: &byteBuffer)
XCTAssertEqual(msg.hasNone, false)
XCTAssertEqual(msg.hasEmpty, true)
XCTAssertEqual(msg.emptyCount, 0)
XCTAssertEqual(msg.hasArray, true)
XCTAssertEqual(msg.arrayCount, 3)
XCTAssertEqual(msg.array, [1, 2, 3])
XCTAssertEqual(msg.none_.isEmpty, true)
XCTAssertEqual(msg.empty.isEmpty, true)
XCTAssertEqual(msg.empty.count, 0)
XCTAssertEqual(msg.array.isEmpty, false)
XCTAssertEqual(msg.array.count, 3)
let array = msg.withUnsafePointerToArray { ptr in
for i in msg.array.startIndex..<msg.array.endIndex {
XCTAssertEqual(msg.array[i], 1 + UInt64(i))
}
let array = msg.withUnsafePointerToArray { ptr, count in
let ptr: UnsafeBufferPointer<UInt64> = UnsafeBufferPointer(
start: ptr.baseAddress?.bindMemory(
to: UInt64.self,
capacity: Int(msg.arrayCount)),
count: Int(msg.arrayCount))
capacity: count),
count: count)
return Array(ptr)
}
@@ -198,36 +205,36 @@ struct Numbers {
position: Int32(bb.read(def: UOffset.self, position: 0))))
}
var vArrayInt: [Int]? { __t.getVector(at: 4) }
var vArrayInt32: [Int32]? { __t.getVector(at: 4) }
var vArrayDouble: [Double]? { __t.getVector(at: 4) }
var vArrayFloat: [Float32]? { __t.getVector(at: 4) }
var vArrayInt: FlatbufferVector<Int> { __t.vector(at: 4, byteSize: 8) }
var vArrayInt32: FlatbufferVector<Int32> { __t.vector(at: 4, byteSize: 4) }
var vArrayDouble: FlatbufferVector<Double> { __t.vector(at: 4, byteSize: 8) }
var vArrayFloat: FlatbufferVector<Float32> { __t.vector(at: 4, byteSize: 4) }
static func createNumbersVector(
b: inout FlatBufferBuilder,
array: [Int]
) -> Offset {
array: [Int]) -> Offset
{
b.createVector(array, size: array.count)
}
static func createNumbersVector(
b: inout FlatBufferBuilder,
array: [Int32]
) -> Offset {
array: [Int32]) -> Offset
{
b.createVector(array, size: array.count)
}
static func createNumbersVector(
b: inout FlatBufferBuilder,
array: [Double]
) -> Offset {
array: [Double]) -> Offset
{
b.createVector(array, size: array.count)
}
static func createNumbersVector(
b: inout FlatBufferBuilder,
array: [Float32]
) -> Offset {
array: [Float32]) -> Offset
{
b.createVector(array, size: array.count)
}

View File

@@ -78,8 +78,8 @@ class CountryDouble {
builder: inout FlatBufferBuilder,
name: String,
log: Double,
lan: Double
) -> Offset {
lan: Double) -> Offset
{
createCountry(
builder: &builder,
offset: builder.create(string: name),
@@ -91,8 +91,8 @@ class CountryDouble {
builder: inout FlatBufferBuilder,
offset: Offset,
log: Double,
lan: Double
) -> Offset {
lan: Double) -> Offset
{
let _start = builder.startTable(with: 3)
CountryDouble.add(builder: &builder, lng: log)
CountryDouble.add(builder: &builder, lan: lan)
@@ -102,8 +102,8 @@ class CountryDouble {
static func end(
builder: inout FlatBufferBuilder,
startOffset: UOffset
) -> Offset {
startOffset: UOffset) -> Offset
{
Offset(offset: builder.endTable(at: startOffset))
}

View File

@@ -29,13 +29,13 @@ class FlatBuffersMoreDefaults: XCTestCase {
let defaults: MoreDefaults = getRoot(byteBuffer: &byteBuffer)
XCTAssertEqual(defaults.emptyString, "")
XCTAssertEqual(defaults.someString, "some")
XCTAssertEqual(defaults.ints, [])
XCTAssertEqual(defaults.floats, [])
XCTAssertEqual(defaults.bools, [])
XCTAssertEqual(defaults.intsCount, 0)
XCTAssertEqual(defaults.floatsCount, 0)
XCTAssertEqual(defaults.abcsCount, 0)
XCTAssertEqual(defaults.boolsCount, 0)
XCTAssertEqual(defaults.ints.isEmpty, true)
XCTAssertEqual(defaults.floats.isEmpty, true)
XCTAssertEqual(defaults.bools.isEmpty, true)
XCTAssertEqual(defaults.ints.count, 0)
XCTAssertEqual(defaults.floats.count, 0)
XCTAssertEqual(defaults.abcs.count, 0)
XCTAssertEqual(defaults.bools.count, 0)
}
func testFlatbuffersObjectAPI() {
@@ -52,12 +52,12 @@ class FlatBuffersMoreDefaults: XCTestCase {
let fDefaults: MoreDefaults = getRoot(byteBuffer: &buffer)
XCTAssertEqual(fDefaults.emptyString, "")
XCTAssertEqual(fDefaults.someString, "some")
XCTAssertEqual(fDefaults.ints, [])
XCTAssertEqual(fDefaults.floats, [])
XCTAssertEqual(fDefaults.intsCount, 0)
XCTAssertEqual(fDefaults.floatsCount, 0)
XCTAssertEqual(fDefaults.abcsCount, 0)
XCTAssertEqual(fDefaults.boolsCount, 0)
XCTAssertEqual(fDefaults.ints.isEmpty, true)
XCTAssertEqual(fDefaults.floats.isEmpty, true)
XCTAssertEqual(fDefaults.ints.count, 0)
XCTAssertEqual(fDefaults.floats.count, 0)
XCTAssertEqual(fDefaults.abcs.count, 0)
XCTAssertEqual(fDefaults.bools.count, 0)
}
func testEncoding() {

View File

@@ -99,13 +99,17 @@ final class FlatbuffersVerifierTests: XCTestCase {
func testVeriferInitPassing() {
let memory = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 1)
var buffer = ByteBuffer(assumingMemoryBound: memory, capacity: Int(FlatBufferMaxSize) - 1)
var buffer = ByteBuffer(
assumingMemoryBound: memory,
capacity: Int(FlatBufferMaxSize) - 1)
XCTAssertNoThrow(try Verifier(buffer: &buffer))
}
func testVeriferInitFailing() {
let memory = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 1)
var buffer = ByteBuffer(assumingMemoryBound: memory, capacity: Int(FlatBufferMaxSize) + 1)
var buffer = ByteBuffer(
assumingMemoryBound: memory,
capacity: Int(FlatBufferMaxSize) + 1)
XCTAssertThrowsError(try Verifier(buffer: &buffer))
}
@@ -403,8 +407,8 @@ final class FlatbuffersVerifierTests: XCTestCase {
private func getOffset(
at value: Int,
within verifier: Verifier
) throws -> Int {
within verifier: Verifier) throws -> Int
{
let offset: UOffset = try verifier.getValue(at: value)
return Int(clamping: (Int(offset) &+ 0).magnitude)
}

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public struct Property: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct Property: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -51,7 +51,7 @@ extension Property: Encodable {
}
}
public struct Property_Mutable: FlatBufferObject {
public struct Property_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -76,7 +76,7 @@ public struct Property_Mutable: FlatBufferObject {
}
}
public struct TestMutatingBool: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct TestMutatingBool: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -9,7 +9,7 @@ import Common
import FlatBuffers
/// Composite components of Monster color.
public enum MyGame_Example_Color: UInt8, Enum, Verifiable {
public enum MyGame_Example_Color: UInt8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = UInt8
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
public var value: UInt8 { return self.rawValue }
@@ -35,7 +35,7 @@ extension MyGame_Example_Color: Encodable {
}
}
public enum MyGame_Example_Race: Int8, Enum, Verifiable {
public enum MyGame_Example_Race: Int8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue }
@@ -60,7 +60,7 @@ extension MyGame_Example_Race: Encodable {
}
}
public enum MyGame_Example_LongEnum: UInt64, Enum, Verifiable {
public enum MyGame_Example_LongEnum: UInt64, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = UInt64
public static var byteSize: Int { return MemoryLayout<UInt64>.size }
public var value: UInt64 { return self.rawValue }
@@ -83,7 +83,7 @@ extension MyGame_Example_LongEnum: Encodable {
}
}
public enum MyGame_Example_Any_: UInt8, UnionEnum {
public enum MyGame_Example_Any_: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -135,7 +135,7 @@ public struct MyGame_Example_Any_Union {
}
}
}
public enum MyGame_Example_AnyUniqueAliases: UInt8, UnionEnum {
public enum MyGame_Example_AnyUniqueAliases: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -187,7 +187,7 @@ public struct MyGame_Example_AnyUniqueAliasesUnion {
}
}
}
public enum MyGame_Example_AnyAmbiguousAliases: UInt8, UnionEnum {
public enum MyGame_Example_AnyAmbiguousAliases: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -239,7 +239,7 @@ public struct MyGame_Example_AnyAmbiguousAliasesUnion {
}
}
}
public struct MyGame_Example_Test: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_Test: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -293,7 +293,7 @@ extension MyGame_Example_Test: Encodable {
}
}
public struct MyGame_Example_Test_Mutable: FlatBufferObject {
public struct MyGame_Example_Test_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -320,7 +320,7 @@ public struct MyGame_Example_Test_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_Vec3: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -415,7 +415,7 @@ extension MyGame_Example_Vec3: Encodable {
}
}
public struct MyGame_Example_Vec3_Mutable: FlatBufferObject {
public struct MyGame_Example_Vec3_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -449,7 +449,7 @@ public struct MyGame_Example_Vec3_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_Ability: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_Ability: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -502,7 +502,7 @@ extension MyGame_Example_Ability: Encodable {
}
}
public struct MyGame_Example_Ability_Mutable: FlatBufferObject {
public struct MyGame_Example_Ability_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -529,7 +529,7 @@ public struct MyGame_Example_Ability_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_StructOfStructs: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_StructOfStructs: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -589,7 +589,7 @@ extension MyGame_Example_StructOfStructs: Encodable {
}
}
public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferObject {
public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -615,7 +615,7 @@ public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_StructOfStructsOfStructs: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_StructOfStructsOfStructs: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -657,7 +657,7 @@ extension MyGame_Example_StructOfStructsOfStructs: Encodable {
}
}
public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferObject {
public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -681,7 +681,7 @@ public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferObject
}
}
public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_InParentNamespace: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -733,7 +733,7 @@ public class MyGame_InParentNamespaceT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_InParentNamespace.self) }
}
public struct MyGame_Example2_Monster: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example2_Monster: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -785,7 +785,7 @@ public class MyGame_Example2_MonsterT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example2_Monster.self) }
}
internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferObject, Verifiable, ObjectAPIPacker {
internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
internal var __buffer: ByteBuffer! { return _accessor.bb }
@@ -866,7 +866,7 @@ internal class MyGame_Example_TestSimpleTableWithEnumT: NativeObject {
internal func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_TestSimpleTableWithEnum.self) }
}
public struct MyGame_Example_Stat: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_Stat: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1005,7 +1005,7 @@ public class MyGame_Example_StatT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Stat.self) }
}
public struct MyGame_Example_Referrable: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_Referrable: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1111,7 +1111,7 @@ public class MyGame_Example_ReferrableT: NativeObject {
}
/// an example documentation comment: "monster object"
public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_Monster: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1196,37 +1196,25 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
public var name: String! { let o = _accessor.offset(VTOFFSET.name.v); return _accessor.string(at: o) }
public var nameSegmentArray: [UInt8]! { return _accessor.getVector(at: VTOFFSET.name.v) }
public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
public var inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public var color: MyGame_Example_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Example_Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .blue }
@discardableResult public func mutate(color: MyGame_Example_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
public var testType: MyGame_Example_Any_ { let o = _accessor.offset(VTOFFSET.testType.v); return o == 0 ? .none_ : MyGame_Example_Any_(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func test<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.test.v); return o == 0 ? nil : _accessor.union(o) }
public var hasTest4: Bool { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? false : true }
public var test4Count: Int32 { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func test4(at index: Int32) -> MyGame_Example_Test? { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Example_Test.self, offset: _accessor.vector(at: o) + index * 4) }
public func mutableTest4(at index: Int32) -> MyGame_Example_Test_Mutable? { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? nil : MyGame_Example_Test_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 4) }
public func withUnsafePointerToTest4<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test4.v, body: body) }
public var hasTestarrayofstring: Bool { let o = _accessor.offset(VTOFFSET.testarrayofstring.v); return o == 0 ? false : true }
public var testarrayofstringCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofstring.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofstring(at index: Int32) -> String? { let o = _accessor.offset(VTOFFSET.testarrayofstring.v); return o == 0 ? nil : _accessor.directString(at: _accessor.vector(at: o) + index * 4) }
public var test4: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
public var mutableTest4: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
public func withUnsafePointerToTest4<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test4.v, body: body) }
public var testarrayofstring: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring.v, byteSize: 4) }
/// an example documentation comment: this will end up in the generated code
/// multiline too
public var hasTestarrayoftables: Bool { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? false : true }
public var testarrayoftablesCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayoftables(at index: Int32) -> MyGame_Example_Monster? { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? nil : MyGame_Example_Monster(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var testarrayoftables: FlatbufferVector<MyGame_Example_Monster> { return _accessor.vector(at: VTOFFSET.testarrayoftables.v, byteSize: 4) }
public func testarrayoftablesBy(key: String) -> MyGame_Example_Monster? { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); 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(VTOFFSET.enemy.v); return o == 0 ? nil : MyGame_Example_Monster(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
public var hasTestnestedflatbuffer: Bool { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return o == 0 ? false : true }
public var testnestedflatbufferCount: Int32 { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testnestedflatbuffer(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var testnestedflatbuffer: [UInt8] { return _accessor.getVector(at: VTOFFSET.testnestedflatbuffer.v) ?? [] }
public var testnestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testnestedflatbuffer.v, byteSize: 1) }
public func mutate(testnestedflatbuffer: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return _accessor.directMutate(testnestedflatbuffer, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToTestnestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testnestedflatbuffer.v, body: body) }
public func withUnsafePointerToTestnestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testnestedflatbuffer.v, body: body) }
public var testempty: MyGame_Example_Stat? { let o = _accessor.offset(VTOFFSET.testempty.v); return o == 0 ? nil : MyGame_Example_Stat(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
public var testbool: Bool { let o = _accessor.offset(VTOFFSET.testbool.v); return o == 0 ? false : _accessor.readBuffer(of: Bool.self, at: o) }
@discardableResult public func mutate(testbool: Bool) -> Bool {let o = _accessor.offset(VTOFFSET.testbool.v); return _accessor.mutate(testbool, index: o) }
@@ -1246,100 +1234,62 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
@discardableResult public func mutate(testhashs64Fnv1a: Int64) -> Bool {let o = _accessor.offset(VTOFFSET.testhashs64Fnv1a.v); return _accessor.mutate(testhashs64Fnv1a, index: o) }
public var testhashu64Fnv1a: UInt64 { let o = _accessor.offset(VTOFFSET.testhashu64Fnv1a.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(testhashu64Fnv1a: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.testhashu64Fnv1a.v); return _accessor.mutate(testhashu64Fnv1a, index: o) }
public var hasTestarrayofbools: Bool { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return o == 0 ? false : true }
public var testarrayofboolsCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofbools(at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return o == 0 ? true : _accessor.directRead(of: Bool.self, offset: _accessor.vector(at: o) + index * 1) }
public var testarrayofbools: [Bool] { return _accessor.getVector(at: VTOFFSET.testarrayofbools.v) ?? [] }
public var testarrayofbools: FlatbufferVector<Bool> { return _accessor.vector(at: VTOFFSET.testarrayofbools.v, byteSize: 1) }
public func mutate(testarrayofbools: Bool, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return _accessor.directMutate(testarrayofbools, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToTestarrayofbools<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofbools.v, body: body) }
public func withUnsafePointerToTestarrayofbools<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofbools.v, body: body) }
public var testf: Float32 { let o = _accessor.offset(VTOFFSET.testf.v); return o == 0 ? 3.14159 : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(testf: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.testf.v); return _accessor.mutate(testf, index: o) }
public var testf2: Float32 { let o = _accessor.offset(VTOFFSET.testf2.v); return o == 0 ? 3.0 : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(testf2: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.testf2.v); return _accessor.mutate(testf2, index: o) }
public var testf3: Float32 { let o = _accessor.offset(VTOFFSET.testf3.v); return o == 0 ? 0.0 : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(testf3: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.testf3.v); return _accessor.mutate(testf3, index: o) }
public var hasTestarrayofstring2: Bool { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? false : true }
public var testarrayofstring2Count: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofstring2(at index: Int32) -> String? { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? nil : _accessor.directString(at: _accessor.vector(at: o) + index * 4) }
public var hasTestarrayofsortedstruct: Bool { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? false : true }
public var testarrayofsortedstructCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofsortedstruct(at index: Int32) -> MyGame_Example_Ability? { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Example_Ability.self, offset: _accessor.vector(at: o) + index * 8) }
public func mutableTestarrayofsortedstruct(at index: Int32) -> MyGame_Example_Ability_Mutable? { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? nil : MyGame_Example_Ability_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToTestarrayofsortedstruct<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofsortedstruct.v, body: body) }
public var hasFlex: Bool { let o = _accessor.offset(VTOFFSET.flex.v); return o == 0 ? false : true }
public var flexCount: Int32 { let o = _accessor.offset(VTOFFSET.flex.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func flex(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.flex.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var flex: [UInt8] { return _accessor.getVector(at: VTOFFSET.flex.v) ?? [] }
public var testarrayofstring2: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring2.v, byteSize: 4) }
public var testarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
public var mutableTestarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability_Mutable> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
public func withUnsafePointerToTestarrayofsortedstruct<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofsortedstruct.v, body: body) }
public var flex: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.flex.v, byteSize: 1) }
public func mutate(flex: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.flex.v); return _accessor.directMutate(flex, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToFlex<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.flex.v, body: body) }
public var hasTest5: Bool { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? false : true }
public var test5Count: Int32 { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func test5(at index: Int32) -> MyGame_Example_Test? { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Example_Test.self, offset: _accessor.vector(at: o) + index * 4) }
public func mutableTest5(at index: Int32) -> MyGame_Example_Test_Mutable? { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? nil : MyGame_Example_Test_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 4) }
public func withUnsafePointerToTest5<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test5.v, body: body) }
public var hasVectorOfLongs: Bool { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return o == 0 ? false : true }
public var vectorOfLongsCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfLongs(at index: Int32) -> Int64 { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return o == 0 ? 0 : _accessor.directRead(of: Int64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfLongs: [Int64] { return _accessor.getVector(at: VTOFFSET.vectorOfLongs.v) ?? [] }
public func withUnsafePointerToFlex<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.flex.v, body: body) }
public var test5: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
public var mutableTest5: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
public func withUnsafePointerToTest5<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test5.v, body: body) }
public var vectorOfLongs: FlatbufferVector<Int64> { return _accessor.vector(at: VTOFFSET.vectorOfLongs.v, byteSize: 8) }
public func mutate(vectorOfLongs: Int64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return _accessor.directMutate(vectorOfLongs, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfLongs<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfLongs.v, body: body) }
public var hasVectorOfDoubles: Bool { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return o == 0 ? false : true }
public var vectorOfDoublesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfDoubles(at index: Int32) -> Double { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return o == 0 ? 0 : _accessor.directRead(of: Double.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfDoubles: [Double] { return _accessor.getVector(at: VTOFFSET.vectorOfDoubles.v) ?? [] }
public func withUnsafePointerToVectorOfLongs<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfLongs.v, body: body) }
public var vectorOfDoubles: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vectorOfDoubles.v, byteSize: 8) }
public func mutate(vectorOfDoubles: Double, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return _accessor.directMutate(vectorOfDoubles, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfDoubles<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfDoubles.v, body: body) }
public func withUnsafePointerToVectorOfDoubles<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfDoubles.v, body: body) }
public var parentNamespaceTest: MyGame_InParentNamespace? { let o = _accessor.offset(VTOFFSET.parentNamespaceTest.v); return o == 0 ? nil : MyGame_InParentNamespace(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
public var hasVectorOfReferrables: Bool { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); return o == 0 ? false : true }
public var vectorOfReferrablesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfReferrables(at index: Int32) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); return o == 0 ? nil : MyGame_Example_Referrable(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var vectorOfReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfReferrables.v, byteSize: 4) }
public func vectorOfReferrablesBy(key: UInt64) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); 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(VTOFFSET.singleWeakReference.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(singleWeakReference: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.singleWeakReference.v); return _accessor.mutate(singleWeakReference, index: o) }
public var hasVectorOfWeakReferences: Bool { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return o == 0 ? false : true }
public var vectorOfWeakReferencesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfWeakReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfWeakReferences: [UInt64] { return _accessor.getVector(at: VTOFFSET.vectorOfWeakReferences.v) ?? [] }
public var vectorOfWeakReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfWeakReferences.v, byteSize: 8) }
public func mutate(vectorOfWeakReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return _accessor.directMutate(vectorOfWeakReferences, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfWeakReferences<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfWeakReferences.v, body: body) }
public var hasVectorOfStrongReferrables: Bool { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); return o == 0 ? false : true }
public var vectorOfStrongReferrablesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfStrongReferrables(at index: Int32) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); return o == 0 ? nil : MyGame_Example_Referrable(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public func withUnsafePointerToVectorOfWeakReferences<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfWeakReferences.v, body: body) }
public var vectorOfStrongReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfStrongReferrables.v, byteSize: 4) }
public func vectorOfStrongReferrablesBy(key: UInt64) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); 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(VTOFFSET.coOwningReference.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(coOwningReference: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.coOwningReference.v); return _accessor.mutate(coOwningReference, index: o) }
public var hasVectorOfCoOwningReferences: Bool { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return o == 0 ? false : true }
public var vectorOfCoOwningReferencesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfCoOwningReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfCoOwningReferences: [UInt64] { return _accessor.getVector(at: VTOFFSET.vectorOfCoOwningReferences.v) ?? [] }
public var vectorOfCoOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfCoOwningReferences.v, byteSize: 8) }
public func mutate(vectorOfCoOwningReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return _accessor.directMutate(vectorOfCoOwningReferences, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfCoOwningReferences<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfCoOwningReferences.v, body: body) }
public func withUnsafePointerToVectorOfCoOwningReferences<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfCoOwningReferences.v, body: body) }
public var nonOwningReference: UInt64 { let o = _accessor.offset(VTOFFSET.nonOwningReference.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(nonOwningReference: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.nonOwningReference.v); return _accessor.mutate(nonOwningReference, index: o) }
public var hasVectorOfNonOwningReferences: Bool { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return o == 0 ? false : true }
public var vectorOfNonOwningReferencesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfNonOwningReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfNonOwningReferences: [UInt64] { return _accessor.getVector(at: VTOFFSET.vectorOfNonOwningReferences.v) ?? [] }
public var vectorOfNonOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfNonOwningReferences.v, byteSize: 8) }
public func mutate(vectorOfNonOwningReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return _accessor.directMutate(vectorOfNonOwningReferences, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfNonOwningReferences<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfNonOwningReferences.v, body: body) }
public func withUnsafePointerToVectorOfNonOwningReferences<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfNonOwningReferences.v, body: body) }
public var anyUniqueType: MyGame_Example_AnyUniqueAliases { let o = _accessor.offset(VTOFFSET.anyUniqueType.v); return o == 0 ? .none_ : MyGame_Example_AnyUniqueAliases(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func anyUnique<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.anyUnique.v); return o == 0 ? nil : _accessor.union(o) }
public var anyAmbiguousType: MyGame_Example_AnyAmbiguousAliases { let o = _accessor.offset(VTOFFSET.anyAmbiguousType.v); return o == 0 ? .none_ : MyGame_Example_AnyAmbiguousAliases(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func anyAmbiguous<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.anyAmbiguous.v); return o == 0 ? nil : _accessor.union(o) }
public var hasVectorOfEnums: Bool { let o = _accessor.offset(VTOFFSET.vectorOfEnums.v); return o == 0 ? false : true }
public var vectorOfEnumsCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfEnums.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfEnums(at index: Int32) -> MyGame_Example_Color? { let o = _accessor.offset(VTOFFSET.vectorOfEnums.v); 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 vectorOfEnums: FlatbufferVector<MyGame_Example_Color> { return _accessor.vector(at: VTOFFSET.vectorOfEnums.v, byteSize: 1) }
public var signedEnum: MyGame_Example_Race { let o = _accessor.offset(VTOFFSET.signedEnum.v); return o == 0 ? .none_ : MyGame_Example_Race(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .none_ }
@discardableResult public func mutate(signedEnum: MyGame_Example_Race) -> Bool {let o = _accessor.offset(VTOFFSET.signedEnum.v); return _accessor.mutate(signedEnum.rawValue, index: o) }
public var hasTestrequirednestedflatbuffer: Bool { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return o == 0 ? false : true }
public var testrequirednestedflatbufferCount: Int32 { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testrequirednestedflatbuffer(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var testrequirednestedflatbuffer: [UInt8] { return _accessor.getVector(at: VTOFFSET.testrequirednestedflatbuffer.v) ?? [] }
public var testrequirednestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testrequirednestedflatbuffer.v, byteSize: 1) }
public func mutate(testrequirednestedflatbuffer: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return _accessor.directMutate(testrequirednestedflatbuffer, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToTestrequirednestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testrequirednestedflatbuffer.v, body: body) }
public var hasScalarKeySortedTables: Bool { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? false : true }
public var scalarKeySortedTablesCount: Int32 { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func scalarKeySortedTables(at index: Int32) -> MyGame_Example_Stat? { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? nil : MyGame_Example_Stat(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public func withUnsafePointerToTestrequirednestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testrequirednestedflatbuffer.v, body: body) }
public var scalarKeySortedTables: FlatbufferVector<MyGame_Example_Stat> { return _accessor.vector(at: VTOFFSET.scalarKeySortedTables.v, byteSize: 4) }
public func scalarKeySortedTablesBy(key: UInt16) -> MyGame_Example_Stat? { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? nil : MyGame_Example_Stat.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb) }
public var nativeInline: MyGame_Example_Test? { let o = _accessor.offset(VTOFFSET.nativeInline.v); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Example_Test.self, at: o) }
public var mutableNativeInline: MyGame_Example_Test_Mutable? { let o = _accessor.offset(VTOFFSET.nativeInline.v); return o == 0 ? nil : MyGame_Example_Test_Mutable(_accessor.bb, o: o + _accessor.position) }
@@ -1604,9 +1554,8 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
let __inventory = builder.createVector(obj.inventory)
let __test = obj.test?.pack(builder: &builder) ?? Offset()
MyGame_Example_Monster.startVectorOfTest4(obj.test4.count, in: &builder)
for i in obj.test4 {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.test4 {
builder.create(struct: val)
}
let __test4 = builder.endVector(len: obj.test4.count)
let __testarrayofstring = builder.createVector(ofStrings: obj.testarrayofstring.compactMap({ $0 }) )
@@ -1621,16 +1570,14 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
let __testarrayofbools = builder.createVector(obj.testarrayofbools)
let __testarrayofstring2 = builder.createVector(ofStrings: obj.testarrayofstring2.compactMap({ $0 }) )
MyGame_Example_Monster.startVectorOfTestarrayofsortedstruct(obj.testarrayofsortedstruct.count, in: &builder)
for i in obj.testarrayofsortedstruct {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.testarrayofsortedstruct {
builder.create(struct: val)
}
let __testarrayofsortedstruct = builder.endVector(len: obj.testarrayofsortedstruct.count)
let __flex = builder.createVector(obj.flex)
MyGame_Example_Monster.startVectorOfTest5(obj.test5.count, in: &builder)
for i in obj.test5 {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.test5 {
builder.create(struct: val)
}
let __test5 = builder.endVector(len: obj.test5.count)
let __vectorOfLongs = builder.createVector(obj.vectorOfLongs)
@@ -1904,9 +1851,7 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(hp, forKey: .hp)
}
try container.encodeIfPresent(name, forKey: .name)
if inventoryCount > 0 {
try container.encodeIfPresent(inventory, forKey: .inventory)
}
try container.encodeIfPresent(inventory, forKey: .inventory)
if color != .blue {
try container.encodeIfPresent(color, forKey: .color)
}
@@ -1925,31 +1870,11 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .test)
default: break;
}
if test4Count > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .test4)
for index in 0..<test4Count {
guard let type = test4(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if testarrayofstringCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofstring)
for index in 0..<testarrayofstringCount {
guard let type = testarrayofstring(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if testarrayoftablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayoftables)
for index in 0..<testarrayoftablesCount {
guard let type = testarrayoftables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(test4, forKey: .test4)
try container.encodeIfPresent(testarrayofstring, forKey: .testarrayofstring)
try container.encodeIfPresent(testarrayoftables, forKey: .testarrayoftables)
try container.encodeIfPresent(enemy, forKey: .enemy)
if testnestedflatbufferCount > 0 {
try container.encodeIfPresent(testnestedflatbuffer, forKey: .testnestedflatbuffer)
}
try container.encodeIfPresent(testnestedflatbuffer, forKey: .testnestedflatbuffer)
try container.encodeIfPresent(testempty, forKey: .testempty)
if testbool != false {
try container.encodeIfPresent(testbool, forKey: .testbool)
@@ -1978,9 +1903,7 @@ extension MyGame_Example_Monster: Encodable {
if testhashu64Fnv1a != 0 {
try container.encodeIfPresent(testhashu64Fnv1a, forKey: .testhashu64Fnv1a)
}
if testarrayofboolsCount > 0 {
try container.encodeIfPresent(testarrayofbools, forKey: .testarrayofbools)
}
try container.encodeIfPresent(testarrayofbools, forKey: .testarrayofbools)
if testf != 3.14159 {
try container.encodeIfPresent(testf, forKey: .testf)
}
@@ -1990,69 +1913,27 @@ extension MyGame_Example_Monster: Encodable {
if testf3 != 0.0 {
try container.encodeIfPresent(testf3, forKey: .testf3)
}
if testarrayofstring2Count > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofstring2)
for index in 0..<testarrayofstring2Count {
guard let type = testarrayofstring2(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if testarrayofsortedstructCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofsortedstruct)
for index in 0..<testarrayofsortedstructCount {
guard let type = testarrayofsortedstruct(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if flexCount > 0 {
try container.encodeIfPresent(flex, forKey: .flex)
}
if test5Count > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .test5)
for index in 0..<test5Count {
guard let type = test5(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if vectorOfLongsCount > 0 {
try container.encodeIfPresent(vectorOfLongs, forKey: .vectorOfLongs)
}
if vectorOfDoublesCount > 0 {
try container.encodeIfPresent(vectorOfDoubles, forKey: .vectorOfDoubles)
}
try container.encodeIfPresent(testarrayofstring2, forKey: .testarrayofstring2)
try container.encodeIfPresent(testarrayofsortedstruct, forKey: .testarrayofsortedstruct)
try container.encodeIfPresent(flex, forKey: .flex)
try container.encodeIfPresent(test5, forKey: .test5)
try container.encodeIfPresent(vectorOfLongs, forKey: .vectorOfLongs)
try container.encodeIfPresent(vectorOfDoubles, forKey: .vectorOfDoubles)
try container.encodeIfPresent(parentNamespaceTest, forKey: .parentNamespaceTest)
if vectorOfReferrablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfReferrables)
for index in 0..<vectorOfReferrablesCount {
guard let type = vectorOfReferrables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(vectorOfReferrables, forKey: .vectorOfReferrables)
if singleWeakReference != 0 {
try container.encodeIfPresent(singleWeakReference, forKey: .singleWeakReference)
}
if vectorOfWeakReferencesCount > 0 {
try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences)
}
if vectorOfStrongReferrablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfStrongReferrables)
for index in 0..<vectorOfStrongReferrablesCount {
guard let type = vectorOfStrongReferrables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences)
try container.encodeIfPresent(vectorOfStrongReferrables, forKey: .vectorOfStrongReferrables)
if coOwningReference != 0 {
try container.encodeIfPresent(coOwningReference, forKey: .coOwningReference)
}
if vectorOfCoOwningReferencesCount > 0 {
try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
}
try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
if nonOwningReference != 0 {
try container.encodeIfPresent(nonOwningReference, forKey: .nonOwningReference)
}
if vectorOfNonOwningReferencesCount > 0 {
try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
}
try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
if anyUniqueType != .none_ {
try container.encodeIfPresent(anyUniqueType, forKey: .anyUniqueType)
}
@@ -2083,26 +1964,12 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .anyAmbiguous)
default: break;
}
if vectorOfEnumsCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfEnums)
for index in 0..<vectorOfEnumsCount {
guard let type = vectorOfEnums(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(vectorOfEnums, forKey: .vectorOfEnums)
if signedEnum != .none_ {
try container.encodeIfPresent(signedEnum, forKey: .signedEnum)
}
if testrequirednestedflatbufferCount > 0 {
try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer)
}
if scalarKeySortedTablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .scalarKeySortedTables)
for index in 0..<scalarKeySortedTablesCount {
guard let type = scalarKeySortedTables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer)
try container.encodeIfPresent(scalarKeySortedTables, forKey: .scalarKeySortedTables)
try container.encodeIfPresent(nativeInline, forKey: .nativeInline)
if longEnumNonEnumDefault != .longone {
try container.encodeIfPresent(longEnumNonEnumDefault, forKey: .longEnumNonEnumDefault)
@@ -2146,7 +2013,7 @@ public class MyGame_Example_MonsterT: NativeObject {
public var inventory: [UInt8]
public var color: MyGame_Example_Color
public var test: MyGame_Example_Any_Union?
public var test4: [MyGame_Example_Test?]
public var test4: [MyGame_Example_Test]
public var testarrayofstring: [String?]
public var testarrayoftables: [MyGame_Example_MonsterT?]
public var enemy: MyGame_Example_MonsterT?
@@ -2166,9 +2033,9 @@ public class MyGame_Example_MonsterT: NativeObject {
public var testf2: Float32
public var testf3: Float32
public var testarrayofstring2: [String?]
public var testarrayofsortedstruct: [MyGame_Example_Ability?]
public var testarrayofsortedstruct: [MyGame_Example_Ability]
public var flex: [UInt8]
public var test5: [MyGame_Example_Test?]
public var test5: [MyGame_Example_Test]
public var vectorOfLongs: [Int64]
public var vectorOfDoubles: [Double]
public var parentNamespaceTest: MyGame_InParentNamespaceT?
@@ -2204,9 +2071,7 @@ public class MyGame_Example_MonsterT: NativeObject {
hp = _t.hp
name = _t.name
inventory = []
for index in 0..<_t.inventoryCount {
inventory.append(_t.inventory(at: index))
}
inventory.append(contentsOf: _t.inventory)
color = _t.color
switch _t.testType {
case .monster:
@@ -2221,24 +2086,17 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break
}
test4 = []
for index in 0..<_t.test4Count {
test4.append(_t.test4(at: index))
}
test4.append(contentsOf: _t.test4)
testarrayofstring = []
for index in 0..<_t.testarrayofstringCount {
testarrayofstring.append(_t.testarrayofstring(at: index))
}
testarrayofstring.append(contentsOf: _t.testarrayofstring)
testarrayoftables = []
for index in 0..<_t.testarrayoftablesCount {
var __v_ = _t.testarrayoftables(at: index)
testarrayoftables.append(__v_?.unpack())
for var val in _t.testarrayoftables{
testarrayoftables.append(val.unpack())
}
var __enemy = _t.enemy
enemy = __enemy?.unpack()
testnestedflatbuffer = []
for index in 0..<_t.testnestedflatbufferCount {
testnestedflatbuffer.append(_t.testnestedflatbuffer(at: index))
}
testnestedflatbuffer.append(contentsOf: _t.testnestedflatbuffer)
var __testempty = _t.testempty
testempty = __testempty?.unpack()
testbool = _t.testbool
@@ -2251,63 +2109,41 @@ public class MyGame_Example_MonsterT: NativeObject {
testhashs64Fnv1a = _t.testhashs64Fnv1a
testhashu64Fnv1a = _t.testhashu64Fnv1a
testarrayofbools = []
for index in 0..<_t.testarrayofboolsCount {
testarrayofbools.append(_t.testarrayofbools(at: index))
}
testarrayofbools.append(contentsOf: _t.testarrayofbools)
testf = _t.testf
testf2 = _t.testf2
testf3 = _t.testf3
testarrayofstring2 = []
for index in 0..<_t.testarrayofstring2Count {
testarrayofstring2.append(_t.testarrayofstring2(at: index))
}
testarrayofstring2.append(contentsOf: _t.testarrayofstring2)
testarrayofsortedstruct = []
for index in 0..<_t.testarrayofsortedstructCount {
testarrayofsortedstruct.append(_t.testarrayofsortedstruct(at: index))
}
testarrayofsortedstruct.append(contentsOf: _t.testarrayofsortedstruct)
flex = []
for index in 0..<_t.flexCount {
flex.append(_t.flex(at: index))
}
flex.append(contentsOf: _t.flex)
test5 = []
for index in 0..<_t.test5Count {
test5.append(_t.test5(at: index))
}
test5.append(contentsOf: _t.test5)
vectorOfLongs = []
for index in 0..<_t.vectorOfLongsCount {
vectorOfLongs.append(_t.vectorOfLongs(at: index))
}
vectorOfLongs.append(contentsOf: _t.vectorOfLongs)
vectorOfDoubles = []
for index in 0..<_t.vectorOfDoublesCount {
vectorOfDoubles.append(_t.vectorOfDoubles(at: index))
}
vectorOfDoubles.append(contentsOf: _t.vectorOfDoubles)
var __parentNamespaceTest = _t.parentNamespaceTest
parentNamespaceTest = __parentNamespaceTest?.unpack()
vectorOfReferrables = []
for index in 0..<_t.vectorOfReferrablesCount {
var __v_ = _t.vectorOfReferrables(at: index)
vectorOfReferrables.append(__v_?.unpack())
for var val in _t.vectorOfReferrables{
vectorOfReferrables.append(val.unpack())
}
singleWeakReference = _t.singleWeakReference
vectorOfWeakReferences = []
for index in 0..<_t.vectorOfWeakReferencesCount {
vectorOfWeakReferences.append(_t.vectorOfWeakReferences(at: index))
}
vectorOfWeakReferences.append(contentsOf: _t.vectorOfWeakReferences)
vectorOfStrongReferrables = []
for index in 0..<_t.vectorOfStrongReferrablesCount {
var __v_ = _t.vectorOfStrongReferrables(at: index)
vectorOfStrongReferrables.append(__v_?.unpack())
for var val in _t.vectorOfStrongReferrables{
vectorOfStrongReferrables.append(val.unpack())
}
coOwningReference = _t.coOwningReference
vectorOfCoOwningReferences = []
for index in 0..<_t.vectorOfCoOwningReferencesCount {
vectorOfCoOwningReferences.append(_t.vectorOfCoOwningReferences(at: index))
}
vectorOfCoOwningReferences.append(contentsOf: _t.vectorOfCoOwningReferences)
nonOwningReference = _t.nonOwningReference
vectorOfNonOwningReferences = []
for index in 0..<_t.vectorOfNonOwningReferencesCount {
vectorOfNonOwningReferences.append(_t.vectorOfNonOwningReferences(at: index))
}
vectorOfNonOwningReferences.append(contentsOf: _t.vectorOfNonOwningReferences)
switch _t.anyUniqueType {
case .m:
var _v = _t.anyUnique(type: MyGame_Example_Monster.self)
@@ -2333,18 +2169,13 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break
}
vectorOfEnums = []
for index in 0..<_t.vectorOfEnumsCount {
vectorOfEnums.append(_t.vectorOfEnums(at: index)!)
}
vectorOfEnums.append(contentsOf: _t.vectorOfEnums)
signedEnum = _t.signedEnum
testrequirednestedflatbuffer = []
for index in 0..<_t.testrequirednestedflatbufferCount {
testrequirednestedflatbuffer.append(_t.testrequirednestedflatbuffer(at: index))
}
testrequirednestedflatbuffer.append(contentsOf: _t.testrequirednestedflatbuffer)
scalarKeySortedTables = []
for index in 0..<_t.scalarKeySortedTablesCount {
var __v_ = _t.scalarKeySortedTables(at: index)
scalarKeySortedTables.append(__v_?.unpack())
for var val in _t.scalarKeySortedTables{
scalarKeySortedTables.append(val.unpack())
}
nativeInline = _t.nativeInline
longEnumNonEnumDefault = _t.longEnumNonEnumDefault
@@ -2420,7 +2251,7 @@ public class MyGame_Example_MonsterT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Monster.self) }
}
public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_TypeAliases: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -2468,18 +2299,12 @@ public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAP
@discardableResult public func mutate(f32: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.f32.v); return _accessor.mutate(f32, index: o) }
public var f64: Double { let o = _accessor.offset(VTOFFSET.f64.v); return o == 0 ? 0.0 : _accessor.readBuffer(of: Double.self, at: o) }
@discardableResult public func mutate(f64: Double) -> Bool {let o = _accessor.offset(VTOFFSET.f64.v); return _accessor.mutate(f64, index: o) }
public var hasV8: Bool { let o = _accessor.offset(VTOFFSET.v8.v); return o == 0 ? false : true }
public var v8Count: Int32 { let o = _accessor.offset(VTOFFSET.v8.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func v8(at index: Int32) -> Int8 { let o = _accessor.offset(VTOFFSET.v8.v); return o == 0 ? 0 : _accessor.directRead(of: Int8.self, offset: _accessor.vector(at: o) + index * 1) }
public var v8: [Int8] { return _accessor.getVector(at: VTOFFSET.v8.v) ?? [] }
public var v8: FlatbufferVector<Int8> { return _accessor.vector(at: VTOFFSET.v8.v, byteSize: 1) }
public func mutate(v8: Int8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.v8.v); return _accessor.directMutate(v8, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToV8<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.v8.v, body: body) }
public var hasVf64: Bool { let o = _accessor.offset(VTOFFSET.vf64.v); return o == 0 ? false : true }
public var vf64Count: Int32 { let o = _accessor.offset(VTOFFSET.vf64.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vf64(at index: Int32) -> Double { let o = _accessor.offset(VTOFFSET.vf64.v); return o == 0 ? 0 : _accessor.directRead(of: Double.self, offset: _accessor.vector(at: o) + index * 8) }
public var vf64: [Double] { return _accessor.getVector(at: VTOFFSET.vf64.v) ?? [] }
public func withUnsafePointerToV8<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.v8.v, body: body) }
public var vf64: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vf64.v, byteSize: 8) }
public func mutate(vf64: Double, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vf64.v); return _accessor.directMutate(vf64, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVf64<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vf64.v, body: body) }
public func withUnsafePointerToVf64<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vf64.v, body: body) }
public static func startTypeAliases(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 12) }
public static func add(i8: Int8, _ fbb: inout FlatBufferBuilder) { fbb.add(element: i8, def: 0, at: VTOFFSET.i8.p) }
public static func add(u8: UInt8, _ fbb: inout FlatBufferBuilder) { fbb.add(element: u8, def: 0, at: VTOFFSET.u8.p) }
@@ -2619,12 +2444,8 @@ extension MyGame_Example_TypeAliases: Encodable {
if f64 != 0.0 {
try container.encodeIfPresent(f64, forKey: .f64)
}
if v8Count > 0 {
try container.encodeIfPresent(v8, forKey: .v8)
}
if vf64Count > 0 {
try container.encodeIfPresent(vf64, forKey: .vf64)
}
try container.encodeIfPresent(v8, forKey: .v8)
try container.encodeIfPresent(vf64, forKey: .vf64)
}
}
@@ -2655,13 +2476,9 @@ public class MyGame_Example_TypeAliasesT: NativeObject {
f32 = _t.f32
f64 = _t.f64
v8 = []
for index in 0..<_t.v8Count {
v8.append(_t.v8(at: index))
}
v8.append(contentsOf: _t.v8)
vf64 = []
for index in 0..<_t.vf64Count {
vf64.append(_t.vf64(at: index))
}
vf64.append(contentsOf: _t.vf64)
}
public init() {

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public enum ABC: Int32, Enum, Verifiable {
public enum ABC: Int32, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int32
public static var byteSize: Int { return MemoryLayout<Int32>.size }
public var value: Int32 { return self.rawValue }
@@ -31,7 +31,7 @@ extension ABC: Encodable {
}
}
public struct MoreDefaults: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MoreDefaults: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -51,28 +51,17 @@ public struct MoreDefaults: FlatBufferObject, Verifiable, ObjectAPIPacker {
var p: VOffset { self.rawValue }
}
public var hasInts: Bool { let o = _accessor.offset(VTOFFSET.ints.v); return o == 0 ? false : true }
public var intsCount: Int32 { let o = _accessor.offset(VTOFFSET.ints.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func ints(at index: Int32) -> Int32 { let o = _accessor.offset(VTOFFSET.ints.v); return o == 0 ? 0 : _accessor.directRead(of: Int32.self, offset: _accessor.vector(at: o) + index * 4) }
public var ints: [Int32] { return _accessor.getVector(at: VTOFFSET.ints.v) ?? [] }
public func withUnsafePointerToInts<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.ints.v, body: body) }
public var hasFloats: Bool { let o = _accessor.offset(VTOFFSET.floats.v); return o == 0 ? false : true }
public var floatsCount: Int32 { let o = _accessor.offset(VTOFFSET.floats.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func floats(at index: Int32) -> Float32 { let o = _accessor.offset(VTOFFSET.floats.v); return o == 0 ? 0 : _accessor.directRead(of: Float32.self, offset: _accessor.vector(at: o) + index * 4) }
public var floats: [Float32] { return _accessor.getVector(at: VTOFFSET.floats.v) ?? [] }
public func withUnsafePointerToFloats<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.floats.v, body: body) }
public var ints: FlatbufferVector<Int32> { return _accessor.vector(at: VTOFFSET.ints.v, byteSize: 4) }
public func withUnsafePointerToInts<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.ints.v, body: body) }
public var floats: FlatbufferVector<Float32> { return _accessor.vector(at: VTOFFSET.floats.v, byteSize: 4) }
public func withUnsafePointerToFloats<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.floats.v, body: body) }
public var emptyString: String? { let o = _accessor.offset(VTOFFSET.emptyString.v); return o == 0 ? "" : _accessor.string(at: o) }
public var emptyStringSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.emptyString.v) }
public var someString: String? { let o = _accessor.offset(VTOFFSET.someString.v); return o == 0 ? "some" : _accessor.string(at: o) }
public var someStringSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.someString.v) }
public var hasAbcs: Bool { let o = _accessor.offset(VTOFFSET.abcs.v); return o == 0 ? false : true }
public var abcsCount: Int32 { let o = _accessor.offset(VTOFFSET.abcs.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func abcs(at index: Int32) -> ABC? { let o = _accessor.offset(VTOFFSET.abcs.v); return o == 0 ? ABC.a : ABC(rawValue: _accessor.directRead(of: Int32.self, offset: _accessor.vector(at: o) + index * 4)) }
public var hasBools: Bool { let o = _accessor.offset(VTOFFSET.bools.v); return o == 0 ? false : true }
public var boolsCount: Int32 { let o = _accessor.offset(VTOFFSET.bools.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func bools(at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.bools.v); return o == 0 ? true : _accessor.directRead(of: Bool.self, offset: _accessor.vector(at: o) + index * 1) }
public var bools: [Bool] { return _accessor.getVector(at: VTOFFSET.bools.v) ?? [] }
public func withUnsafePointerToBools<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.bools.v, body: body) }
public var abcs: FlatbufferVector<ABC> { return _accessor.vector(at: VTOFFSET.abcs.v, byteSize: 4) }
public var bools: FlatbufferVector<Bool> { return _accessor.vector(at: VTOFFSET.bools.v, byteSize: 1) }
public func withUnsafePointerToBools<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.bools.v, body: body) }
public static func startMoreDefaults(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 6) }
public static func addVectorOf(ints: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: ints, at: VTOFFSET.ints.p) }
public static func addVectorOf(floats: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: floats, at: VTOFFSET.floats.p) }
@@ -162,24 +151,12 @@ extension MoreDefaults: Encodable {
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if intsCount > 0 {
try container.encodeIfPresent(ints, forKey: .ints)
}
if floatsCount > 0 {
try container.encodeIfPresent(floats, forKey: .floats)
}
try container.encodeIfPresent(ints, forKey: .ints)
try container.encodeIfPresent(floats, forKey: .floats)
try container.encodeIfPresent(emptyString, forKey: .emptyString)
try container.encodeIfPresent(someString, forKey: .someString)
if abcsCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .abcs)
for index in 0..<abcsCount {
guard let type = abcs(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if boolsCount > 0 {
try container.encodeIfPresent(bools, forKey: .bools)
}
try container.encodeIfPresent(abcs, forKey: .abcs)
try container.encodeIfPresent(bools, forKey: .bools)
}
}
@@ -194,23 +171,15 @@ public class MoreDefaultsT: NativeObject {
public init(_ _t: inout MoreDefaults) {
ints = []
for index in 0..<_t.intsCount {
ints.append(_t.ints(at: index))
}
ints.append(contentsOf: _t.ints)
floats = []
for index in 0..<_t.floatsCount {
floats.append(_t.floats(at: index))
}
floats.append(contentsOf: _t.floats)
emptyString = _t.emptyString
someString = _t.someString
abcs = []
for index in 0..<_t.abcsCount {
abcs.append(_t.abcs(at: index)!)
}
abcs.append(contentsOf: _t.abcs)
bools = []
for index in 0..<_t.boolsCount {
bools.append(_t.bools(at: index))
}
bools.append(contentsOf: _t.bools)
}
public init() {

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public struct Swift_Tests_NanInfTable: FlatBufferObject, Verifiable {
public struct Swift_Tests_NanInfTable: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public enum optional_scalars_OptionalByte: Int8, Enum, Verifiable {
public enum optional_scalars_OptionalByte: Int8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue }
@@ -31,7 +31,7 @@ extension optional_scalars_OptionalByte: Encodable {
}
}
public struct optional_scalars_ScalarStuff: FlatBufferObject, Verifiable {
public struct optional_scalars_ScalarStuff: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public enum Character: UInt8, UnionEnum {
public enum Character: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -75,7 +75,7 @@ public struct CharacterUnion {
}
}
}
public enum Gadget: UInt8, UnionEnum {
public enum Gadget: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -122,7 +122,7 @@ public struct GadgetUnion {
}
}
}
public struct Rapunzel: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct Rapunzel: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -165,7 +165,7 @@ extension Rapunzel: Encodable {
}
}
public struct Rapunzel_Mutable: FlatBufferObject {
public struct Rapunzel_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -190,7 +190,7 @@ public struct Rapunzel_Mutable: FlatBufferObject {
}
}
public struct BookReader: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct BookReader: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -233,7 +233,7 @@ extension BookReader: Encodable {
}
}
public struct BookReader_Mutable: FlatBufferObject {
public struct BookReader_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -258,7 +258,7 @@ public struct BookReader_Mutable: FlatBufferObject {
}
}
public struct FallingTub: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct FallingTub: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -301,7 +301,7 @@ extension FallingTub: Encodable {
}
}
public struct FallingTub_Mutable: FlatBufferObject {
public struct FallingTub_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -326,7 +326,7 @@ public struct FallingTub_Mutable: FlatBufferObject {
}
}
public struct Attacker: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct Attacker: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -407,7 +407,7 @@ public class AttackerT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: Attacker.self) }
}
public struct HandFan: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct HandFan: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -488,7 +488,7 @@ public class HandFanT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: HandFan.self) }
}
public struct Movie: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct Movie: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -510,11 +510,8 @@ public struct Movie: FlatBufferObject, Verifiable, ObjectAPIPacker {
public var mainCharacterType: Character { let o = _accessor.offset(VTOFFSET.mainCharacterType.v); return o == 0 ? .none_ : Character(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func mainCharacter<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.mainCharacter.v); return o == 0 ? nil : _accessor.union(o) }
public var hasCharactersType: Bool { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? false : true }
public var charactersTypeCount: Int32 { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func charactersType(at index: Int32) -> Character? { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? Character.none_ : Character(rawValue: _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1)) }
public var hasCharacters: Bool { let o = _accessor.offset(VTOFFSET.characters.v); return o == 0 ? false : true }
public var charactersCount: Int32 { let o = _accessor.offset(VTOFFSET.characters.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public var charactersType: FlatbufferVector<Character> { return _accessor.vector(at: VTOFFSET.charactersType.v, byteSize: 1) }
public var characters: UnionFlatbufferVector { return _accessor.unionVector(at: VTOFFSET.characters.v, byteSize: 4) }
public func characters<T: FlatbuffersInitializable>(at index: Int32, type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.characters.v); return o == 0 ? nil : _accessor.directUnion(_accessor.vector(at: o) + index * 4) }
public static func startMovie(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 4) }
public static func add(mainCharacterType: Character, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mainCharacterType.rawValue, def: 0, at: VTOFFSET.mainCharacterType.p) }
@@ -642,33 +639,30 @@ extension Movie: Encodable {
try container.encodeIfPresent(_v, forKey: .mainCharacter)
default: break;
}
if charactersCount > 0 {
var enumsEncoder = container.nestedUnkeyedContainer(forKey: .charactersType)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .characters)
for index in 0..<charactersCount {
guard let type = charactersType(at: index) else { continue }
try enumsEncoder.encode(type)
switch type {
case .mulan:
let _v = characters(at: index, type: Attacker.self)
try contentEncoder.encode(_v)
case .rapunzel:
let _v = characters(at: index, type: Rapunzel.self)
try contentEncoder.encode(_v)
case .belle:
let _v = characters(at: index, type: BookReader.self)
try contentEncoder.encode(_v)
case .bookfan:
let _v = characters(at: index, type: BookReader.self)
try contentEncoder.encode(_v)
case .other:
let _v = characters(at: index, type: String.self)
try contentEncoder.encode(_v)
case .unused:
let _v = characters(at: index, type: String.self)
try contentEncoder.encode(_v)
default: break;
}
try container.encode(charactersType, forKey: .charactersType)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .characters)
let _characters = charactersType
for index in _characters.startIndex..<_characters.endIndex {
switch _characters[index] {
case .mulan:
let _v = characters(at: Int32(index), type: Attacker.self)
try contentEncoder.encode(_v)
case .rapunzel:
let _v = characters(at: Int32(index), type: Rapunzel.self)
try contentEncoder.encode(_v)
case .belle:
let _v = characters(at: Int32(index), type: BookReader.self)
try contentEncoder.encode(_v)
case .bookfan:
let _v = characters(at: Int32(index), type: BookReader.self)
try contentEncoder.encode(_v)
case .other:
let _v = characters(at: Int32(index), type: String.self)
try contentEncoder.encode(_v)
case .unused:
let _v = characters(at: Int32(index), type: String.self)
try contentEncoder.encode(_v)
default: break;
}
}
}
@@ -702,25 +696,26 @@ public class MovieT: NativeObject {
default: break
}
characters = []
for index in 0..<_t.charactersCount {
switch _t.charactersType(at: index) {
let _charactersType = _t.charactersType
for index in _charactersType.startIndex..<_charactersType.endIndex {
switch _t.charactersType[index] {
case .mulan:
var _v = _t.characters(at: index, type: Attacker.self)
var _v = _t.characters(at: Int32(index), type: Attacker.self)
characters.append(CharacterUnion(_v?.unpack(), type: .mulan))
case .rapunzel:
var _v = _t.characters(at: index, type: Rapunzel_Mutable.self)
var _v = _t.characters(at: Int32(index), type: Rapunzel_Mutable.self)
characters.append(CharacterUnion(_v?.unpack(), type: .rapunzel))
case .belle:
var _v = _t.characters(at: index, type: BookReader_Mutable.self)
var _v = _t.characters(at: Int32(index), type: BookReader_Mutable.self)
characters.append(CharacterUnion(_v?.unpack(), type: .belle))
case .bookfan:
var _v = _t.characters(at: index, type: BookReader_Mutable.self)
var _v = _t.characters(at: Int32(index), type: BookReader_Mutable.self)
characters.append(CharacterUnion(_v?.unpack(), type: .bookfan))
case .other:
var _v = _t.characters(at: index, type: String.self)
var _v = _t.characters(at: Int32(index), type: String.self)
characters.append(CharacterUnion(_v?.unpack(), type: .other))
case .unused:
var _v = _t.characters(at: index, type: String.self)
var _v = _t.characters(at: Int32(index), type: String.self)
characters.append(CharacterUnion(_v?.unpack(), type: .unused))
default: break
}

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public struct Swift_Tests_Vectors: FlatBufferObject, Verifiable {
public struct Swift_Tests_Vectors: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -25,21 +25,12 @@ public struct Swift_Tests_Vectors: FlatBufferObject, Verifiable {
var p: VOffset { self.rawValue }
}
public var hasNone: Bool { let o = _accessor.offset(VTOFFSET.none_.v); return o == 0 ? false : true }
public var none_Count: Int32 { let o = _accessor.offset(VTOFFSET.none_.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func none_(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.none_.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var none_: [UInt64] { return _accessor.getVector(at: VTOFFSET.none_.v) ?? [] }
public func withUnsafePointerToNone<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.none_.v, body: body) }
public var hasEmpty: Bool { let o = _accessor.offset(VTOFFSET.empty.v); return o == 0 ? false : true }
public var emptyCount: Int32 { let o = _accessor.offset(VTOFFSET.empty.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func empty(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.empty.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var empty: [UInt64] { return _accessor.getVector(at: VTOFFSET.empty.v) ?? [] }
public func withUnsafePointerToEmpty<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.empty.v, body: body) }
public var hasArray: Bool { let o = _accessor.offset(VTOFFSET.array.v); return o == 0 ? false : true }
public var arrayCount: Int32 { let o = _accessor.offset(VTOFFSET.array.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func array(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.array.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var array: [UInt64] { return _accessor.getVector(at: VTOFFSET.array.v) ?? [] }
public func withUnsafePointerToArray<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.array.v, body: body) }
public var none_: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.none_.v, byteSize: 8) }
public func withUnsafePointerToNone<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.none_.v, body: body) }
public var empty: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.empty.v, byteSize: 8) }
public func withUnsafePointerToEmpty<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.empty.v, body: body) }
public var array: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.array.v, byteSize: 8) }
public func withUnsafePointerToArray<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.array.v, body: body) }
public static func startVectors(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 3) }
public static func addVectorOf(none_: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: none_, at: VTOFFSET.none_.p) }
public static func addVectorOf(empty: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: empty, at: VTOFFSET.empty.p) }
@@ -76,15 +67,9 @@ extension Swift_Tests_Vectors: Encodable {
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if none_Count > 0 {
try container.encodeIfPresent(none_, forKey: .none_)
}
if emptyCount > 0 {
try container.encodeIfPresent(empty, forKey: .empty)
}
if arrayCount > 0 {
try container.encodeIfPresent(array, forKey: .array)
}
try container.encodeIfPresent(none_, forKey: .none_)
try container.encodeIfPresent(empty, forKey: .empty)
try container.encodeIfPresent(array, forKey: .array)
}
}

View File

@@ -125,15 +125,15 @@ final class FlexBuffersReaderTests: XCTestCase {
private var path: String {
#if os(macOS)
// Gets the current path of this test file then
// strips out the nested directories.
let filePath = URL(filePath: #file)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
return filePath.absoluteString
// Gets the current path of this test file then
// strips out the nested directories.
let filePath = URL(filePath: #file)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
return filePath.absoluteString
#else
return FileManager.default.currentDirectoryPath
return FileManager.default.currentDirectoryPath
#endif
}

View File

@@ -20,7 +20,7 @@ import PackageDescription
let package = Package(
name: "FlatBuffers.Test.Swift.Wasm",
platforms: [
.macOS(.v10_14)
.macOS(.v10_14),
],
dependencies: [
.package(path: "../../.."),
@@ -31,6 +31,6 @@ let package = Package(
.testTarget(
name: "FlatBuffers.Test.Swift.WasmTests",
dependencies: [
.product(name: "FlatBuffers", package: "flatbuffers")
.product(name: "FlatBuffers", package: "flatbuffers"),
]),
])

View File

@@ -68,6 +68,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
])
// swiftformat:enable all
var buffer = bytes.buffer
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
readMonster(monster: monster)
mutateMonster(fb: bytes.buffer)
@@ -130,7 +131,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let root = Monster.endMonster(&fbb, start: mStart)
fbb.finish(offset: root)
var buffer = fbb.sizedBuffer
let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
let newMonster: Monster = getRoot(byteBuffer: &buffer)
XCTAssertNil(newMonster.pos)
XCTAssertEqual(newMonster.name, "Frodo")
}
@@ -153,30 +154,61 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
fbb.finish(offset: root)
var buffer = fbb.sizedBuffer
let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
let newMonster: Monster = getRoot(byteBuffer: &buffer)
XCTAssertEqual(newMonster.pos!.x, 10)
XCTAssertEqual(newMonster.name, "Barney")
}
func testReadMonsterFromUnsafePointerWithoutCopying() {
// swiftformat:disable all
var array: [UInt8] = [
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,
]
// swiftformat:enable all
let unpacked =
array
.withUnsafeMutableBytes { memory -> MyGame_Example_MonsterT in
var bytes = ByteBuffer(
assumingMemoryBound: memory.baseAddress!,
capacity: memory.count)
var monster: Monster = getRoot(byteBuffer: &bytes)
readFlatbufferMonster(monster: &monster)
let unpacked = monster.unpack()
return unpacked
}
readObjectApi(monster: unpacked)
}
func testArrayOfBools() {
let boolArray = [false, true, false, true, false, true, false]
var fbb = FlatBufferBuilder(initialSize: 1)
let name = fbb.create(string: "Frodo")
let bools = fbb.createVector(boolArray)
let root = Monster.createMonster(
&fbb,
nameOffset: name,
testarrayofboolsVectorOffset: bools)
fbb.finish(offset: root)
var buffer = fbb.sizedBuffer
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
let monster: Monster = getRoot(byteBuffer: &buffer)
let values = monster.testarrayofbools
XCTAssertEqual(boolArray, values)
XCTAssertEqual(boolArray.count, values.count)
for i in 0..<monster.testarrayofboolsCount {
XCTAssertEqual(boolArray[Int(i)], monster.testarrayofbools(at: i))
for (index, bool) in monster.testarrayofbools.enumerated() {
XCTAssertEqual(bool, boolArray[index])
}
}
@@ -188,6 +220,87 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
byteBuffer: &byteBuffer) as MyGame_Example_Monster))
}
func testUnalignedRead() {
// Aligned read
let fbb = createMonster(withPrefix: false)
let testAligned: () -> Bool = {
var buffer = fbb.sizedBuffer
var monster: Monster = getRoot(byteBuffer: &buffer)
self.readFlatbufferMonster(monster: &monster)
return true
}
XCTAssertEqual(testAligned(), true)
let testUnaligned: () -> Bool = {
var bytes: [UInt8] = [0x00]
bytes.append(contentsOf: fbb.sizedByteArray)
return bytes.withUnsafeMutableBytes { ptr in
guard var baseAddress = ptr.baseAddress else {
XCTFail("Base pointer is not defined")
return false
}
baseAddress = baseAddress.advanced(by: 1)
let unlignedPtr = UnsafeMutableRawPointer(baseAddress)
var bytes = ByteBuffer(
assumingMemoryBound: unlignedPtr,
capacity: ptr.count - 1)
var monster: Monster = getRoot(byteBuffer: &bytes)
self.readFlatbufferMonster(monster: &monster)
return true
}
}
XCTAssertEqual(testUnaligned(), true)
}
func testReadingRemovedSizeUnalignedBuffer() {
// Aligned read
let fbb = createMonster(withPrefix: true)
let testUnaligned: () -> Bool = {
var bytes: [UInt8] = [0x00]
bytes.append(contentsOf: fbb.sizedByteArray)
return bytes.withUnsafeMutableBytes { ptr in
guard var baseAddress = ptr.baseAddress else {
XCTFail("Base pointer is not defined")
return false
}
baseAddress = baseAddress.advanced(by: 1)
let unlignedPtr = UnsafeMutableRawPointer(baseAddress)
let bytes = ByteBuffer(
assumingMemoryBound: unlignedPtr,
capacity: ptr.count - 1)
var newBuf = FlatBuffersUtils.removeSizePrefix(bb: bytes)
var monster: Monster = getRoot(byteBuffer: &newBuf)
self.readFlatbufferMonster(monster: &monster)
return true
}
}
XCTAssertEqual(testUnaligned(), true)
}
func testForceRetainedObject() {
let byteBuffer = {
// swiftformat:disable all
var data: [UInt8]? = [
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,
]
// swiftformat:enable all
let buffer = ByteBuffer(bytes: data!)
data = nil
return buffer
}()
readVerifiedMonster(fb: byteBuffer)
}
func readMonster(monster: Monster) {
var monster = monster
readFlatbufferMonster(monster: &monster)
@@ -195,12 +308,17 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
readObjectApi(monster: unpacked!)
guard var buffer = unpacked?.serialize()
else { fatalError("Couldnt generate bytebuffer") }
var newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
var newMonster: Monster = getRoot(byteBuffer: &buffer)
readFlatbufferMonster(monster: &newMonster)
}
func createMonster(withPrefix prefix: Bool) -> FlatBufferBuilder {
var fbb = FlatBufferBuilder(initialSize: 1)
write(fbb: &fbb, prefix: prefix)
return fbb
}
func write(fbb: inout FlatBufferBuilder, prefix: Bool = false) {
let names = [
fbb.create(string: "Frodo"),
fbb.create(string: "Barney"),
@@ -257,7 +375,6 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
Monster.addVectorOf(testarrayoftables: sortedArray, &fbb)
let end = Monster.endMonster(&fbb, start: mStart)
Monster.finish(&fbb, end: end, prefix: prefix)
return fbb
}
func mutateMonster(fb: ByteBuffer) {
@@ -265,9 +382,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let monster: Monster = getRoot(byteBuffer: &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")
XCTAssertEqual(monster.testarrayoftables[0].name, "Barney")
XCTAssertEqual(monster.testarrayoftables[1].name, "Frodo")
XCTAssertEqual(monster.testarrayoftables[2].name, "Wilma")
// Example of searching for a table by the key
XCTAssertNotNil(monster.testarrayoftablesBy(key: "Frodo"))
@@ -276,18 +393,14 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertEqual(monster.testType, .monster)
XCTAssertTrue(monster.mutate(testbool: false))
XCTAssertEqual(monster.testbool, false)
XCTAssertTrue(monster.mutate(testbool: true))
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))
for i in 0..<monster.inventory.count {
XCTAssertEqual(monster.inventory[i], Byte(i + 1))
}
XCTAssertEqual(monster.mutate(inventory: 0, at: 0), true)
@@ -305,6 +418,13 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertTrue(vec?.mutate(x: 1) ?? false)
XCTAssertEqual(vec?.x, 1)
XCTAssertTrue(vec?.mutate(test1: 3) ?? false)
let mutableTest4 = monster.mutableTest4
let orignalValues = mutableTest4[0].a
XCTAssertEqual(mutableTest4[0].mutate(a: 100), true)
XCTAssertNotEqual(monster.test4[0].a, orignalValues)
XCTAssertEqual(monster.test4[0].a, 100)
XCTAssertEqual(mutableTest4[0].mutate(a: orignalValues), true)
}
func readFlatbufferMonster(monster: inout MyGame_Example_Monster) {
@@ -327,47 +447,64 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertEqual(monster.mutate(mana: 10), false)
XCTAssertEqual(monster.mana, 150)
XCTAssertEqual(monster.inventoryCount, 5)
XCTAssertEqual(monster.inventory.count, 5)
var sum: Byte = 0
for i in 0...monster.inventoryCount {
sum += monster.inventory(at: i)
for inventory in monster.inventory {
sum += inventory
}
XCTAssertEqual(sum, 10)
XCTAssertEqual(monster.test4Count, 2)
let test0 = monster.test4(at: 0)
let test1 = monster.test4(at: 1)
monster.withUnsafePointerToInventory { ptr, count in
var sum: UInt8 = 0
for pointee in ptr.startIndex..<ptr.endIndex {
sum += ptr[pointee]
}
XCTAssertEqual(sum, 10)
}
XCTAssertEqual(monster.test4.count, 2)
let test4 = monster.test4
var sum0 = 0
var sum1 = 0
if let a = test0?.a, let b = test0?.b {
sum0 = Int(a) + Int(b)
for test0 in test4 {
sum0 += Int(test0.a) + Int(test0.b)
}
if let a = test1?.a, let b = test1?.b {
sum1 = Int(a) + Int(b)
}
XCTAssertEqual(sum0 + sum1, 100)
XCTAssertEqual(sum0, 100)
let mutableTest0 = monster.mutableTest4(at: 0)
let mutableTest1 = monster.mutableTest4(at: 1)
monster.withUnsafePointerToTest4 { ptr, count in
guard let ptr = ptr.baseAddress else { return }
let bindedMemory: UnsafeBufferPointer<MyGame_Example_Test> =
UnsafeBufferPointer(
start: ptr.bindMemory(
to: MyGame_Example_Test.self,
capacity: count),
count: count)
var pointerSum = 0
for pointee in bindedMemory.startIndex..<bindedMemory.endIndex {
pointerSum += Int(bindedMemory[pointee].a) +
Int(bindedMemory[pointee].b)
}
XCTAssertEqual(pointerSum, 100)
}
let mutableTest4 = monster.mutableTest4
var sum2 = 0
var sum3 = 0
if let a = mutableTest0?.a, let b = mutableTest0?.b {
sum2 = Int(a) + Int(b)
for test0 in mutableTest4 {
sum2 += Int(test0.a) + Int(test0.b)
}
if let a = mutableTest1?.a, let b = mutableTest1?.b {
sum3 = Int(a) + Int(b)
}
XCTAssertEqual(sum2 + sum3, 100)
XCTAssertEqual(sum2, 100)
XCTAssertEqual(monster.testarrayofstringCount, 2)
XCTAssertEqual(monster.testarrayofstring(at: 0), "test1")
XCTAssertEqual(monster.testarrayofstring(at: 1), "test2")
let stringArray = monster.testarrayofstring
XCTAssertEqual(stringArray.count, 2)
XCTAssertEqual(stringArray[0], "test1")
XCTAssertEqual(stringArray[1], "test2")
XCTAssertEqual(monster.testbool, true)
let array = monster.nameSegmentArray
XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster")
if 0 == monster.testarrayofboolsCount {
if 0 == monster.testarrayofbools.count {
XCTAssertEqual(monster.testarrayofbools.isEmpty, true)
} else {
XCTAssertEqual(monster.testarrayofbools.isEmpty, false)
@@ -402,20 +539,43 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
}
XCTAssertEqual(sum, 10)
XCTAssertEqual(monster.test4.count, 2)
let test0 = monster.test4[0]
let test1 = monster.test4[1]
var sum0 = 0
var sum1 = 0
if let a = test0?.a, let b = test0?.b {
sum0 = Int(a) + Int(b)
for test in monster.test4 {
sum0 += Int(test.a) + Int(test.b)
}
if let a = test1?.a, let b = test1?.b {
sum1 = Int(a) + Int(b)
}
XCTAssertEqual(sum0 + sum1, 100)
XCTAssertEqual(sum0, 100)
XCTAssertEqual(monster.testbool, true)
}
func testEncoding() {
let fbb = createMonster(withPrefix: false)
var sizedBuffer = fbb.sizedBuffer
do {
struct Test: Decodable {
struct Pos: Decodable {
let x, y, z: Int
}
let hp: Int
let inventory: [UInt8]
let name: String
let pos: Pos
}
let reader: Monster = try getCheckedRoot(byteBuffer: &sizedBuffer)
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
let data = try encoder.encode(reader)
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let value = try decoder.decode(Test.self, from: data)
XCTAssertEqual(value.name, "MyMonster")
XCTAssertEqual(value.pos.x, 1)
XCTAssertEqual(value.pos.y, 2)
XCTAssertEqual(value.pos.z, 3)
} catch {
XCTFail(error.localizedDescription)
}
}
var jsonData: String {
"""
{\"hp\":80,\"inventory\":[0,1,2,3,4],\"test\":{\"name\":\"Fred\"},\"testarrayofstring\":[\"test1\",\"test2\"],\"testarrayoftables\":[{\"name\":\"Barney\"},{\"name\":\"Frodo\"},{\"name\":\"Wilma\"}],\"test4\":[{\"a\":30,\"b\":40},{\"a\":10,\"b\":20}],\"testbool\":true,\"test_type\":\"Monster\",\"pos\":{\"y\":2,\"test3\":{\"a\":5,\"b\":6},\"z\":3,\"x\":1,\"test1\":3,\"test2\":\"Green\"},\"name\":\"MyMonster\"}

View File

@@ -9,7 +9,7 @@ import Common
import FlatBuffers
/// Composite components of Monster color.
public enum MyGame_Example_Color: UInt8, Enum, Verifiable {
public enum MyGame_Example_Color: UInt8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = UInt8
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
public var value: UInt8 { return self.rawValue }
@@ -35,7 +35,7 @@ extension MyGame_Example_Color: Encodable {
}
}
public enum MyGame_Example_Race: Int8, Enum, Verifiable {
public enum MyGame_Example_Race: Int8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue }
@@ -60,7 +60,7 @@ extension MyGame_Example_Race: Encodable {
}
}
public enum MyGame_Example_LongEnum: UInt64, Enum, Verifiable {
public enum MyGame_Example_LongEnum: UInt64, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = UInt64
public static var byteSize: Int { return MemoryLayout<UInt64>.size }
public var value: UInt64 { return self.rawValue }
@@ -83,7 +83,7 @@ extension MyGame_Example_LongEnum: Encodable {
}
}
public enum MyGame_Example_Any_: UInt8, UnionEnum {
public enum MyGame_Example_Any_: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -135,7 +135,7 @@ public struct MyGame_Example_Any_Union {
}
}
}
public enum MyGame_Example_AnyUniqueAliases: UInt8, UnionEnum {
public enum MyGame_Example_AnyUniqueAliases: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -187,7 +187,7 @@ public struct MyGame_Example_AnyUniqueAliasesUnion {
}
}
}
public enum MyGame_Example_AnyAmbiguousAliases: UInt8, UnionEnum {
public enum MyGame_Example_AnyAmbiguousAliases: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
public init?(value: T) {
@@ -239,7 +239,7 @@ public struct MyGame_Example_AnyAmbiguousAliasesUnion {
}
}
}
public struct MyGame_Example_Test: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_Test: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -293,7 +293,7 @@ extension MyGame_Example_Test: Encodable {
}
}
public struct MyGame_Example_Test_Mutable: FlatBufferObject {
public struct MyGame_Example_Test_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -320,7 +320,7 @@ public struct MyGame_Example_Test_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_Vec3: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -415,7 +415,7 @@ extension MyGame_Example_Vec3: Encodable {
}
}
public struct MyGame_Example_Vec3_Mutable: FlatBufferObject {
public struct MyGame_Example_Vec3_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -449,7 +449,7 @@ public struct MyGame_Example_Vec3_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_Ability: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_Ability: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -502,7 +502,7 @@ extension MyGame_Example_Ability: Encodable {
}
}
public struct MyGame_Example_Ability_Mutable: FlatBufferObject {
public struct MyGame_Example_Ability_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -529,7 +529,7 @@ public struct MyGame_Example_Ability_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_StructOfStructs: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_StructOfStructs: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -589,7 +589,7 @@ extension MyGame_Example_StructOfStructs: Encodable {
}
}
public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferObject {
public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -615,7 +615,7 @@ public struct MyGame_Example_StructOfStructs_Mutable: FlatBufferObject {
}
}
public struct MyGame_Example_StructOfStructsOfStructs: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct MyGame_Example_StructOfStructsOfStructs: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -657,7 +657,7 @@ extension MyGame_Example_StructOfStructsOfStructs: Encodable {
}
}
public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferObject {
public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -681,7 +681,7 @@ public struct MyGame_Example_StructOfStructsOfStructs_Mutable: FlatBufferObject
}
}
public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_InParentNamespace: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -733,7 +733,7 @@ public class MyGame_InParentNamespaceT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_InParentNamespace.self) }
}
public struct MyGame_Example2_Monster: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example2_Monster: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -785,7 +785,7 @@ public class MyGame_Example2_MonsterT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example2_Monster.self) }
}
internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferObject, Verifiable, ObjectAPIPacker {
internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
internal var __buffer: ByteBuffer! { return _accessor.bb }
@@ -866,7 +866,7 @@ internal class MyGame_Example_TestSimpleTableWithEnumT: NativeObject {
internal func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_TestSimpleTableWithEnum.self) }
}
public struct MyGame_Example_Stat: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_Stat: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1005,7 +1005,7 @@ public class MyGame_Example_StatT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Stat.self) }
}
public struct MyGame_Example_Referrable: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_Referrable: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1111,7 +1111,7 @@ public class MyGame_Example_ReferrableT: NativeObject {
}
/// an example documentation comment: "monster object"
public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_Monster: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1196,37 +1196,25 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
public var name: String! { let o = _accessor.offset(VTOFFSET.name.v); return _accessor.string(at: o) }
public var nameSegmentArray: [UInt8]! { return _accessor.getVector(at: VTOFFSET.name.v) }
public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
public var inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public var color: MyGame_Example_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Example_Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .blue }
@discardableResult public func mutate(color: MyGame_Example_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
public var testType: MyGame_Example_Any_ { let o = _accessor.offset(VTOFFSET.testType.v); return o == 0 ? .none_ : MyGame_Example_Any_(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func test<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.test.v); return o == 0 ? nil : _accessor.union(o) }
public var hasTest4: Bool { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? false : true }
public var test4Count: Int32 { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func test4(at index: Int32) -> MyGame_Example_Test? { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Example_Test.self, offset: _accessor.vector(at: o) + index * 4) }
public func mutableTest4(at index: Int32) -> MyGame_Example_Test_Mutable? { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? nil : MyGame_Example_Test_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 4) }
public func withUnsafePointerToTest4<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test4.v, body: body) }
public var hasTestarrayofstring: Bool { let o = _accessor.offset(VTOFFSET.testarrayofstring.v); return o == 0 ? false : true }
public var testarrayofstringCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofstring.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofstring(at index: Int32) -> String? { let o = _accessor.offset(VTOFFSET.testarrayofstring.v); return o == 0 ? nil : _accessor.directString(at: _accessor.vector(at: o) + index * 4) }
public var test4: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
public var mutableTest4: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
public func withUnsafePointerToTest4<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test4.v, body: body) }
public var testarrayofstring: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring.v, byteSize: 4) }
/// an example documentation comment: this will end up in the generated code
/// multiline too
public var hasTestarrayoftables: Bool { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? false : true }
public var testarrayoftablesCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayoftables(at index: Int32) -> MyGame_Example_Monster? { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? nil : MyGame_Example_Monster(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var testarrayoftables: FlatbufferVector<MyGame_Example_Monster> { return _accessor.vector(at: VTOFFSET.testarrayoftables.v, byteSize: 4) }
public func testarrayoftablesBy(key: String) -> MyGame_Example_Monster? { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); 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(VTOFFSET.enemy.v); return o == 0 ? nil : MyGame_Example_Monster(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
public var hasTestnestedflatbuffer: Bool { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return o == 0 ? false : true }
public var testnestedflatbufferCount: Int32 { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testnestedflatbuffer(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var testnestedflatbuffer: [UInt8] { return _accessor.getVector(at: VTOFFSET.testnestedflatbuffer.v) ?? [] }
public var testnestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testnestedflatbuffer.v, byteSize: 1) }
public func mutate(testnestedflatbuffer: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testnestedflatbuffer.v); return _accessor.directMutate(testnestedflatbuffer, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToTestnestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testnestedflatbuffer.v, body: body) }
public func withUnsafePointerToTestnestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testnestedflatbuffer.v, body: body) }
public var testempty: MyGame_Example_Stat? { let o = _accessor.offset(VTOFFSET.testempty.v); return o == 0 ? nil : MyGame_Example_Stat(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
public var testbool: Bool { let o = _accessor.offset(VTOFFSET.testbool.v); return o == 0 ? false : _accessor.readBuffer(of: Bool.self, at: o) }
@discardableResult public func mutate(testbool: Bool) -> Bool {let o = _accessor.offset(VTOFFSET.testbool.v); return _accessor.mutate(testbool, index: o) }
@@ -1246,100 +1234,62 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
@discardableResult public func mutate(testhashs64Fnv1a: Int64) -> Bool {let o = _accessor.offset(VTOFFSET.testhashs64Fnv1a.v); return _accessor.mutate(testhashs64Fnv1a, index: o) }
public var testhashu64Fnv1a: UInt64 { let o = _accessor.offset(VTOFFSET.testhashu64Fnv1a.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(testhashu64Fnv1a: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.testhashu64Fnv1a.v); return _accessor.mutate(testhashu64Fnv1a, index: o) }
public var hasTestarrayofbools: Bool { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return o == 0 ? false : true }
public var testarrayofboolsCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofbools(at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return o == 0 ? true : _accessor.directRead(of: Bool.self, offset: _accessor.vector(at: o) + index * 1) }
public var testarrayofbools: [Bool] { return _accessor.getVector(at: VTOFFSET.testarrayofbools.v) ?? [] }
public var testarrayofbools: FlatbufferVector<Bool> { return _accessor.vector(at: VTOFFSET.testarrayofbools.v, byteSize: 1) }
public func mutate(testarrayofbools: Bool, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testarrayofbools.v); return _accessor.directMutate(testarrayofbools, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToTestarrayofbools<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofbools.v, body: body) }
public func withUnsafePointerToTestarrayofbools<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofbools.v, body: body) }
public var testf: Float32 { let o = _accessor.offset(VTOFFSET.testf.v); return o == 0 ? 3.14159 : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(testf: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.testf.v); return _accessor.mutate(testf, index: o) }
public var testf2: Float32 { let o = _accessor.offset(VTOFFSET.testf2.v); return o == 0 ? 3.0 : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(testf2: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.testf2.v); return _accessor.mutate(testf2, index: o) }
public var testf3: Float32 { let o = _accessor.offset(VTOFFSET.testf3.v); return o == 0 ? 0.0 : _accessor.readBuffer(of: Float32.self, at: o) }
@discardableResult public func mutate(testf3: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.testf3.v); return _accessor.mutate(testf3, index: o) }
public var hasTestarrayofstring2: Bool { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? false : true }
public var testarrayofstring2Count: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofstring2(at index: Int32) -> String? { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? nil : _accessor.directString(at: _accessor.vector(at: o) + index * 4) }
public var hasTestarrayofsortedstruct: Bool { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? false : true }
public var testarrayofsortedstructCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testarrayofsortedstruct(at index: Int32) -> MyGame_Example_Ability? { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Example_Ability.self, offset: _accessor.vector(at: o) + index * 8) }
public func mutableTestarrayofsortedstruct(at index: Int32) -> MyGame_Example_Ability_Mutable? { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? nil : MyGame_Example_Ability_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToTestarrayofsortedstruct<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofsortedstruct.v, body: body) }
public var hasFlex: Bool { let o = _accessor.offset(VTOFFSET.flex.v); return o == 0 ? false : true }
public var flexCount: Int32 { let o = _accessor.offset(VTOFFSET.flex.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func flex(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.flex.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var flex: [UInt8] { return _accessor.getVector(at: VTOFFSET.flex.v) ?? [] }
public var testarrayofstring2: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring2.v, byteSize: 4) }
public var testarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
public var mutableTestarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability_Mutable> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
public func withUnsafePointerToTestarrayofsortedstruct<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofsortedstruct.v, body: body) }
public var flex: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.flex.v, byteSize: 1) }
public func mutate(flex: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.flex.v); return _accessor.directMutate(flex, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToFlex<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.flex.v, body: body) }
public var hasTest5: Bool { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? false : true }
public var test5Count: Int32 { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func test5(at index: Int32) -> MyGame_Example_Test? { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Example_Test.self, offset: _accessor.vector(at: o) + index * 4) }
public func mutableTest5(at index: Int32) -> MyGame_Example_Test_Mutable? { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? nil : MyGame_Example_Test_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 4) }
public func withUnsafePointerToTest5<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test5.v, body: body) }
public var hasVectorOfLongs: Bool { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return o == 0 ? false : true }
public var vectorOfLongsCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfLongs(at index: Int32) -> Int64 { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return o == 0 ? 0 : _accessor.directRead(of: Int64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfLongs: [Int64] { return _accessor.getVector(at: VTOFFSET.vectorOfLongs.v) ?? [] }
public func withUnsafePointerToFlex<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.flex.v, body: body) }
public var test5: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
public var mutableTest5: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
public func withUnsafePointerToTest5<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test5.v, body: body) }
public var vectorOfLongs: FlatbufferVector<Int64> { return _accessor.vector(at: VTOFFSET.vectorOfLongs.v, byteSize: 8) }
public func mutate(vectorOfLongs: Int64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfLongs.v); return _accessor.directMutate(vectorOfLongs, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfLongs<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfLongs.v, body: body) }
public var hasVectorOfDoubles: Bool { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return o == 0 ? false : true }
public var vectorOfDoublesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfDoubles(at index: Int32) -> Double { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return o == 0 ? 0 : _accessor.directRead(of: Double.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfDoubles: [Double] { return _accessor.getVector(at: VTOFFSET.vectorOfDoubles.v) ?? [] }
public func withUnsafePointerToVectorOfLongs<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfLongs.v, body: body) }
public var vectorOfDoubles: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vectorOfDoubles.v, byteSize: 8) }
public func mutate(vectorOfDoubles: Double, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfDoubles.v); return _accessor.directMutate(vectorOfDoubles, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfDoubles<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfDoubles.v, body: body) }
public func withUnsafePointerToVectorOfDoubles<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfDoubles.v, body: body) }
public var parentNamespaceTest: MyGame_InParentNamespace? { let o = _accessor.offset(VTOFFSET.parentNamespaceTest.v); return o == 0 ? nil : MyGame_InParentNamespace(_accessor.bb, o: _accessor.indirect(o + _accessor.position)) }
public var hasVectorOfReferrables: Bool { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); return o == 0 ? false : true }
public var vectorOfReferrablesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfReferrables(at index: Int32) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); return o == 0 ? nil : MyGame_Example_Referrable(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var vectorOfReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfReferrables.v, byteSize: 4) }
public func vectorOfReferrablesBy(key: UInt64) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfReferrables.v); 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(VTOFFSET.singleWeakReference.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(singleWeakReference: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.singleWeakReference.v); return _accessor.mutate(singleWeakReference, index: o) }
public var hasVectorOfWeakReferences: Bool { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return o == 0 ? false : true }
public var vectorOfWeakReferencesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfWeakReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfWeakReferences: [UInt64] { return _accessor.getVector(at: VTOFFSET.vectorOfWeakReferences.v) ?? [] }
public var vectorOfWeakReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfWeakReferences.v, byteSize: 8) }
public func mutate(vectorOfWeakReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfWeakReferences.v); return _accessor.directMutate(vectorOfWeakReferences, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfWeakReferences<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfWeakReferences.v, body: body) }
public var hasVectorOfStrongReferrables: Bool { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); return o == 0 ? false : true }
public var vectorOfStrongReferrablesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfStrongReferrables(at index: Int32) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); return o == 0 ? nil : MyGame_Example_Referrable(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public func withUnsafePointerToVectorOfWeakReferences<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfWeakReferences.v, body: body) }
public var vectorOfStrongReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfStrongReferrables.v, byteSize: 4) }
public func vectorOfStrongReferrablesBy(key: UInt64) -> MyGame_Example_Referrable? { let o = _accessor.offset(VTOFFSET.vectorOfStrongReferrables.v); 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(VTOFFSET.coOwningReference.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(coOwningReference: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.coOwningReference.v); return _accessor.mutate(coOwningReference, index: o) }
public var hasVectorOfCoOwningReferences: Bool { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return o == 0 ? false : true }
public var vectorOfCoOwningReferencesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfCoOwningReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfCoOwningReferences: [UInt64] { return _accessor.getVector(at: VTOFFSET.vectorOfCoOwningReferences.v) ?? [] }
public var vectorOfCoOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfCoOwningReferences.v, byteSize: 8) }
public func mutate(vectorOfCoOwningReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfCoOwningReferences.v); return _accessor.directMutate(vectorOfCoOwningReferences, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfCoOwningReferences<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfCoOwningReferences.v, body: body) }
public func withUnsafePointerToVectorOfCoOwningReferences<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfCoOwningReferences.v, body: body) }
public var nonOwningReference: UInt64 { let o = _accessor.offset(VTOFFSET.nonOwningReference.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) }
@discardableResult public func mutate(nonOwningReference: UInt64) -> Bool {let o = _accessor.offset(VTOFFSET.nonOwningReference.v); return _accessor.mutate(nonOwningReference, index: o) }
public var hasVectorOfNonOwningReferences: Bool { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return o == 0 ? false : true }
public var vectorOfNonOwningReferencesCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfNonOwningReferences(at index: Int32) -> UInt64 { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return o == 0 ? 0 : _accessor.directRead(of: UInt64.self, offset: _accessor.vector(at: o) + index * 8) }
public var vectorOfNonOwningReferences: [UInt64] { return _accessor.getVector(at: VTOFFSET.vectorOfNonOwningReferences.v) ?? [] }
public var vectorOfNonOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfNonOwningReferences.v, byteSize: 8) }
public func mutate(vectorOfNonOwningReferences: UInt64, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vectorOfNonOwningReferences.v); return _accessor.directMutate(vectorOfNonOwningReferences, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVectorOfNonOwningReferences<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfNonOwningReferences.v, body: body) }
public func withUnsafePointerToVectorOfNonOwningReferences<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vectorOfNonOwningReferences.v, body: body) }
public var anyUniqueType: MyGame_Example_AnyUniqueAliases { let o = _accessor.offset(VTOFFSET.anyUniqueType.v); return o == 0 ? .none_ : MyGame_Example_AnyUniqueAliases(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func anyUnique<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.anyUnique.v); return o == 0 ? nil : _accessor.union(o) }
public var anyAmbiguousType: MyGame_Example_AnyAmbiguousAliases { let o = _accessor.offset(VTOFFSET.anyAmbiguousType.v); return o == 0 ? .none_ : MyGame_Example_AnyAmbiguousAliases(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func anyAmbiguous<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.anyAmbiguous.v); return o == 0 ? nil : _accessor.union(o) }
public var hasVectorOfEnums: Bool { let o = _accessor.offset(VTOFFSET.vectorOfEnums.v); return o == 0 ? false : true }
public var vectorOfEnumsCount: Int32 { let o = _accessor.offset(VTOFFSET.vectorOfEnums.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vectorOfEnums(at index: Int32) -> MyGame_Example_Color? { let o = _accessor.offset(VTOFFSET.vectorOfEnums.v); 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 vectorOfEnums: FlatbufferVector<MyGame_Example_Color> { return _accessor.vector(at: VTOFFSET.vectorOfEnums.v, byteSize: 1) }
public var signedEnum: MyGame_Example_Race { let o = _accessor.offset(VTOFFSET.signedEnum.v); return o == 0 ? .none_ : MyGame_Example_Race(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .none_ }
@discardableResult public func mutate(signedEnum: MyGame_Example_Race) -> Bool {let o = _accessor.offset(VTOFFSET.signedEnum.v); return _accessor.mutate(signedEnum.rawValue, index: o) }
public var hasTestrequirednestedflatbuffer: Bool { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return o == 0 ? false : true }
public var testrequirednestedflatbufferCount: Int32 { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func testrequirednestedflatbuffer(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var testrequirednestedflatbuffer: [UInt8] { return _accessor.getVector(at: VTOFFSET.testrequirednestedflatbuffer.v) ?? [] }
public var testrequirednestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testrequirednestedflatbuffer.v, byteSize: 1) }
public func mutate(testrequirednestedflatbuffer: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.testrequirednestedflatbuffer.v); return _accessor.directMutate(testrequirednestedflatbuffer, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToTestrequirednestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testrequirednestedflatbuffer.v, body: body) }
public var hasScalarKeySortedTables: Bool { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? false : true }
public var scalarKeySortedTablesCount: Int32 { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func scalarKeySortedTables(at index: Int32) -> MyGame_Example_Stat? { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? nil : MyGame_Example_Stat(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public func withUnsafePointerToTestrequirednestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testrequirednestedflatbuffer.v, body: body) }
public var scalarKeySortedTables: FlatbufferVector<MyGame_Example_Stat> { return _accessor.vector(at: VTOFFSET.scalarKeySortedTables.v, byteSize: 4) }
public func scalarKeySortedTablesBy(key: UInt16) -> MyGame_Example_Stat? { let o = _accessor.offset(VTOFFSET.scalarKeySortedTables.v); return o == 0 ? nil : MyGame_Example_Stat.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb) }
public var nativeInline: MyGame_Example_Test? { let o = _accessor.offset(VTOFFSET.nativeInline.v); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Example_Test.self, at: o) }
public var mutableNativeInline: MyGame_Example_Test_Mutable? { let o = _accessor.offset(VTOFFSET.nativeInline.v); return o == 0 ? nil : MyGame_Example_Test_Mutable(_accessor.bb, o: o + _accessor.position) }
@@ -1604,9 +1554,8 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
let __inventory = builder.createVector(obj.inventory)
let __test = obj.test?.pack(builder: &builder) ?? Offset()
MyGame_Example_Monster.startVectorOfTest4(obj.test4.count, in: &builder)
for i in obj.test4 {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.test4 {
builder.create(struct: val)
}
let __test4 = builder.endVector(len: obj.test4.count)
let __testarrayofstring = builder.createVector(ofStrings: obj.testarrayofstring.compactMap({ $0 }) )
@@ -1621,16 +1570,14 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
let __testarrayofbools = builder.createVector(obj.testarrayofbools)
let __testarrayofstring2 = builder.createVector(ofStrings: obj.testarrayofstring2.compactMap({ $0 }) )
MyGame_Example_Monster.startVectorOfTestarrayofsortedstruct(obj.testarrayofsortedstruct.count, in: &builder)
for i in obj.testarrayofsortedstruct {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.testarrayofsortedstruct {
builder.create(struct: val)
}
let __testarrayofsortedstruct = builder.endVector(len: obj.testarrayofsortedstruct.count)
let __flex = builder.createVector(obj.flex)
MyGame_Example_Monster.startVectorOfTest5(obj.test5.count, in: &builder)
for i in obj.test5 {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.test5 {
builder.create(struct: val)
}
let __test5 = builder.endVector(len: obj.test5.count)
let __vectorOfLongs = builder.createVector(obj.vectorOfLongs)
@@ -1904,9 +1851,7 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(hp, forKey: .hp)
}
try container.encodeIfPresent(name, forKey: .name)
if inventoryCount > 0 {
try container.encodeIfPresent(inventory, forKey: .inventory)
}
try container.encodeIfPresent(inventory, forKey: .inventory)
if color != .blue {
try container.encodeIfPresent(color, forKey: .color)
}
@@ -1925,31 +1870,11 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .test)
default: break;
}
if test4Count > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .test4)
for index in 0..<test4Count {
guard let type = test4(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if testarrayofstringCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofstring)
for index in 0..<testarrayofstringCount {
guard let type = testarrayofstring(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if testarrayoftablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayoftables)
for index in 0..<testarrayoftablesCount {
guard let type = testarrayoftables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(test4, forKey: .test4)
try container.encodeIfPresent(testarrayofstring, forKey: .testarrayofstring)
try container.encodeIfPresent(testarrayoftables, forKey: .testarrayoftables)
try container.encodeIfPresent(enemy, forKey: .enemy)
if testnestedflatbufferCount > 0 {
try container.encodeIfPresent(testnestedflatbuffer, forKey: .testnestedflatbuffer)
}
try container.encodeIfPresent(testnestedflatbuffer, forKey: .testnestedflatbuffer)
try container.encodeIfPresent(testempty, forKey: .testempty)
if testbool != false {
try container.encodeIfPresent(testbool, forKey: .testbool)
@@ -1978,9 +1903,7 @@ extension MyGame_Example_Monster: Encodable {
if testhashu64Fnv1a != 0 {
try container.encodeIfPresent(testhashu64Fnv1a, forKey: .testhashu64Fnv1a)
}
if testarrayofboolsCount > 0 {
try container.encodeIfPresent(testarrayofbools, forKey: .testarrayofbools)
}
try container.encodeIfPresent(testarrayofbools, forKey: .testarrayofbools)
if testf != 3.14159 {
try container.encodeIfPresent(testf, forKey: .testf)
}
@@ -1990,69 +1913,27 @@ extension MyGame_Example_Monster: Encodable {
if testf3 != 0.0 {
try container.encodeIfPresent(testf3, forKey: .testf3)
}
if testarrayofstring2Count > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofstring2)
for index in 0..<testarrayofstring2Count {
guard let type = testarrayofstring2(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if testarrayofsortedstructCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofsortedstruct)
for index in 0..<testarrayofsortedstructCount {
guard let type = testarrayofsortedstruct(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if flexCount > 0 {
try container.encodeIfPresent(flex, forKey: .flex)
}
if test5Count > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .test5)
for index in 0..<test5Count {
guard let type = test5(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if vectorOfLongsCount > 0 {
try container.encodeIfPresent(vectorOfLongs, forKey: .vectorOfLongs)
}
if vectorOfDoublesCount > 0 {
try container.encodeIfPresent(vectorOfDoubles, forKey: .vectorOfDoubles)
}
try container.encodeIfPresent(testarrayofstring2, forKey: .testarrayofstring2)
try container.encodeIfPresent(testarrayofsortedstruct, forKey: .testarrayofsortedstruct)
try container.encodeIfPresent(flex, forKey: .flex)
try container.encodeIfPresent(test5, forKey: .test5)
try container.encodeIfPresent(vectorOfLongs, forKey: .vectorOfLongs)
try container.encodeIfPresent(vectorOfDoubles, forKey: .vectorOfDoubles)
try container.encodeIfPresent(parentNamespaceTest, forKey: .parentNamespaceTest)
if vectorOfReferrablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfReferrables)
for index in 0..<vectorOfReferrablesCount {
guard let type = vectorOfReferrables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(vectorOfReferrables, forKey: .vectorOfReferrables)
if singleWeakReference != 0 {
try container.encodeIfPresent(singleWeakReference, forKey: .singleWeakReference)
}
if vectorOfWeakReferencesCount > 0 {
try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences)
}
if vectorOfStrongReferrablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfStrongReferrables)
for index in 0..<vectorOfStrongReferrablesCount {
guard let type = vectorOfStrongReferrables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences)
try container.encodeIfPresent(vectorOfStrongReferrables, forKey: .vectorOfStrongReferrables)
if coOwningReference != 0 {
try container.encodeIfPresent(coOwningReference, forKey: .coOwningReference)
}
if vectorOfCoOwningReferencesCount > 0 {
try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
}
try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
if nonOwningReference != 0 {
try container.encodeIfPresent(nonOwningReference, forKey: .nonOwningReference)
}
if vectorOfNonOwningReferencesCount > 0 {
try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
}
try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
if anyUniqueType != .none_ {
try container.encodeIfPresent(anyUniqueType, forKey: .anyUniqueType)
}
@@ -2083,26 +1964,12 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .anyAmbiguous)
default: break;
}
if vectorOfEnumsCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfEnums)
for index in 0..<vectorOfEnumsCount {
guard let type = vectorOfEnums(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(vectorOfEnums, forKey: .vectorOfEnums)
if signedEnum != .none_ {
try container.encodeIfPresent(signedEnum, forKey: .signedEnum)
}
if testrequirednestedflatbufferCount > 0 {
try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer)
}
if scalarKeySortedTablesCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .scalarKeySortedTables)
for index in 0..<scalarKeySortedTablesCount {
guard let type = scalarKeySortedTables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer)
try container.encodeIfPresent(scalarKeySortedTables, forKey: .scalarKeySortedTables)
try container.encodeIfPresent(nativeInline, forKey: .nativeInline)
if longEnumNonEnumDefault != .longone {
try container.encodeIfPresent(longEnumNonEnumDefault, forKey: .longEnumNonEnumDefault)
@@ -2146,7 +2013,7 @@ public class MyGame_Example_MonsterT: NativeObject {
public var inventory: [UInt8]
public var color: MyGame_Example_Color
public var test: MyGame_Example_Any_Union?
public var test4: [MyGame_Example_Test?]
public var test4: [MyGame_Example_Test]
public var testarrayofstring: [String?]
public var testarrayoftables: [MyGame_Example_MonsterT?]
public var enemy: MyGame_Example_MonsterT?
@@ -2166,9 +2033,9 @@ public class MyGame_Example_MonsterT: NativeObject {
public var testf2: Float32
public var testf3: Float32
public var testarrayofstring2: [String?]
public var testarrayofsortedstruct: [MyGame_Example_Ability?]
public var testarrayofsortedstruct: [MyGame_Example_Ability]
public var flex: [UInt8]
public var test5: [MyGame_Example_Test?]
public var test5: [MyGame_Example_Test]
public var vectorOfLongs: [Int64]
public var vectorOfDoubles: [Double]
public var parentNamespaceTest: MyGame_InParentNamespaceT?
@@ -2204,9 +2071,7 @@ public class MyGame_Example_MonsterT: NativeObject {
hp = _t.hp
name = _t.name
inventory = []
for index in 0..<_t.inventoryCount {
inventory.append(_t.inventory(at: index))
}
inventory.append(contentsOf: _t.inventory)
color = _t.color
switch _t.testType {
case .monster:
@@ -2221,24 +2086,17 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break
}
test4 = []
for index in 0..<_t.test4Count {
test4.append(_t.test4(at: index))
}
test4.append(contentsOf: _t.test4)
testarrayofstring = []
for index in 0..<_t.testarrayofstringCount {
testarrayofstring.append(_t.testarrayofstring(at: index))
}
testarrayofstring.append(contentsOf: _t.testarrayofstring)
testarrayoftables = []
for index in 0..<_t.testarrayoftablesCount {
var __v_ = _t.testarrayoftables(at: index)
testarrayoftables.append(__v_?.unpack())
for var val in _t.testarrayoftables{
testarrayoftables.append(val.unpack())
}
var __enemy = _t.enemy
enemy = __enemy?.unpack()
testnestedflatbuffer = []
for index in 0..<_t.testnestedflatbufferCount {
testnestedflatbuffer.append(_t.testnestedflatbuffer(at: index))
}
testnestedflatbuffer.append(contentsOf: _t.testnestedflatbuffer)
var __testempty = _t.testempty
testempty = __testempty?.unpack()
testbool = _t.testbool
@@ -2251,63 +2109,41 @@ public class MyGame_Example_MonsterT: NativeObject {
testhashs64Fnv1a = _t.testhashs64Fnv1a
testhashu64Fnv1a = _t.testhashu64Fnv1a
testarrayofbools = []
for index in 0..<_t.testarrayofboolsCount {
testarrayofbools.append(_t.testarrayofbools(at: index))
}
testarrayofbools.append(contentsOf: _t.testarrayofbools)
testf = _t.testf
testf2 = _t.testf2
testf3 = _t.testf3
testarrayofstring2 = []
for index in 0..<_t.testarrayofstring2Count {
testarrayofstring2.append(_t.testarrayofstring2(at: index))
}
testarrayofstring2.append(contentsOf: _t.testarrayofstring2)
testarrayofsortedstruct = []
for index in 0..<_t.testarrayofsortedstructCount {
testarrayofsortedstruct.append(_t.testarrayofsortedstruct(at: index))
}
testarrayofsortedstruct.append(contentsOf: _t.testarrayofsortedstruct)
flex = []
for index in 0..<_t.flexCount {
flex.append(_t.flex(at: index))
}
flex.append(contentsOf: _t.flex)
test5 = []
for index in 0..<_t.test5Count {
test5.append(_t.test5(at: index))
}
test5.append(contentsOf: _t.test5)
vectorOfLongs = []
for index in 0..<_t.vectorOfLongsCount {
vectorOfLongs.append(_t.vectorOfLongs(at: index))
}
vectorOfLongs.append(contentsOf: _t.vectorOfLongs)
vectorOfDoubles = []
for index in 0..<_t.vectorOfDoublesCount {
vectorOfDoubles.append(_t.vectorOfDoubles(at: index))
}
vectorOfDoubles.append(contentsOf: _t.vectorOfDoubles)
var __parentNamespaceTest = _t.parentNamespaceTest
parentNamespaceTest = __parentNamespaceTest?.unpack()
vectorOfReferrables = []
for index in 0..<_t.vectorOfReferrablesCount {
var __v_ = _t.vectorOfReferrables(at: index)
vectorOfReferrables.append(__v_?.unpack())
for var val in _t.vectorOfReferrables{
vectorOfReferrables.append(val.unpack())
}
singleWeakReference = _t.singleWeakReference
vectorOfWeakReferences = []
for index in 0..<_t.vectorOfWeakReferencesCount {
vectorOfWeakReferences.append(_t.vectorOfWeakReferences(at: index))
}
vectorOfWeakReferences.append(contentsOf: _t.vectorOfWeakReferences)
vectorOfStrongReferrables = []
for index in 0..<_t.vectorOfStrongReferrablesCount {
var __v_ = _t.vectorOfStrongReferrables(at: index)
vectorOfStrongReferrables.append(__v_?.unpack())
for var val in _t.vectorOfStrongReferrables{
vectorOfStrongReferrables.append(val.unpack())
}
coOwningReference = _t.coOwningReference
vectorOfCoOwningReferences = []
for index in 0..<_t.vectorOfCoOwningReferencesCount {
vectorOfCoOwningReferences.append(_t.vectorOfCoOwningReferences(at: index))
}
vectorOfCoOwningReferences.append(contentsOf: _t.vectorOfCoOwningReferences)
nonOwningReference = _t.nonOwningReference
vectorOfNonOwningReferences = []
for index in 0..<_t.vectorOfNonOwningReferencesCount {
vectorOfNonOwningReferences.append(_t.vectorOfNonOwningReferences(at: index))
}
vectorOfNonOwningReferences.append(contentsOf: _t.vectorOfNonOwningReferences)
switch _t.anyUniqueType {
case .m:
var _v = _t.anyUnique(type: MyGame_Example_Monster.self)
@@ -2333,18 +2169,13 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break
}
vectorOfEnums = []
for index in 0..<_t.vectorOfEnumsCount {
vectorOfEnums.append(_t.vectorOfEnums(at: index)!)
}
vectorOfEnums.append(contentsOf: _t.vectorOfEnums)
signedEnum = _t.signedEnum
testrequirednestedflatbuffer = []
for index in 0..<_t.testrequirednestedflatbufferCount {
testrequirednestedflatbuffer.append(_t.testrequirednestedflatbuffer(at: index))
}
testrequirednestedflatbuffer.append(contentsOf: _t.testrequirednestedflatbuffer)
scalarKeySortedTables = []
for index in 0..<_t.scalarKeySortedTablesCount {
var __v_ = _t.scalarKeySortedTables(at: index)
scalarKeySortedTables.append(__v_?.unpack())
for var val in _t.scalarKeySortedTables{
scalarKeySortedTables.append(val.unpack())
}
nativeInline = _t.nativeInline
longEnumNonEnumDefault = _t.longEnumNonEnumDefault
@@ -2420,7 +2251,7 @@ public class MyGame_Example_MonsterT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Monster.self) }
}
public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct MyGame_Example_TypeAliases: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -2468,18 +2299,12 @@ public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAP
@discardableResult public func mutate(f32: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.f32.v); return _accessor.mutate(f32, index: o) }
public var f64: Double { let o = _accessor.offset(VTOFFSET.f64.v); return o == 0 ? 0.0 : _accessor.readBuffer(of: Double.self, at: o) }
@discardableResult public func mutate(f64: Double) -> Bool {let o = _accessor.offset(VTOFFSET.f64.v); return _accessor.mutate(f64, index: o) }
public var hasV8: Bool { let o = _accessor.offset(VTOFFSET.v8.v); return o == 0 ? false : true }
public var v8Count: Int32 { let o = _accessor.offset(VTOFFSET.v8.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func v8(at index: Int32) -> Int8 { let o = _accessor.offset(VTOFFSET.v8.v); return o == 0 ? 0 : _accessor.directRead(of: Int8.self, offset: _accessor.vector(at: o) + index * 1) }
public var v8: [Int8] { return _accessor.getVector(at: VTOFFSET.v8.v) ?? [] }
public var v8: FlatbufferVector<Int8> { return _accessor.vector(at: VTOFFSET.v8.v, byteSize: 1) }
public func mutate(v8: Int8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.v8.v); return _accessor.directMutate(v8, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToV8<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.v8.v, body: body) }
public var hasVf64: Bool { let o = _accessor.offset(VTOFFSET.vf64.v); return o == 0 ? false : true }
public var vf64Count: Int32 { let o = _accessor.offset(VTOFFSET.vf64.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func vf64(at index: Int32) -> Double { let o = _accessor.offset(VTOFFSET.vf64.v); return o == 0 ? 0 : _accessor.directRead(of: Double.self, offset: _accessor.vector(at: o) + index * 8) }
public var vf64: [Double] { return _accessor.getVector(at: VTOFFSET.vf64.v) ?? [] }
public func withUnsafePointerToV8<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.v8.v, body: body) }
public var vf64: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vf64.v, byteSize: 8) }
public func mutate(vf64: Double, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.vf64.v); return _accessor.directMutate(vf64, index: _accessor.vector(at: o) + index * 8) }
public func withUnsafePointerToVf64<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vf64.v, body: body) }
public func withUnsafePointerToVf64<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.vf64.v, body: body) }
public static func startTypeAliases(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 12) }
public static func add(i8: Int8, _ fbb: inout FlatBufferBuilder) { fbb.add(element: i8, def: 0, at: VTOFFSET.i8.p) }
public static func add(u8: UInt8, _ fbb: inout FlatBufferBuilder) { fbb.add(element: u8, def: 0, at: VTOFFSET.u8.p) }
@@ -2619,12 +2444,8 @@ extension MyGame_Example_TypeAliases: Encodable {
if f64 != 0.0 {
try container.encodeIfPresent(f64, forKey: .f64)
}
if v8Count > 0 {
try container.encodeIfPresent(v8, forKey: .v8)
}
if vf64Count > 0 {
try container.encodeIfPresent(vf64, forKey: .vf64)
}
try container.encodeIfPresent(v8, forKey: .v8)
try container.encodeIfPresent(vf64, forKey: .vf64)
}
}
@@ -2655,13 +2476,9 @@ public class MyGame_Example_TypeAliasesT: NativeObject {
f32 = _t.f32
f64 = _t.f64
v8 = []
for index in 0..<_t.v8Count {
v8.append(_t.v8(at: index))
}
v8.append(contentsOf: _t.v8)
vf64 = []
for index in 0..<_t.vf64Count {
vf64.append(_t.vf64(at: index))
}
vf64.append(contentsOf: _t.vf64)
}
public init() {

View File

@@ -8,7 +8,7 @@
@_implementationOnly import FlatBuffers
internal struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker {
internal struct Message: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
internal var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -2,7 +2,7 @@
// swiftlint:disable all
// swiftformat:disable all
public struct BytesCount: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject {
public struct BytesCount: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -45,7 +45,7 @@ extension BytesCount: Encodable {
}
}
public struct BytesCount_Mutable: FlatBufferObject {
public struct BytesCount_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -70,7 +70,7 @@ public struct BytesCount_Mutable: FlatBufferObject {
}
}
public struct InternalMessage: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct InternalMessage: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -153,7 +153,7 @@ public class InternalMessageT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: InternalMessage.self) }
}
public struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker {
public struct Message: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -24,12 +24,12 @@ let package = Package(
.macOS(.v10_14),
],
dependencies: [
.package(path: "../../..")
.package(path: "../../.."),
],
targets: [
.executableTarget(
name: "fuzzer",
dependencies: [
.product(name: "FlatBuffers", package: "flatbuffers")
])
.product(name: "FlatBuffers", package: "flatbuffers"),
]),
])