[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

@@ -57,10 +57,10 @@ let package = Package(
extension Array where Element == Package.Dependency { extension Array where Element == Package.Dependency {
static var dependencies: [Package.Dependency] { static var dependencies: [Package.Dependency] {
#if os(Windows) #if os(Windows)
[] []
#else #else
// Test only Dependency // Test only Dependency
[.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1")] [.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1")]
#endif #endif
} }
} }
@@ -68,13 +68,13 @@ extension Array where Element == Package.Dependency {
extension Array where Element == PackageDescription.Target.Dependency { extension Array where Element == PackageDescription.Target.Dependency {
static var dependencies: [PackageDescription.Target.Dependency] { static var dependencies: [PackageDescription.Target.Dependency] {
#if os(Windows) #if os(Windows)
["FlatBuffers"] ["FlatBuffers"]
#else #else
// Test only Dependency // Test only Dependency
[ [
.product(name: "GRPC", package: "grpc-swift"), .product(name: "GRPC", package: "grpc-swift"),
"FlatBuffers", "FlatBuffers",
] ]
#endif #endif
} }
} }

View File

@@ -88,8 +88,8 @@ let benchmarks = {
Benchmark( Benchmark(
"Allocating ByteBuffer 1GB", "Allocating ByteBuffer 1GB",
configuration: singleConfiguration configuration: singleConfiguration)
) { benchmark in { benchmark in
let memory = UnsafeMutableRawPointer.allocate( let memory = UnsafeMutableRawPointer.allocate(
byteCount: 1_024_000_000, byteCount: 1_024_000_000,
alignment: 1) alignment: 1)
@@ -165,8 +165,8 @@ let benchmarks = {
Benchmark( Benchmark(
"FlatBufferBuilder Add", "FlatBufferBuilder Add",
configuration: kiloConfiguration configuration: kiloConfiguration)
) { benchmark in { benchmark in
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32) var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
benchmark.startMeasurement() benchmark.startMeasurement()
for _ in benchmark.scaledIterations { for _ in benchmark.scaledIterations {
@@ -182,8 +182,8 @@ let benchmarks = {
Benchmark( Benchmark(
"FlatBufferBuilder Start table", "FlatBufferBuilder Start table",
configuration: kiloConfiguration configuration: kiloConfiguration)
) { benchmark in { benchmark in
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32) var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
benchmark.startMeasurement() benchmark.startMeasurement()
for _ in benchmark.scaledIterations { for _ in benchmark.scaledIterations {

View File

@@ -20,7 +20,7 @@ import PackageDescription
let package = Package( let package = Package(
name: "benchmarks", name: "benchmarks",
platforms: [ platforms: [
.macOS(.v13) .macOS(.v13),
], ],
dependencies: [ dependencies: [
.package(path: "../.."), .package(path: "../.."),
@@ -37,6 +37,6 @@ let package = Package(
], ],
path: "Benchmarks/FlatbuffersBenchmarks", path: "Benchmarks/FlatbuffersBenchmarks",
plugins: [ plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark") .plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
]) ]),
]) ])

View File

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

View File

@@ -39,7 +39,7 @@ func greet(name: String, client greeter: models_GreeterServiceClient) {
// Make the RPC call to the server. // Make the RPC call to the server.
let sayHello = let sayHello =
greeter greeter
.SayHello(Message<models_HelloRequest>(builder: &builder)) .SayHello(Message<models_HelloRequest>(builder: &builder))
// wait() on the response to stop the program from exiting before the response is received. // wait() on the response to stop the program from exiting before the response is received.
do { do {

View File

@@ -32,8 +32,7 @@ class Greeter: models_GreeterProvider {
func SayHello( func SayHello(
request: Message<models_HelloRequest>, request: Message<models_HelloRequest>,
context: StatusOnlyCallContext context: StatusOnlyCallContext)
)
-> EventLoopFuture<Message<models_HelloReply>> -> EventLoopFuture<Message<models_HelloReply>>
{ {
let recipient = request.object.name ?? "Stranger" let recipient = request.object.name ?? "Stranger"
@@ -48,15 +47,14 @@ class Greeter: models_GreeterProvider {
func SayManyHellos( func SayManyHellos(
request: Message<models_HelloRequest>, request: Message<models_HelloRequest>,
context: StreamingResponseCallContext<Message<models_HelloReply>> context: StreamingResponseCallContext<Message<models_HelloReply>>)
)
-> EventLoopFuture<GRPCStatus> -> EventLoopFuture<GRPCStatus>
{ {
for name in greetings { for name in greetings {
var builder = FlatBufferBuilder() var builder = FlatBufferBuilder()
let off = let off =
builder builder
.create(string: "\(name) \(request.object.name ?? "Unknown")") .create(string: "\(name) \(request.object.name ?? "Unknown")")
let root = models_HelloReply.createHelloReply( let root = models_HelloReply.createHelloReply(
&builder, &builder,
messageOffset: off) messageOffset: off)

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers import FlatBuffers
public enum MyGame_Sample_Color: Int8, Enum, Verifiable { public enum MyGame_Sample_Color: Int8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int8 public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size } public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue } public var value: Int8 { return self.rawValue }
@@ -31,7 +31,7 @@ extension MyGame_Sample_Color: Encodable {
} }
} }
public enum MyGame_Sample_Equipment: UInt8, UnionEnum { public enum MyGame_Sample_Equipment: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8 public typealias T = UInt8
public init?(value: T) { public init?(value: T) {
@@ -73,7 +73,7 @@ public struct MyGame_Sample_EquipmentUnion {
} }
} }
} }
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject { public struct MyGame_Sample_Vec3: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
@@ -136,7 +136,7 @@ extension MyGame_Sample_Vec3: Encodable {
} }
} }
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject { public struct MyGame_Sample_Vec3_Mutable: FlatBufferStruct, FlatbuffersVectorInitializable {
static func validateVersion() { FlatBuffersVersion_25_9_23() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -165,7 +165,7 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
} }
} }
public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPacker { public struct MyGame_Sample_Monster: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -197,24 +197,17 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPack
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) } @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 o == 0 ? nil : _accessor.string(at: o) } public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) } public var 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 inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
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 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 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_Sample_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .blue } public var color: MyGame_Sample_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .blue }
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) } @discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true } public var weapons: FlatbufferVector<MyGame_Sample_Weapon> { return _accessor.vector(at: VTOFFSET.weapons.v, byteSize: 4) }
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ } public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) } public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
public var hasPath: Bool { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? false : true } public var path: FlatbufferVector<MyGame_Sample_Vec3> { return _accessor.vector(at: VTOFFSET.path.v, byteSize: 12) }
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var mutablePath: FlatbufferVector<MyGame_Sample_Vec3_Mutable> { return _accessor.vector(at: VTOFFSET.path.v, byteSize: 12) }
public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) } public func withUnsafePointerToPath<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.path.v, body: body) }
public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) }
public func withUnsafePointerToPath<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.path.v, body: body) }
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 11) } public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 11) }
public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) } public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) } public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) }
@@ -282,9 +275,8 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPack
let __weapons = builder.createVector(ofOffsets: __weapons__) let __weapons = builder.createVector(ofOffsets: __weapons__)
let __equipped = obj.equipped?.pack(builder: &builder) ?? Offset() let __equipped = obj.equipped?.pack(builder: &builder) ?? Offset()
MyGame_Sample_Monster.startVectorOfPath(obj.path.count, in: &builder) MyGame_Sample_Monster.startVectorOfPath(obj.path.count, in: &builder)
for i in obj.path { for val in obj.path {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __path = builder.endVector(len: obj.path.count) let __path = builder.endVector(len: obj.path.count)
let __root = MyGame_Sample_Monster.startMonster(&builder) let __root = MyGame_Sample_Monster.startMonster(&builder)
@@ -350,19 +342,11 @@ extension MyGame_Sample_Monster: Encodable {
try container.encodeIfPresent(hp, forKey: .hp) try container.encodeIfPresent(hp, forKey: .hp)
} }
try container.encodeIfPresent(name, forKey: .name) try container.encodeIfPresent(name, forKey: .name)
if inventoryCount > 0 { try container.encodeIfPresent(inventory, forKey: .inventory)
try container.encodeIfPresent(inventory, forKey: .inventory)
}
if color != .blue { if color != .blue {
try container.encodeIfPresent(color, forKey: .color) try container.encodeIfPresent(color, forKey: .color)
} }
if weaponsCount > 0 { try container.encodeIfPresent(weapons, forKey: .weapons)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .weapons)
for index in 0..<weaponsCount {
guard let type = weapons(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if equippedType != .none_ { if equippedType != .none_ {
try container.encodeIfPresent(equippedType, forKey: .equippedType) try container.encodeIfPresent(equippedType, forKey: .equippedType)
} }
@@ -372,13 +356,7 @@ extension MyGame_Sample_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .equipped) try container.encodeIfPresent(_v, forKey: .equipped)
default: break; default: break;
} }
if pathCount > 0 { try container.encodeIfPresent(path, forKey: .path)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .path)
for index in 0..<pathCount {
guard let type = path(at: index) else { continue }
try contentEncoder.encode(type)
}
}
} }
} }
@@ -392,7 +370,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
public var color: MyGame_Sample_Color public var color: MyGame_Sample_Color
public var weapons: [MyGame_Sample_WeaponT?] public var weapons: [MyGame_Sample_WeaponT?]
public var equipped: MyGame_Sample_EquipmentUnion? public var equipped: MyGame_Sample_EquipmentUnion?
public var path: [MyGame_Sample_Vec3?] public var path: [MyGame_Sample_Vec3]
public init(_ _t: inout MyGame_Sample_Monster) { public init(_ _t: inout MyGame_Sample_Monster) {
pos = _t.pos pos = _t.pos
@@ -400,14 +378,11 @@ public class MyGame_Sample_MonsterT: NativeObject {
hp = _t.hp hp = _t.hp
name = _t.name name = _t.name
inventory = [] inventory = []
for index in 0..<_t.inventoryCount { inventory.append(contentsOf: _t.inventory)
inventory.append(_t.inventory(at: index))
}
color = _t.color color = _t.color
weapons = [] weapons = []
for index in 0..<_t.weaponsCount { for var val in _t.weapons{
var __v_ = _t.weapons(at: index) weapons.append(val.unpack())
weapons.append(__v_?.unpack())
} }
switch _t.equippedType { switch _t.equippedType {
case .weapon: case .weapon:
@@ -416,9 +391,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
default: break default: break
} }
path = [] path = []
for index in 0..<_t.pathCount { path.append(contentsOf: _t.path)
path.append(_t.path(at: index))
}
} }
public init() { public init() {
@@ -434,7 +407,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Sample_Monster.self) } public func serialize() -> ByteBuffer { return serialize(type: MyGame_Sample_Monster.self) }
} }
public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable, ObjectAPIPacker { public struct MyGame_Sample_Weapon: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable, ObjectAPIPacker {
static func validateVersion() { FlatBuffersVersion_25_9_23() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -142,12 +142,6 @@ static std::string GenIndirect(const std::string& reading) {
return "{{ACCESS}}.indirect(" + reading + ")"; return "{{ACCESS}}.indirect(" + reading + ")";
} }
static std::string GenArrayMainBody(const std::string& optional) {
return "{{ACCESS_TYPE}} func {{FIELDMETHOD}}(at index: Int32) -> "
"{{VALUETYPE}}" +
optional + " { ";
}
} // namespace } // namespace
class SwiftGenerator : public BaseGenerator { class SwiftGenerator : public BaseGenerator {
@@ -234,7 +228,8 @@ class SwiftGenerator : public BaseGenerator {
GenComment(struct_def.doc_comment); GenComment(struct_def.doc_comment);
code_.SetValue("STRUCTNAME", namer_.NamespacedType(struct_def)); code_.SetValue("STRUCTNAME", namer_.NamespacedType(struct_def));
code_ += code_ +=
"{{ACCESS_TYPE}} struct {{STRUCTNAME}}: NativeStruct, Verifiable, " "{{ACCESS_TYPE}} struct {{STRUCTNAME}}: NativeStruct, "
"FlatbuffersVectorInitializable, Verifiable, "
"FlatbuffersInitializable\\"; "FlatbuffersInitializable\\";
if (parser_.opts.generate_object_based_api) code_ += ", NativeObject\\"; if (parser_.opts.generate_object_based_api) code_ += ", NativeObject\\";
code_ += " {"; code_ += " {";
@@ -473,7 +468,8 @@ class SwiftGenerator : public BaseGenerator {
code_.SetValue("OBJECTTYPE", struct_def.fixed ? "Struct" : "Table"); code_.SetValue("OBJECTTYPE", struct_def.fixed ? "Struct" : "Table");
code_.SetValue("MUTABLE", struct_def.fixed ? Mutable() : ""); code_.SetValue("MUTABLE", struct_def.fixed ? Mutable() : "");
code_ += code_ +=
"{{ACCESS_TYPE}} struct {{STRUCTNAME}}{{MUTABLE}}: FlatBufferObject\\"; "{{ACCESS_TYPE}} struct {{STRUCTNAME}}{{MUTABLE}}: "
"FlatBuffer{{OBJECTTYPE}}, FlatbuffersVectorInitializable\\";
if (!struct_def.fixed) code_ += ", Verifiable\\"; if (!struct_def.fixed) code_ += ", Verifiable\\";
if (!struct_def.fixed && parser_.opts.generate_object_based_api) if (!struct_def.fixed && parser_.opts.generate_object_based_api)
code_ += ", ObjectAPIPacker\\"; code_ += ", ObjectAPIPacker\\";
@@ -807,43 +803,23 @@ class SwiftGenerator : public BaseGenerator {
} }
void GenTableReaderVectorFields(const FieldDef& field) { void GenTableReaderVectorFields(const FieldDef& field) {
std::string const_string = "return o == 0 ? {{CONSTANT}} : ";
const auto vectortype = field.value.type.VectorType(); const auto vectortype = field.value.type.VectorType();
code_.SetValue("SIZE", NumToString(InlineSize(vectortype))); code_.SetValue("SIZE", NumToString(InlineSize(vectortype)));
code_.SetValue("HAS_FIELDVAR", namer_.Variable("has", field));
code_ += "{{ACCESS_TYPE}} var {{HAS_FIELDVAR}}: Bool { " + GenOffset() + if (vectortype.base_type == BASE_TYPE_STRING) {
"return o == 0 ? false : true }"; code_.SetValue("VALUETYPE", "String?");
code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}Count: Int32 { " + GenOffset() + }
"return o == 0 ? 0 : {{ACCESS}}.vector(count: o) }";
code_.SetValue("CONSTANT", IsScalar(vectortype.base_type) ? "0" : "nil");
const auto nullable =
IsScalar(vectortype.base_type) && !IsEnum(vectortype) ? "" : "?";
if (vectortype.base_type != BASE_TYPE_UNION) { if (vectortype.base_type != BASE_TYPE_UNION) {
code_ += GenArrayMainBody(nullable) + GenOffset() + "\\";
} else {
code_ += code_ +=
"{{ACCESS_TYPE}} func {{FIELDVAR}}<T: FlatbuffersInitializable>(at " "{{ACCESS_TYPE}} var {{FIELDVAR}}: "
"index: " "FlatbufferVector<{{VALUETYPE}}> "
"Int32, type: T.Type) -> T? { " + "{ return {{ACCESS}}.vector(at: {{TABLEOFFSET}}.{{OFFSET}}.v, "
GenOffset() + "\\"; "byteSize: {{SIZE}}) }";
} }
if (IsBool(vectortype.base_type)) {
code_.SetValue("CONSTANT", field.value.offset == 0 ? "false" : "true");
code_.SetValue("VALUETYPE", "Bool");
}
if (!IsEnum(vectortype)) code_ += const_string + "\\";
if (IsScalar(vectortype.base_type) && !IsEnum(vectortype) && if (IsScalar(vectortype.base_type) && !IsEnum(vectortype) &&
!IsBool(field.value.type.base_type)) { !IsBool(field.value.type.base_type)) {
code_ +=
"{{ACCESS}}.directRead(of: {{VALUETYPE}}.self, offset: "
"{{ACCESS}}.vector(at: o) + index * {{SIZE}}) }";
code_ +=
"{{ACCESS_TYPE}} var {{FIELDVAR}}: [{{VALUETYPE}}] { return "
"{{ACCESS}}.getVector(at: {{TABLEOFFSET}}.{{OFFSET}}.v) ?? [] }";
if (parser_.opts.mutable_buffer) code_ += GenMutateArray(); if (parser_.opts.mutable_buffer) code_ += GenMutateArray();
GenUnsafeBufferPointer(field); GenUnsafeBufferPointer(field);
return; return;
@@ -851,34 +827,26 @@ class SwiftGenerator : public BaseGenerator {
if (vectortype.base_type == BASE_TYPE_STRUCT && if (vectortype.base_type == BASE_TYPE_STRUCT &&
field.value.type.struct_def->fixed) { field.value.type.struct_def->fixed) {
code_.SetValue("FIELDVAR", namer_.Method("mutable", field));
code_ += code_ +=
"{{ACCESS}}.directRead(of: {{VALUETYPE}}.self, offset: " "{{ACCESS_TYPE}} var {{FIELDVAR}}: "
"{{ACCESS}}.vector(at: o) + index * {{SIZE}}) }"; "FlatbufferVector<{{VALUETYPE}}_Mutable> "
code_.SetValue("FIELDMETHOD", namer_.Method("mutable", field)); "{ return {{ACCESS}}.vector(at: {{TABLEOFFSET}}.{{OFFSET}}.v, "
code_.SetValue("VALUETYPE", GenType(field.value.type) + Mutable()); "byteSize: {{SIZE}}) }";
code_ += GenArrayMainBody(nullable) + GenOffset() + const_string +
GenConstructor("{{ACCESS}}.vector(at: o) + index * {{SIZE}}");
GenUnsafeBufferPointer(field); GenUnsafeBufferPointer(field);
return; return;
} }
if (IsString(vectortype)) {
code_ +=
"{{ACCESS}}.directString(at: {{ACCESS}}.vector(at: o) + "
"index * {{SIZE}}) }";
return;
}
if (IsEnum(vectortype)) {
code_.SetValue("BASEVALUE", GenTypeBasic(vectortype, false));
code_ += "return o == 0 ? {{VALUETYPE}}" + GenEnumDefaultValue(field) +
" : {{VALUETYPE}}(rawValue: {{ACCESS}}.directRead(of: "
"{{BASEVALUE}}.self, offset: {{ACCESS}}.vector(at: o) + "
"index * {{SIZE}})) }";
return;
}
if (vectortype.base_type == BASE_TYPE_UNION) { if (vectortype.base_type == BASE_TYPE_UNION) {
code_ +=
"{{ACCESS_TYPE}} var {{FIELDVAR}}: UnionFlatbufferVector "
"{ return {{ACCESS}}.unionVector(at: {{TABLEOFFSET}}.{{OFFSET}}.v, "
"byteSize: {{SIZE}}) }";
code_ +=
"{{ACCESS_TYPE}} func {{FIELDVAR}}<T: FlatbuffersInitializable>(at "
"index: "
"Int32, type: T.Type) -> T? { " +
GenOffset() + "return o == 0 ? nil : \\";
code_ += code_ +=
"{{ACCESS}}.directUnion({{ACCESS}}.vector(at: o) + " "{{ACCESS}}.directUnion({{ACCESS}}.vector(at: o) + "
"index * {{SIZE}}) }"; "index * {{SIZE}}) }";
@@ -887,9 +855,6 @@ class SwiftGenerator : public BaseGenerator {
if (vectortype.base_type == BASE_TYPE_STRUCT && if (vectortype.base_type == BASE_TYPE_STRUCT &&
!field.value.type.struct_def->fixed) { !field.value.type.struct_def->fixed) {
code_ += GenConstructor(
"{{ACCESS}}.indirect({{ACCESS}}.vector(at: o) + index * "
"{{SIZE}})");
const auto& sd = *field.value.type.struct_def; const auto& sd = *field.value.type.struct_def;
const auto& fields = sd.fields.vec; const auto& fields = sd.fields.vec;
for (auto kit = fields.begin(); kit != fields.end(); ++kit) { for (auto kit = fields.begin(); kit != fields.end(); ++kit) {
@@ -907,7 +872,8 @@ class SwiftGenerator : public BaseGenerator {
namer_.Variable("withUnsafePointerTo", field)); namer_.Variable("withUnsafePointerTo", field));
code_ += code_ +=
"{{ACCESS_TYPE}} func {{functionName}}<T>(_ body: " "{{ACCESS_TYPE}} func {{functionName}}<T>(_ body: "
"(UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try " "(UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return "
"try "
"{{ACCESS}}.withUnsafePointerToSlice(at: {{TABLEOFFSET}}.{{OFFSET}}.v, " "{{ACCESS}}.withUnsafePointerToSlice(at: {{TABLEOFFSET}}.{{OFFSET}}.v, "
"body: body) }"; "body: body) }";
} }
@@ -938,16 +904,15 @@ class SwiftGenerator : public BaseGenerator {
return; return;
if (is_vector) { if (is_vector) {
code_ += code_ +=
"var enumsEncoder = container.nestedUnkeyedContainer(forKey: " "try container.encode({{FIELDVAR}}Type, forKey: .charactersType)";
".{{FIELDVAR}}Type)";
code_ += code_ +=
"var contentEncoder = container.nestedUnkeyedContainer(forKey: " "var contentEncoder = container.nestedUnkeyedContainer(forKey: "
".{{FIELDVAR}})"; ".{{FIELDVAR}})";
code_ += "for index in 0..<{{FIELDVAR}}Count {"; code_ += "let _{{FIELDVAR}} = {{FIELDVAR}}Type";
code_ +=
"for index in _{{FIELDVAR}}.startIndex..<_{{FIELDVAR}}.endIndex {";
Indent(); Indent();
code_ += "guard let type = {{FIELDVAR}}Type(at: index) else { continue }"; code_ += "switch _{{FIELDVAR}}[index] {";
code_ += "try enumsEncoder.encode(type)";
code_ += "switch type {";
for (auto it = union_def.Vals().begin(); it != union_def.Vals().end(); for (auto it = union_def.Vals().begin(); it != union_def.Vals().end();
++it) { ++it) {
const auto& ev = **it; const auto& ev = **it;
@@ -959,7 +924,8 @@ class SwiftGenerator : public BaseGenerator {
} }
code_ += "case .{{KEY}}:"; code_ += "case .{{KEY}}:";
Indent(); Indent();
code_ += "let _v = {{FIELDVAR}}(at: index, type: {{VALUETYPE}}.self)"; code_ +=
"let _v = {{FIELDVAR}}(at: Int32(index), type: {{VALUETYPE}}.self)";
code_ += "try contentEncoder.encode(_v)"; code_ += "try contentEncoder.encode(_v)";
Outdent(); Outdent();
} }
@@ -998,17 +964,10 @@ class SwiftGenerator : public BaseGenerator {
if (field.deprecated) continue; if (field.deprecated) continue;
const auto type = field.value.type; const auto type = field.value.type;
const auto is_non_union_vector =
(field.value.type.base_type == BASE_TYPE_ARRAY ||
field.value.type.base_type == BASE_TYPE_VECTOR) &&
field.value.type.VectorType().base_type != BASE_TYPE_UTYPE;
code_.SetValue("FIELDVAR", namer_.Variable(field)); code_.SetValue("FIELDVAR", namer_.Variable(field));
code_.SetValue("CONSTANT", SwiftConstant(field)); code_.SetValue("CONSTANT", SwiftConstant(field));
bool should_indent = true; bool should_indent = true;
if (is_non_union_vector) { if (IsEnum(type) && !field.IsOptional()) {
code_ += "if {{FIELDVAR}}Count > 0 {";
} else if (IsEnum(type) && !field.IsOptional()) {
code_.SetValue("CONSTANT", GenEnumDefaultValue(field)); code_.SetValue("CONSTANT", GenEnumDefaultValue(field));
code_ += "if {{FIELDVAR}} != {{CONSTANT}} {"; code_ += "if {{FIELDVAR}} != {{CONSTANT}} {";
} else if (IsFloat(type.base_type) && } else if (IsFloat(type.base_type) &&
@@ -1027,18 +986,6 @@ class SwiftGenerator : public BaseGenerator {
if (IsUnion(type) && !IsEnum(type)) { if (IsUnion(type) && !IsEnum(type)) {
GenerateEncoderUnionBody(field); GenerateEncoderUnionBody(field);
} else if (is_non_union_vector &&
(!IsScalar(type.VectorType().base_type) ||
IsEnum(type.VectorType()))) {
code_ +=
"var contentEncoder = container.nestedUnkeyedContainer(forKey: "
".{{FIELDVAR}})";
code_ += "for index in 0..<{{FIELDVAR}}Count {";
Indent();
code_ += "guard let type = {{FIELDVAR}}(at: index) else { continue }";
code_ += "try contentEncoder.encode(type)";
Outdent();
code_ += "}";
} else { } else {
code_ += code_ +=
"try container.encodeIfPresent({{FIELDVAR}}, forKey: " "try container.encodeIfPresent({{FIELDVAR}}, forKey: "
@@ -1046,8 +993,7 @@ class SwiftGenerator : public BaseGenerator {
} }
if (should_indent) Outdent(); if (should_indent) Outdent();
if (is_non_union_vector || if ((IsScalar(type.base_type) && !field.IsOptional())) {
(IsScalar(type.base_type) && !field.IsOptional())) {
code_ += "}"; code_ += "}";
} }
} }
@@ -1202,7 +1148,8 @@ class SwiftGenerator : public BaseGenerator {
code_.SetValue("BASE_TYPE", GenTypeBasic(enum_def.underlying_type, false)); code_.SetValue("BASE_TYPE", GenTypeBasic(enum_def.underlying_type, false));
GenComment(enum_def.doc_comment); GenComment(enum_def.doc_comment);
code_ += code_ +=
"{{ACCESS_TYPE}} enum {{ENUM_NAME}}: {{BASE_TYPE}}, {{ENUM_TYPE}} {"; "{{ACCESS_TYPE}} enum {{ENUM_NAME}}: "
"{{BASE_TYPE}}, FlatbuffersVectorInitializable, {{ENUM_TYPE}} {";
Indent(); Indent();
code_ += "{{ACCESS_TYPE}} typealias T = {{BASE_TYPE}}"; code_ += "{{ACCESS_TYPE}} typealias T = {{BASE_TYPE}}";
if (enum_def.is_union) { if (enum_def.is_union) {
@@ -1481,10 +1428,9 @@ class SwiftGenerator : public BaseGenerator {
std::string code; std::string code;
GenerateStructArgs(*field_type.struct_def, &code, "", "", "_o", true); GenerateStructArgs(*field_type.struct_def, &code, "", "", "_o", true);
code = code.substr(0, code.size() - 2); code = code.substr(0, code.size() - 2);
code_ += "for i in obj." + field + " {"; code_ += "for val in obj." + field + " {";
Indent(); Indent();
code_ += "guard let _o = i else { continue }"; code_ += "builder.create(struct: val)";
code_ += "builder.create(struct: _o)";
Outdent(); Outdent();
code_ += "}"; code_ += "}";
code_ += "let __" + var + " = builder.endVector(len: obj." + field + code_ += "let __" + var + " = builder.endVector(len: obj." + field +
@@ -1636,23 +1582,24 @@ class SwiftGenerator : public BaseGenerator {
if (vectortype.base_type != BASE_TYPE_UTYPE) { if (vectortype.base_type != BASE_TYPE_UTYPE) {
buffer_constructor.push_back(field_var + " = []"); buffer_constructor.push_back(field_var + " = []");
buffer_constructor.push_back("for index in 0..<_t." + field_field +
"Count {");
base_constructor.push_back(field_var + " = []"); base_constructor.push_back(field_var + " = []");
} }
switch (vectortype.base_type) { switch (vectortype.base_type) {
case BASE_TYPE_STRUCT: { case BASE_TYPE_STRUCT: {
code_.SetValue("VALUETYPE", GenType(vectortype, true)); code_.SetValue("VALUETYPE", GenType(vectortype, true));
code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: [{{VALUETYPE}}?]"; code_.SetValue("OPTIONAL", !vectortype.struct_def->fixed ? "?" : "");
code_ +=
"{{ACCESS_TYPE}} var {{FIELDVAR}}: [{{VALUETYPE}}{{OPTIONAL}}]";
if (!vectortype.struct_def->fixed) { if (!vectortype.struct_def->fixed) {
buffer_constructor.push_back(indentation + "var __v_ = _t." + buffer_constructor.push_back("for var val in _t." + field_field +
field_field + "(at: index)"); "{");
buffer_constructor.push_back(indentation + field_var + buffer_constructor.push_back(indentation + field_var +
".append(__v_?.unpack())"); ".append(val.unpack())");
buffer_constructor.push_back("}");
} else { } else {
buffer_constructor.push_back(indentation + field_var + ".append(_t." + buffer_constructor.push_back(field_var + ".append(contentsOf: _t." +
field_var + "(at: index))"); field_field + ")");
} }
break; break;
} }
@@ -1674,21 +1621,11 @@ class SwiftGenerator : public BaseGenerator {
(IsString(vectortype) ? "String?" : GenType(vectortype))); (IsString(vectortype) ? "String?" : GenType(vectortype)));
code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: [{{VALUETYPE}}]"; code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: [{{VALUETYPE}}]";
if (IsEnum(vectortype) && vectortype.base_type != BASE_TYPE_UNION) { buffer_constructor.push_back(field_var + ".append(contentsOf: _t." +
const auto default_value = IsEnum(field.value.type) field_field + ")");
? GenEnumDefaultValue(field)
: SwiftConstant(field);
buffer_constructor.push_back(indentation + field_var + ".append(_t." +
field_field + "(at: index)!)");
break;
}
buffer_constructor.push_back(indentation + field_var + ".append(_t." +
field_field + "(at: index))");
break; break;
} }
} }
if (vectortype.base_type != BASE_TYPE_UTYPE)
buffer_constructor.push_back("}");
} }
void BuildUnionEnumSwitchCaseWritter(const EnumDef& ed) { void BuildUnionEnumSwitchCaseWritter(const EnumDef& ed) {
@@ -1720,9 +1657,17 @@ class SwiftGenerator : public BaseGenerator {
code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: \\"; code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: \\";
code_ += is_vector ? "[{{VALUETYPE}}Union?]" : "{{VALUETYPE}}Union?"; code_ += is_vector ? "[{{VALUETYPE}}Union?]" : "{{VALUETYPE}}Union?";
const auto vector_reader = is_vector ? "(at: index" : ""; const auto vector_reader = is_vector ? "[index]" : "";
if (is_vector) {
buffer_constructor.push_back("let _" + field + "Type = _t." + field +
"Type");
buffer_constructor.push_back("for index in _" + field +
"Type.startIndex..<_" + field +
"Type.endIndex {");
}
buffer_constructor.push_back(indentation + "switch _t." + field + "Type" + buffer_constructor.push_back(indentation + "switch _t." + field + "Type" +
vector_reader + (is_vector ? ")" : "") + " {"); vector_reader + " {");
for (auto it = ed.Vals().begin(); it < ed.Vals().end(); ++it) { for (auto it = ed.Vals().begin(); it < ed.Vals().end(); ++it) {
const auto ev = **it; const auto ev = **it;
@@ -1733,18 +1678,28 @@ class SwiftGenerator : public BaseGenerator {
const auto type = IsStruct(ev.union_type) const auto type = IsStruct(ev.union_type)
? GenType(ev.union_type) + Mutable() ? GenType(ev.union_type) + Mutable()
: GenType(ev.union_type); : GenType(ev.union_type);
buffer_constructor.push_back(indentation + "case ." + variant + ":"); buffer_constructor.push_back(indentation + "case ." + variant + ":");
buffer_constructor.push_back(
indentation + " var _v = _t." + field + (is_vector ? "" : "(") +
vector_reader + (is_vector ? ", " : "") + "type: " + type + ".self)");
const auto constructor = const auto constructor =
ns_type + "Union(_v?.unpack(), type: ." + variant + ")"; ns_type + "Union(_v?.unpack(), type: ." + variant + ")";
buffer_constructor.push_back( if (is_vector) {
indentation + " " + field + buffer_constructor.push_back(indentation + " var _v = _t." + field +
(is_vector ? ".append(" + constructor + ")" : " = " + constructor)); "(at: Int32(index), type: " + type +
".self)");
buffer_constructor.push_back(indentation + " " + field + ".append(" +
constructor + ")");
} else {
buffer_constructor.push_back(indentation + " var _v = _t." + field +
"(" + "type: " + type + ".self)");
buffer_constructor.push_back(indentation + " " + field + " = " +
constructor);
}
} }
buffer_constructor.push_back(indentation + "default: break"); buffer_constructor.push_back(indentation + "default: break");
buffer_constructor.push_back(indentation + "}"); buffer_constructor.push_back(indentation + "}");
if (is_vector) {
buffer_constructor.push_back("}");
}
} }
void AddMinOrMaxEnumValue(const std::string& str, const std::string& type) { void AddMinOrMaxEnumValue(const std::string& str, const std::string& type) {

View File

@@ -28,9 +28,9 @@ extension Int {
var n = UInt32(self) var n = UInt32(self)
#if arch(arm) || arch(i386) #if arch(arm) || arch(i386)
let max = UInt32(Int.max) let max = UInt32(Int.max)
#else #else
let max = UInt32.max let max = UInt32.max
#endif #endif
n -= 1 n -= 1

View File

@@ -23,7 +23,7 @@ import Foundation
@inline(__always) @inline(__always)
public func padding( public func padding(
bufSize: UInt, bufSize: UInt,
elementSize: UInt elementSize: UInt) -> UInt
) -> UInt { {
((~bufSize) &+ 1) & (elementSize &- 1) ((~bufSize) &+ 1) & (elementSize &- 1)
} }

View File

@@ -29,8 +29,8 @@ public struct ByteBuffer {
@usableFromInline @usableFromInline
enum Blob { enum Blob {
#if !os(WASI) #if !os(WASI)
case data(Data) case data(Data)
case bytes(ContiguousBytes) case bytes(ContiguousBytes)
#endif #endif
case byteBuffer(_InternalByteBuffer) case byteBuffer(_InternalByteBuffer)
@@ -96,16 +96,16 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeBytes<T>( func withUnsafeBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
switch retainedBlob { switch retainedBlob {
case .byteBuffer(let byteBuffer): case .byteBuffer(let byteBuffer):
return try byteBuffer.withUnsafeBytes(body) return try byteBuffer.withUnsafeBytes(body)
#if !os(WASI) #if !os(WASI)
case .data(let data): case .data(let data):
return try data.withUnsafeBytes(body) return try data.withUnsafeBytes(body)
case .bytes(let contiguousBytes): case .bytes(let contiguousBytes):
return try contiguousBytes.withUnsafeBytes(body) return try contiguousBytes.withUnsafeBytes(body)
#endif #endif
case .array(let array): case .array(let array):
return try array.withUnsafeBytes(body) return try array.withUnsafeBytes(body)
@@ -118,21 +118,21 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeRawPointer<T>( func withUnsafeRawPointer<T>(
_ body: (UnsafeMutableRawPointer) throws _ body: (UnsafeMutableRawPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
switch retainedBlob { switch retainedBlob {
case .byteBuffer(let byteBuffer): case .byteBuffer(let byteBuffer):
return try byteBuffer.withUnsafeRawPointer(body) return try byteBuffer.withUnsafeRawPointer(body)
#if !os(WASI) #if !os(WASI)
case .data(let data): case .data(let data):
return return
try data try data
.withUnsafeBytes { .withUnsafeBytes {
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!)) try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
} }
case .bytes(let contiguousBytes): case .bytes(let contiguousBytes):
return return
try contiguousBytes try contiguousBytes
.withUnsafeBytes { .withUnsafeBytes {
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!)) try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
} }
@@ -140,9 +140,9 @@ public struct ByteBuffer {
case .array(let array): case .array(let array):
return return
try array try array
.withUnsafeBytes { .withUnsafeBytes {
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!)) try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
} }
case .pointer(let ptr): case .pointer(let ptr):
return try body(ptr) return try body(ptr)
} }
@@ -152,20 +152,20 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func readWithUnsafeRawPointer<T>( func readWithUnsafeRawPointer<T>(
position: Int, position: Int,
_ body: (UnsafeRawPointer) throws -> T _ body: (UnsafeRawPointer) throws -> T) rethrows -> T
) rethrows -> T { {
switch retainedBlob { switch retainedBlob {
case .byteBuffer(let byteBuffer): case .byteBuffer(let byteBuffer):
return try byteBuffer.readWithUnsafeRawPointer(position: position, body) return try byteBuffer.readWithUnsafeRawPointer(position: position, body)
#if !os(WASI) #if !os(WASI)
case .data(let data): case .data(let data):
return try data.withUnsafeBytes { return try data.withUnsafeBytes {
try body($0.baseAddress!.advanced(by: position)) try body($0.baseAddress!.advanced(by: position))
} }
case .bytes(let contiguousBytes): case .bytes(let contiguousBytes):
return try contiguousBytes.withUnsafeBytes { return try contiguousBytes.withUnsafeBytes {
try body($0.baseAddress!.advanced(by: position)) try body($0.baseAddress!.advanced(by: position))
} }
#endif #endif
case .array(let array): case .array(let array):
return try array.withUnsafeBytes { return try array.withUnsafeBytes {
@@ -197,7 +197,7 @@ public struct ByteBuffer {
blob: .byteBuffer(byteBuffer), blob: .byteBuffer(byteBuffer),
capacity: byteBuffer.capacity) capacity: byteBuffer.capacity)
_readerIndex = Int(byteBuffer.size) _readerIndex = Int(byteBuffer.size)
self.capacity = byteBuffer.capacity capacity = byteBuffer.capacity
} }
/// Constructor that creates a Flatbuffer from unsafe memory region by copying /// Constructor that creates a Flatbuffer from unsafe memory region by copying
@@ -209,8 +209,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public init( public init(
copyingMemoryBound memory: UnsafeRawPointer, copyingMemoryBound memory: UnsafeRawPointer,
capacity: Int capacity: Int)
) { {
_storage = Storage(count: capacity) _storage = Storage(count: capacity)
_storage.copy(from: memory, count: capacity) _storage.copy(from: memory, count: capacity)
_readerIndex = capacity _readerIndex = capacity
@@ -228,29 +228,29 @@ public struct ByteBuffer {
} }
#if !os(WASI) #if !os(WASI)
/// Constructor that creates a Flatbuffer from the Swift Data type object /// Constructor that creates a Flatbuffer from the Swift Data type object
/// - Parameter /// - Parameter
/// - data: Swift data Object /// - data: Swift data Object
@inline(__always) @inline(__always)
public init(data: Data) { public init(data: Data) {
_storage = Storage(blob: .data(data), capacity: data.count) _storage = Storage(blob: .data(data), capacity: data.count)
_readerIndex = data.count _readerIndex = data.count
capacity = data.count capacity = data.count
} }
/// Constructor that creates a Flatbuffer object from a ContiguousBytes /// Constructor that creates a Flatbuffer object from a ContiguousBytes
/// - Parameters: /// - Parameters:
/// - contiguousBytes: Binary stripe to use as the buffer /// - contiguousBytes: Binary stripe to use as the buffer
/// - count: amount of readable bytes /// - count: amount of readable bytes
@inline(__always) @inline(__always)
public init<Bytes: ContiguousBytes>( public init<Bytes: ContiguousBytes>(
contiguousBytes: Bytes, contiguousBytes: Bytes,
count: Int count: Int)
) { {
_storage = Storage(blob: .bytes(contiguousBytes), capacity: count) _storage = Storage(blob: .bytes(contiguousBytes), capacity: count)
_readerIndex = count _readerIndex = count
self.capacity = count capacity = count
} }
#endif #endif
/// Constructor that creates a Flatbuffer from unsafe memory region without copying /// Constructor that creates a Flatbuffer from unsafe memory region without copying
@@ -262,8 +262,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public init( public init(
assumingMemoryBound memory: UnsafeMutableRawPointer, assumingMemoryBound memory: UnsafeMutableRawPointer,
capacity: Int capacity: Int)
) { {
_storage = Storage( _storage = Storage(
blob: .pointer(memory), blob: .pointer(memory),
capacity: capacity) capacity: capacity)
@@ -280,8 +280,8 @@ public struct ByteBuffer {
init( init(
blob: Storage.Blob, blob: Storage.Blob,
count: Int, count: Int,
removing removeBytes: Int removing removeBytes: Int)
) { {
_storage = Storage(blob: blob, capacity: count) _storage = Storage(blob: blob, capacity: count)
_readerIndex = removeBytes _readerIndex = removeBytes
capacity = count capacity = count
@@ -332,8 +332,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public func readSlice<T>( public func readSlice<T>(
index: Int, index: Int,
count: Int count: Int) -> [T]
) -> [T] { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
@@ -355,8 +355,8 @@ public struct ByteBuffer {
public func withUnsafePointerToSlice<T>( public func withUnsafePointerToSlice<T>(
index: Int, index: Int,
count: Int, count: Int,
body: (UnsafeRawBufferPointer) throws -> T body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T
) rethrows -> T { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
@@ -366,46 +366,46 @@ public struct ByteBuffer {
} }
#if !os(WASI) #if !os(WASI)
/// Reads a string from the buffer and encodes it to a swift string /// Reads a string from the buffer and encodes it to a swift string
/// - Parameters: /// - Parameters:
/// - index: index of the string in the buffer /// - index: index of the string in the buffer
/// - count: length of the string /// - count: length of the string
/// - type: Encoding of the string /// - type: Encoding of the string
@inline(__always) @inline(__always)
public func readString( public func readString(
at index: Int, at index: Int,
count: Int, count: Int,
type: String.Encoding = .utf8 type: String.Encoding = .utf8) -> String?
) -> String? { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
return _storage.readWithUnsafeRawPointer(position: index) { return _storage.readWithUnsafeRawPointer(position: index) {
let buf = UnsafeBufferPointer( let buf = UnsafeBufferPointer(
start: $0.bindMemory(to: UInt8.self, capacity: count), start: $0.bindMemory(to: UInt8.self, capacity: count),
count: count) count: count)
return String( return String(
bytes: buf, bytes: buf,
encoding: type) encoding: type)
}
} }
}
#else #else
/// Reads a string from the buffer and encodes it to a swift string /// Reads a string from the buffer and encodes it to a swift string
/// - Parameters: /// - Parameters:
/// - index: index of the string in the buffer /// - index: index of the string in the buffer
/// - count: length of the string /// - count: length of the string
@inline(__always) @inline(__always)
public func readString( public func readString(
at index: Int, at index: Int,
count: Int count: Int) -> String?
) -> String? { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
return _storage.readWithUnsafeRawPointer(position: index) { return _storage.readWithUnsafeRawPointer(position: index) {
String(cString: $0.bindMemory(to: UInt8.self, capacity: count)) String(cString: $0.bindMemory(to: UInt8.self, capacity: count))
}
} }
}
#endif #endif
/// Creates a new Flatbuffer object that's duplicated from the current one /// Creates a new Flatbuffer object that's duplicated from the current one
@@ -437,8 +437,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public func withUnsafeBytes<T>( public func withUnsafeBytes<T>(
body: (UnsafeRawBufferPointer) throws body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try _storage.withUnsafeBytes(body) try _storage.withUnsafeBytes(body)
} }
@@ -446,8 +446,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeMutableRawPointer<T>( func withUnsafeMutableRawPointer<T>(
body: (UnsafeMutableRawPointer) throws body: (UnsafeMutableRawPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try _storage.withUnsafeRawPointer(body) try _storage.withUnsafeRawPointer(body)
} }
@@ -455,8 +455,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func readWithUnsafeRawPointer<T>( func readWithUnsafeRawPointer<T>(
position: Int, position: Int,
_ body: (UnsafeRawPointer) throws -> T _ body: (UnsafeRawPointer) throws -> T) rethrows -> T
) rethrows -> T { {
try _storage.readWithUnsafeRawPointer(position: position, body) try _storage.readWithUnsafeRawPointer(position: position, body)
} }
} }

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// Type aliases /// Type aliases
@@ -28,7 +28,7 @@ public typealias VOffset = UInt16
/// Maximum size for a buffer /// Maximum size for a buffer
public let FlatBufferMaxSize = public let FlatBufferMaxSize =
UInt32 UInt32
.max << ((MemoryLayout<SOffset>.size * 8 - 1) - 1) .max << ((MemoryLayout<SOffset>.size * 8 - 1) - 1)
/// Protocol that All Scalars should conform to /// Protocol that All Scalars should conform to
/// ///
@@ -36,28 +36,28 @@ public let FlatBufferMaxSize =
extension Scalar where Self: FixedWidthInteger {} extension Scalar where Self: FixedWidthInteger {}
extension Double: Verifiable {} extension Double: Verifiable, FlatbuffersVectorInitializable {}
extension Float32: Verifiable {} extension Float32: Verifiable, FlatbuffersVectorInitializable {}
extension Bool: Verifiable {} extension Bool: Verifiable, FlatbuffersVectorInitializable {}
extension Int: Verifiable {} extension Int: Verifiable, FlatbuffersVectorInitializable {}
extension Int8: Verifiable {} extension Int8: Verifiable, FlatbuffersVectorInitializable {}
extension Int16: Verifiable {} extension Int16: Verifiable, FlatbuffersVectorInitializable {}
extension Int32: Verifiable {} extension Int32: Verifiable, FlatbuffersVectorInitializable {}
extension Int64: Verifiable {} extension Int64: Verifiable, FlatbuffersVectorInitializable {}
extension UInt8: Verifiable {} extension UInt8: Verifiable, FlatbuffersVectorInitializable {}
extension UInt16: Verifiable {} extension UInt16: Verifiable, FlatbuffersVectorInitializable {}
extension UInt32: Verifiable {} extension UInt32: Verifiable, FlatbuffersVectorInitializable {}
extension UInt64: Verifiable {} extension UInt64: Verifiable, FlatbuffersVectorInitializable {}
public func FlatBuffersVersion_25_9_23() {} public func FlatBuffersVersion_25_9_23() {}

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// Enum is a protocol that all flatbuffers enums should conform to /// Enum is a protocol that all flatbuffers enums should conform to
@@ -28,8 +28,13 @@ public protocol Enum {
associatedtype T: Scalar & Verifiable associatedtype T: Scalar & Verifiable
/// Size of the current associatedtype in the enum /// Size of the current associatedtype in the enum
static var byteSize: Int { get } static var byteSize: Int { get }
/// Provides a static min value in case we fail to decode
/// in vectors
static var min: Self { get }
/// The current value the enum hosts /// The current value the enum hosts
var value: T { get } var value: T { get }
init?(rawValue: T)
} }
extension Enum where Self: Verifiable { extension Enum where Self: Verifiable {
@@ -44,8 +49,8 @@ extension Enum where Self: Verifiable {
public static func verify<T>( public static func verify<T>(
_ verifier: inout Verifier, _ verifier: inout Verifier,
at position: Int, at position: Int,
of type: T.Type of type: T.Type) throws where T: Verifiable
) throws where T: Verifiable { {
try verifier.inBuffer(position: position, of: type.self) try verifier.inBuffer(position: position, of: type.self)
} }

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// ``FlatBufferBuilder`` builds a `FlatBuffer` through manipulating its internal state. /// ``FlatBufferBuilder`` builds a `FlatBuffer` through manipulating its internal state.
@@ -63,21 +63,21 @@ public struct FlatBufferBuilder {
public var capacity: Int { _bb.capacity } public var capacity: Int { _bb.capacity }
#if !os(WASI) #if !os(WASI)
/// Data representation of the buffer /// Data representation of the buffer
/// ///
/// Should only be used after ``finish(offset:addPrefix:)`` is called /// Should only be used after ``finish(offset:addPrefix:)`` is called
public var data: Data { public var data: Data {
assert(finished, "Data shouldn't be called before finish()") assert(finished, "Data shouldn't be called before finish()")
return _bb.withUnsafeSlicedBytes { ptr in return _bb.withUnsafeSlicedBytes { ptr in
var data = Data() var data = Data()
data.append( data.append(
ptr.baseAddress!.bindMemory( ptr.baseAddress!.bindMemory(
to: UInt8.self, to: UInt8.self,
capacity: ptr.count), capacity: ptr.count),
count: ptr.count) count: ptr.count)
return data return data
}
} }
}
#endif #endif
/// Returns the underlying bytes in the ``ByteBuffer`` /// Returns the underlying bytes in the ``ByteBuffer``
@@ -132,8 +132,8 @@ public struct FlatBufferBuilder {
/// however the builder can be force by passing true for `serializeDefaults` /// however the builder can be force by passing true for `serializeDefaults`
public init( public init(
initialSize: Int32 = 1024, initialSize: Int32 = 1024,
serializeDefaults force: Bool = false serializeDefaults force: Bool = false)
) { {
assert(initialSize > 0, "Size should be greater than zero!") assert(initialSize > 0, "Size should be greater than zero!")
guard isLitteEndian else { guard isLitteEndian else {
fatalError( fatalError(
@@ -200,8 +200,8 @@ public struct FlatBufferBuilder {
mutating public func finish( mutating public func finish(
offset: Offset, offset: Offset,
fileId: String, fileId: String,
addPrefix prefix: Bool = false addPrefix prefix: Bool = false)
) { {
let size = MemoryLayout<UOffset>.size let size = MemoryLayout<UOffset>.size
preAlign( preAlign(
len: size &+ (prefix ? size : 0) &+ FileIdLength, len: size &+ (prefix ? size : 0) &+ FileIdLength,
@@ -230,8 +230,8 @@ public struct FlatBufferBuilder {
/// include the size of the current buffer. /// include the size of the current buffer.
mutating public func finish( mutating public func finish(
offset: Offset, offset: Offset,
addPrefix prefix: Bool = false addPrefix prefix: Bool = false)
) { {
notNested() notNested()
let size = MemoryLayout<UOffset>.size let size = MemoryLayout<UOffset>.size
preAlign(len: size &+ (prefix ? size : 0), alignment: _minAlignment) preAlign(len: size &+ (prefix ? size : 0), alignment: _minAlignment)
@@ -470,8 +470,8 @@ public struct FlatBufferBuilder {
@inline(__always) @inline(__always)
mutating public func createVector<T: Scalar>( mutating public func createVector<T: Scalar>(
_ elements: [T], _ elements: [T],
size: Int size: Int) -> Offset
) -> Offset { {
let size = size let size = size
startVector(size, elementSize: MemoryLayout<T>.size) startVector(size, elementSize: MemoryLayout<T>.size)
_bb.push(elements: elements) _bb.push(elements: elements)
@@ -479,20 +479,20 @@ public struct FlatBufferBuilder {
} }
#if swift(>=5.0) && !os(WASI) #if swift(>=5.0) && !os(WASI)
@inline(__always) @inline(__always)
/// Creates a vector of bytes in the buffer. /// Creates a vector of bytes in the buffer.
/// ///
/// Allows creating a vector from `Data` without copying to a `[UInt8]` /// Allows creating a vector from `Data` without copying to a `[UInt8]`
/// ///
/// - Parameter bytes: bytes to be written into the buffer /// - Parameter bytes: bytes to be written into the buffer
/// - Returns: ``Offset`` of the vector /// - Returns: ``Offset`` of the vector
mutating public func createVector(bytes: ContiguousBytes) -> Offset { mutating public func createVector(bytes: ContiguousBytes) -> Offset {
bytes.withUnsafeBytes { bytes.withUnsafeBytes {
startVector($0.count, elementSize: MemoryLayout<UInt8>.size) startVector($0.count, elementSize: MemoryLayout<UInt8>.size)
_bb.push(bytes: $0) _bb.push(bytes: $0)
return endVector(len: $0.count) return endVector(len: $0.count)
}
} }
}
#endif #endif
/// Creates a vector of type ``Enum`` into the ``ByteBuffer`` /// Creates a vector of type ``Enum`` into the ``ByteBuffer``
@@ -530,8 +530,8 @@ public struct FlatBufferBuilder {
@inline(__always) @inline(__always)
mutating public func createVector<T: Enum>( mutating public func createVector<T: Enum>(
_ elements: [T], _ elements: [T],
size: Int size: Int) -> Offset
) -> Offset { {
let size = size let size = size
startVector(size, elementSize: T.byteSize) startVector(size, elementSize: T.byteSize)
for index in stride(from: elements.count, to: 0, by: -1) { for index in stride(from: elements.count, to: 0, by: -1) {
@@ -576,8 +576,8 @@ public struct FlatBufferBuilder {
@inline(__always) @inline(__always)
mutating public func createVector( mutating public func createVector(
ofOffsets offsets: [Offset], ofOffsets offsets: [Offset],
len: Int len: Int) -> Offset
) -> Offset { {
startVector(len, elementSize: MemoryLayout<Offset>.size) startVector(len, elementSize: MemoryLayout<Offset>.size)
for index in stride(from: offsets.count, to: 0, by: -1) { for index in stride(from: offsets.count, to: 0, by: -1) {
push(element: offsets[index &- 1]) push(element: offsets[index &- 1])
@@ -653,8 +653,8 @@ public struct FlatBufferBuilder {
@inline(__always) @inline(__always)
@discardableResult @discardableResult
mutating public func create<T: NativeStruct>( mutating public func create<T: NativeStruct>(
struct s: T, position: VOffset struct s: T, position: VOffset) -> Offset
) -> Offset { {
let offset = create(struct: s) let offset = create(struct: s)
_vtableStorage.add( _vtableStorage.add(
loc: (offset: _bb.size, position: VOffset(position))) loc: (offset: _bb.size, position: VOffset(position)))
@@ -678,8 +678,8 @@ public struct FlatBufferBuilder {
@inline(__always) @inline(__always)
@discardableResult @discardableResult
mutating public func create<T: NativeStruct>( mutating public func create<T: NativeStruct>(
struct s: T struct s: T) -> Offset
) -> Offset { {
let size = MemoryLayout<T>.size let size = MemoryLayout<T>.size
preAlign(len: size, alignment: MemoryLayout<T>.alignment) preAlign(len: size, alignment: MemoryLayout<T>.alignment)
_bb.push(struct: s, size: size) _bb.push(struct: s, size: size)
@@ -794,8 +794,8 @@ public struct FlatBufferBuilder {
mutating public func add<T: Scalar>( mutating public func add<T: Scalar>(
element: T, element: T,
def: T, def: T,
at position: VOffset at position: VOffset)
) { {
if element == def && !serializeDefaults { return } if element == def && !serializeDefaults { return }
track(offset: push(element: element), at: position) track(offset: push(element: element), at: position)
} }

View File

@@ -28,8 +28,17 @@ public protocol FlatbuffersInitializable {
init(_ bb: ByteBuffer, o: Int32) init(_ bb: ByteBuffer, o: Int32)
} }
/// FlatbufferObject structures all the Flatbuffers objects /// FlatbufferTabke structures all the Flatbuffers tables
public protocol FlatBufferObject: FlatbuffersInitializable { public protocol FlatBufferTable: FlatbuffersInitializable,
FlatbuffersVectorInitializable
{
var __buffer: ByteBuffer! { get }
}
/// FlatbufferStruct structures all the Flatbuffers structs
public protocol FlatBufferStruct: FlatbuffersInitializable,
FlatbuffersVectorInitializable
{
var __buffer: ByteBuffer! { get } var __buffer: ByteBuffer! { get }
} }

View File

@@ -63,13 +63,13 @@ public enum FlatbuffersErrors: Error, Equatable {
#if !os(WASI) #if !os(WASI)
extension FlatbuffersErrors { extension FlatbuffersErrors {
public static func == ( public static func == (
lhs: FlatbuffersErrors, lhs: FlatbuffersErrors,
rhs: FlatbuffersErrors rhs: FlatbuffersErrors) -> Bool
) -> Bool { {
lhs.localizedDescription == rhs.localizedDescription lhs.localizedDescription == rhs.localizedDescription
}
} }
}
#endif #endif

View File

@@ -28,20 +28,20 @@ public protocol FlatBufferGRPCMessage {
@inline(__always) @inline(__always)
func withUnsafeReadableBytes<T>( func withUnsafeReadableBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T
} }
/// Message is a wrapper around Buffers to to able to send Flatbuffers `Buffers` through the /// Message is a wrapper around Buffers to to able to send Flatbuffers `Buffers` through the
/// GRPC library /// GRPC library
public struct Message<T: FlatBufferObject>: FlatBufferGRPCMessage { public struct Message<T: FlatBufferTable>: FlatBufferGRPCMessage {
internal var buffer: ByteBuffer internal var buffer: ByteBuffer
/// Returns the an object of type T that would be read from the buffer /// Returns the an object of type T that would be read from the buffer
public var object: T { public var object: T {
T.init( T.init(
buffer, buffer,
o: Int32(buffer.read(def: UOffset.self, position: buffer.reader)) &+ Int32(buffer.reader)) o: Int32(buffer.read(def: UOffset.self, position: buffer.reader)) &+
Int32(buffer.reader))
} }
public var size: Int { Int(buffer.size) } public var size: Int { Int(buffer.size) }
@@ -66,8 +66,8 @@ public struct Message<T: FlatBufferObject>: FlatBufferGRPCMessage {
@inline(__always) @inline(__always)
public func withUnsafeReadableBytes<Data>( public func withUnsafeReadableBytes<Data>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> Data -> Data) rethrows -> Data
) rethrows -> Data { {
return try buffer.readWithUnsafeRawPointer(position: buffer.reader) { return try buffer.readWithUnsafeRawPointer(position: buffer.reader) {
try body(UnsafeRawBufferPointer(start: $0, count: size)) try body(UnsafeRawBufferPointer(start: $0, count: size))
} }

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// Mutable is a protocol that allows us to mutate Scalar values within a ``ByteBuffer`` /// Mutable is a protocol that allows us to mutate Scalar values within a ``ByteBuffer``

View File

@@ -27,7 +27,8 @@ extension NativeObject {
/// - Parameter type: Type of the Flatbuffer object /// - Parameter type: Type of the Flatbuffer object
/// - Returns: returns the encoded sized ByteBuffer /// - Returns: returns the encoded sized ByteBuffer
public func serialize<T: ObjectAPIPacker>(type: T.Type) -> ByteBuffer public func serialize<T: ObjectAPIPacker>(type: T.Type) -> ByteBuffer
where T.T == Self { where T.T == Self
{
var builder = FlatBufferBuilder(initialSize: 1024) var builder = FlatBufferBuilder(initialSize: 1024)
return serialize(builder: &builder, type: type.self) return serialize(builder: &builder, type: type.self)
} }
@@ -42,8 +43,8 @@ extension NativeObject {
/// It can be considered less expensive in terms of memory allocation /// It can be considered less expensive in terms of memory allocation
public func serialize<T: ObjectAPIPacker>( public func serialize<T: ObjectAPIPacker>(
builder: inout FlatBufferBuilder, builder: inout FlatBufferBuilder,
type: T.Type type: T.Type) -> ByteBuffer where T.T == Self
) -> ByteBuffer where T.T == Self { {
var s = self var s = self
let root = type.pack(&builder, obj: &s) let root = type.pack(&builder, obj: &s)
builder.finish(offset: root) builder.finish(offset: root)

View File

@@ -26,11 +26,11 @@ import Foundation
/// ///
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in /// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
/// the ``ByteBuffer`` and verifies the buffer by calling ``getCheckedRoot(byteBuffer:options:)`` /// the ``ByteBuffer`` and verifies the buffer by calling ``getCheckedRoot(byteBuffer:options:)``
public func getPrefixedSizeCheckedRoot<T: FlatBufferObject & Verifiable>( public func getPrefixedSizeCheckedRoot<T: FlatBufferTable & Verifiable>(
byteBuffer: inout ByteBuffer, byteBuffer: inout ByteBuffer,
fileId: String? = nil, fileId: String? = nil,
options: VerifierOptions = .init() options: VerifierOptions = .init()) throws -> T
) throws -> T { {
byteBuffer.skipPrefix() byteBuffer.skipPrefix()
return try getCheckedRoot( return try getCheckedRoot(
byteBuffer: &byteBuffer, byteBuffer: &byteBuffer,
@@ -48,11 +48,11 @@ public func getPrefixedSizeCheckedRoot<T: FlatBufferObject & Verifiable>(
/// ///
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in /// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
/// the ``ByteBuffer`` and verifies the buffer by calling ``getCheckedRoot(byteBuffer:options:)`` /// the ``ByteBuffer`` and verifies the buffer by calling ``getCheckedRoot(byteBuffer:options:)``
public func getCheckedPrefixedSizeRoot<T: FlatBufferObject & Verifiable>( public func getCheckedPrefixedSizeRoot<T: FlatBufferTable & Verifiable>(
byteBuffer: inout ByteBuffer, byteBuffer: inout ByteBuffer,
fileId: String? = nil, fileId: String? = nil,
options: VerifierOptions = .init() options: VerifierOptions = .init()) throws -> T
) throws -> T { {
let prefix = byteBuffer.skipPrefix() let prefix = byteBuffer.skipPrefix()
if prefix != byteBuffer.size { if prefix != byteBuffer.size {
throw FlatbuffersErrors.prefixedSizeNotEqualToBufferSize throw FlatbuffersErrors.prefixedSizeNotEqualToBufferSize
@@ -70,9 +70,8 @@ public func getCheckedPrefixedSizeRoot<T: FlatBufferObject & Verifiable>(
/// ///
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in /// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
/// the ``ByteBuffer`` and then calls ``getRoot(byteBuffer:)`` /// the ``ByteBuffer`` and then calls ``getRoot(byteBuffer:)``
public func getPrefixedSizeRoot<T: FlatBufferObject>( public func getPrefixedSizeRoot<T: FlatBufferTable>(
byteBuffer: inout ByteBuffer byteBuffer: inout ByteBuffer)
)
-> T -> T
{ {
byteBuffer.skipPrefix() byteBuffer.skipPrefix()
@@ -90,11 +89,11 @@ public func getPrefixedSizeRoot<T: FlatBufferObject>(
/// ``getCheckedRoot(byteBuffer:options:)`` Takes in a ``ByteBuffer`` and verifies /// ``getCheckedRoot(byteBuffer:options:)`` Takes in a ``ByteBuffer`` and verifies
/// that by creating a ``Verifier`` and checkes if all the `Bytes` and correctly aligned /// that by creating a ``Verifier`` and checkes if all the `Bytes` and correctly aligned
/// and within the ``ByteBuffer`` range. /// and within the ``ByteBuffer`` range.
public func getCheckedRoot<T: FlatBufferObject & Verifiable>( public func getCheckedRoot<T: FlatBufferTable & Verifiable>(
byteBuffer: inout ByteBuffer, byteBuffer: inout ByteBuffer,
fileId: String? = nil, fileId: String? = nil,
options: VerifierOptions = .init() options: VerifierOptions = .init()) throws -> T
) throws -> T { {
var verifier = try Verifier(buffer: &byteBuffer, options: options) var verifier = try Verifier(buffer: &byteBuffer, options: options)
if let fileId = fileId { if let fileId = fileId {
try verifier.verify(id: fileId) try verifier.verify(id: fileId)
@@ -109,7 +108,7 @@ public func getCheckedRoot<T: FlatBufferObject & Verifiable>(
/// Returns a `NON-Checked` flatbuffers object /// Returns a `NON-Checked` flatbuffers object
/// - Parameter byteBuffer: Buffer that contains data /// - Parameter byteBuffer: Buffer that contains data
/// - Returns: Returns a Flatbuffers object /// - Returns: Returns a Flatbuffers object
public func getRoot<T: FlatBufferObject>(byteBuffer: inout ByteBuffer) -> T { public func getRoot<T: FlatBufferTable>(byteBuffer: inout ByteBuffer) -> T {
T.init( T.init(
byteBuffer, byteBuffer,
o: Int32(byteBuffer.read(def: UOffset.self, position: byteBuffer.reader)) o: Int32(byteBuffer.read(def: UOffset.self, position: byteBuffer.reader))

View File

@@ -28,8 +28,8 @@ extension String: Verifiable {
public static func verify<T>( public static func verify<T>(
_ verifier: inout Verifier, _ verifier: inout Verifier,
at position: Int, at position: Int,
of type: T.Type of type: T.Type) throws where T: Verifiable
) throws where T: Verifiable { {
let range = try String.verifyRange(&verifier, at: position, of: UInt8.self) let range = try String.verifyRange(&verifier, at: position, of: UInt8.self)
/// Safe &+ since we already check for overflow in verify range /// Safe &+ since we already check for overflow in verify range
@@ -75,16 +75,16 @@ extension String: ObjectAPIPacker {
public static func pack( public static func pack(
_ builder: inout FlatBufferBuilder, _ builder: inout FlatBufferBuilder,
obj: inout String? obj: inout String?) -> Offset
) -> Offset { {
guard var obj = obj else { return Offset() } guard var obj = obj else { return Offset() }
return pack(&builder, obj: &obj) return pack(&builder, obj: &obj)
} }
public static func pack( public static func pack(
_ builder: inout FlatBufferBuilder, _ builder: inout FlatBufferBuilder,
obj: inout String obj: inout String) -> Offset
) -> Offset { {
builder.create(string: obj) builder.create(string: obj)
} }
@@ -97,14 +97,15 @@ extension String: ObjectAPIPacker {
extension String: NativeObject { extension String: NativeObject {
public func serialize<T: ObjectAPIPacker>(type: T.Type) -> ByteBuffer public func serialize<T: ObjectAPIPacker>(type: T.Type) -> ByteBuffer
where T.T == Self { where T.T == Self
{
fatalError("serialize should never be called from string directly") fatalError("serialize should never be called from string directly")
} }
public func serialize<T: ObjectAPIPacker>( public func serialize<T: ObjectAPIPacker>(
builder: inout FlatBufferBuilder, builder: inout FlatBufferBuilder,
type: T.Type type: T.Type) -> ByteBuffer where T.T == Self
) -> ByteBuffer where T.T == Self { {
fatalError("serialize should never be called from string directly") fatalError("serialize should never be called from string directly")
} }
} }

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// Struct is a representation of a mutable `Flatbuffers` struct /// Struct is a representation of a mutable `Flatbuffers` struct

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// `Table` is a Flatbuffers object that can read, /// `Table` is a Flatbuffers object that can read,
@@ -71,15 +71,7 @@ public struct Table {
/// String reads from the buffer with respect to position of the current table. /// String reads from the buffer with respect to position of the current table.
/// - Parameter offset: Offset of the string /// - Parameter offset: Offset of the string
public func string(at offset: Int32) -> String? { public func string(at offset: Int32) -> String? {
directString(at: offset &+ position) var offset = offset &+ position
}
/// Direct string reads from the buffer disregarding the position of the table.
/// It would be preferable to use string unless the current position of the table
/// is not needed
/// - Parameter offset: Offset of the string
public func directString(at offset: Int32) -> String? {
var offset = offset
offset &+= bb.read(def: Int32.self, position: Int(offset)) offset &+= bb.read(def: Int32.self, position: Int(offset))
let count = bb.read(def: Int32.self, position: Int(offset)) let count = bb.read(def: Int32.self, position: Int(offset))
let position = Int(offset) &+ MemoryLayout<Int32>.size let position = Int(offset) &+ MemoryLayout<Int32>.size
@@ -91,24 +83,7 @@ public struct Table {
/// - type: Type of Element that needs to be read from the buffer /// - type: Type of Element that needs to be read from the buffer
/// - o: Offset of the Element /// - o: Offset of the Element
public func readBuffer<T>(of type: T.Type, at o: Int32) -> T { public func readBuffer<T>(of type: T.Type, at o: Int32) -> T {
directRead(of: T.self, offset: o &+ position) bb.read(def: T.self, position: Int(o &+ position))
}
/// Reads from the buffer disregarding the position of the table.
/// It would be used when reading from an
/// ```
/// let offset = __t.offset(10)
/// //Only used when the we already know what is the
/// // position in the table since __t.vector(at:)
/// // returns the index with respect to the position
/// __t.directRead(of: Byte.self,
/// offset: __t.vector(at: offset) + index * 1)
/// ```
/// - Parameters:
/// - type: Type of Element that needs to be read from the buffer
/// - o: Offset of the Element
public func directRead<T>(of type: T.Type, offset o: Int32) -> T {
bb.read(def: T.self, position: Int(o))
} }
/// Returns that current `Union` object at a specific offset /// Returns that current `Union` object at a specific offset
@@ -137,6 +112,35 @@ public struct Table {
return bb.readSlice(index: Int(vector(at: o)), count: Int(vector(count: o))) return bb.readSlice(index: Int(vector(at: o)), count: Int(vector(count: o)))
} }
public func vector<T>(at off: Int32, byteSize: Int) -> FlatbufferVector<T> {
let off = offset(off)
return FlatbufferVector(
bb: bb,
startPosition: vector(at: off),
count: Int(count(offset: off)),
byteSize: byteSize)
}
public func unionVector(
at off: Int32,
byteSize: Int) -> UnionFlatbufferVector
{
let off = offset(off)
return UnionFlatbufferVector(
bb: bb,
startPosition: vector(at: off),
count: Int(count(offset: off)),
byteSize: byteSize)
}
private func count(offset: Int32) -> Int32 {
if offset == 0 {
return 0
}
return vector(count: offset)
}
/// Returns the underlying pointer to a vector within the buffer /// Returns the underlying pointer to a vector within the buffer
/// This should only be used by `Scalars` /// This should only be used by `Scalars`
/// - Parameter off: Readable offset /// - Parameter off: Readable offset
@@ -144,14 +148,15 @@ public struct Table {
@inline(__always) @inline(__always)
public func withUnsafePointerToSlice<T>( public func withUnsafePointerToSlice<T>(
at off: Int32, at off: Int32,
body: (UnsafeRawBufferPointer) throws -> T body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T?
) rethrows -> T? { {
let o = offset(off) let o = offset(off)
guard o != 0 else { return nil } guard o != 0 else { return nil }
let count = Int(vector(count: o))
return try bb.withUnsafePointerToSlice( return try bb.withUnsafePointerToSlice(
index: Int(vector(at: o)), index: Int(vector(at: o)),
count: Int(vector(count: o)), count: count,
body: body) body: { try body($0, count) })
} }
/// Vector count gets the count of Elements within the array /// Vector count gets the count of Elements within the array
@@ -192,8 +197,8 @@ public struct Table {
static public func offset( static public func offset(
_ o: Int32, _ o: Int32,
vOffset: Int32, vOffset: Int32,
fbb: inout FlatBufferBuilder fbb: inout FlatBufferBuilder) -> Int32
) -> Int32 { {
let vTable = Int32(fbb.capacity) &- o let vTable = Int32(fbb.capacity) &- o
return vTable return vTable
&+ Int32( &+ Int32(
@@ -216,8 +221,8 @@ public struct Table {
static public func compare( static public func compare(
_ off1: Int32, _ off1: Int32,
_ off2: Int32, _ off2: Int32,
fbb: inout FlatBufferBuilder fbb: inout FlatBufferBuilder) -> Int32
) -> Int32 { {
let memorySize = Int32(MemoryLayout<Int32>.size) let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1)) let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1))
let _off2 = off2 &+ fbb.read(def: Int32.self, position: Int(off2)) let _off2 = off2 &+ fbb.read(def: Int32.self, position: Int(off2))
@@ -246,8 +251,8 @@ public struct Table {
static public func compare( static public func compare(
_ off1: Int32, _ off1: Int32,
_ key: [Byte], _ key: [Byte],
fbb: inout FlatBufferBuilder fbb: inout FlatBufferBuilder) -> Int32
) -> Int32 { {
let memorySize = Int32(MemoryLayout<Int32>.size) let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1)) let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1))
let len1 = fbb.read(def: Int32.self, position: Int(_off1)) let len1 = fbb.read(def: Int32.self, position: Int(_off1))
@@ -274,8 +279,8 @@ public struct Table {
static public func offset( static public func offset(
_ o: Int32, _ o: Int32,
vOffset: Int32, vOffset: Int32,
fbb: ByteBuffer fbb: ByteBuffer) -> Int32
) -> Int32 { {
let vTable = Int32(fbb.capacity) &- o let vTable = Int32(fbb.capacity) &- o
return vTable return vTable
&+ Int32( &+ Int32(
@@ -298,8 +303,8 @@ public struct Table {
static public func compare( static public func compare(
_ off1: Int32, _ off1: Int32,
_ off2: Int32, _ off2: Int32,
fbb: ByteBuffer fbb: ByteBuffer) -> Int32
) -> Int32 { {
let memorySize = Int32(MemoryLayout<Int32>.size) let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1)) let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1))
let _off2 = off2 &+ fbb.read(def: Int32.self, position: Int(off2)) let _off2 = off2 &+ fbb.read(def: Int32.self, position: Int(off2))
@@ -328,8 +333,8 @@ public struct Table {
static public func compare( static public func compare(
_ off1: Int32, _ off1: Int32,
_ key: [Byte], _ key: [Byte],
fbb: ByteBuffer fbb: ByteBuffer) -> Int32
) -> Int32 { {
let memorySize = Int32(MemoryLayout<Int32>.size) let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1)) let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1))
let len1 = fbb.read(def: Int32.self, position: Int(_off1)) let len1 = fbb.read(def: Int32.self, position: Int(_off1))

View File

@@ -45,8 +45,8 @@ public struct TableVerifier {
position: Int, position: Int,
vtable: Int, vtable: Int,
vtableLength: Int, vtableLength: Int,
verifier: inout Verifier verifier: inout Verifier)
) { {
_position = position _position = position
_vtable = vtable _vtable = vtable
_vtableLength = vtableLength _vtableLength = vtableLength
@@ -84,8 +84,8 @@ public struct TableVerifier {
field: VOffset, field: VOffset,
fieldName: String, fieldName: String,
required: Bool, required: Bool,
type: T.Type type: T.Type) throws where T: Verifiable
) throws where T: Verifiable { {
let derefValue = try dereference(field) let derefValue = try dereference(field)
if let value = derefValue { if let value = derefValue {
@@ -115,9 +115,9 @@ public struct TableVerifier {
unionKeyName: String, unionKeyName: String,
fieldName: String, fieldName: String,
required: Bool, required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
) throws where T: UnionEnum
where T: UnionEnum { {
let keyPos = try dereference(key) let keyPos = try dereference(key)
let valPos = try dereference(field) let valPos = try dereference(field)
@@ -131,7 +131,7 @@ public struct TableVerifier {
} }
if let _key = keyPos, if let _key = keyPos,
let _val = valPos let _val = valPos
{ {
/// verifiying that the key is within the buffer /// verifiying that the key is within the buffer
try T.T.verify(&_verifier, at: _key, of: T.T.self) try T.T.verify(&_verifier, at: _key, of: T.T.self)
@@ -172,14 +172,14 @@ public struct TableVerifier {
unionKeyName: String, unionKeyName: String,
fieldName: String, fieldName: String,
required: Bool, required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
) throws where T: UnionEnum
where T: UnionEnum { {
let keyVectorPosition = try dereference(key) let keyVectorPosition = try dereference(key)
let offsetVectorPosition = try dereference(field) let offsetVectorPosition = try dereference(field)
if let keyPos = keyVectorPosition, if let keyPos = keyVectorPosition,
let valPos = offsetVectorPosition let valPos = offsetVectorPosition
{ {
try UnionVector<T>.verify( try UnionVector<T>.verify(
&_verifier, &_verifier,

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2024 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
public struct FlatbufferVector<
Element: FlatbuffersVectorInitializable
>: RandomAccessCollection {
public typealias Element = Element
public typealias Index = Int
private let bb: ByteBuffer
private let byteSize: Int
private let startPosition: Int32
public let count: Int
init(
bb: ByteBuffer,
startPosition: Int32,
count: Int,
byteSize: Int)
{
self.bb = bb
self.byteSize = byteSize
self.count = count
self.startPosition = startPosition
}
public var startIndex: Int {
0
}
public var endIndex: Int {
count
}
public var isEmpty: Bool {
count == 0
}
public subscript(position: Int) -> Element {
guard position < count else {
fatalError(
"Trying to read element at index \(position) in a vector of size \(count)")
}
let index = startPosition &+ Int32(position &* byteSize)
return Element.readFrom(byteBuffer: bb, index: Int(index))
}
public func index(after i: Int) -> Int {
guard i < count else { return count }
return i &+ 1
}
}
extension FlatbufferVector: Encodable where Element: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
for element in self {
try container.encode(element)
}
}
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2024 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
#if canImport(Common)
import Common
#endif
public protocol FlatbuffersVectorInitializable {
static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self
}
extension Scalar where Self: FlatbuffersVectorInitializable {
public static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self {
byteBuffer.read(def: Self.self, position: index)
}
}
extension NativeStruct where Self: FlatbuffersVectorInitializable {
public static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self {
byteBuffer.read(def: Self.self, position: index)
}
}
extension FlatBufferStruct {
public static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self {
Self.init(byteBuffer, o: Int32(index))
}
}
extension FlatBufferTable {
public static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self {
return Self.init(
byteBuffer,
o: Int32(index) &+ byteBuffer.read(def: Int32.self, position: index))
}
}
extension Optional: FlatbuffersVectorInitializable where Wrapped == String {
public static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self {
var index = Int32(index)
index &+= byteBuffer.read(def: Int32.self, position: Int(index))
let count = byteBuffer.read(def: Int32.self, position: Int(index))
let position = Int(index) &+ MemoryLayout<Int32>.size
return byteBuffer.readString(at: position, count: Int(count))
}
}
extension Enum where Self: FlatbuffersVectorInitializable {
public static func readFrom(byteBuffer: ByteBuffer, index: Int) -> Self {
Self
.init(rawValue: byteBuffer.read(def: Self.T.self, position: index)) ??
Self.min
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2024 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
public struct UnionFlatbufferVector {
private let bb: ByteBuffer
private let byteSize: Int
private let startPosition: Int32
public let count: Int
init(
bb: ByteBuffer,
startPosition: Int32,
count: Int,
byteSize: Int)
{
self.bb = bb
self.byteSize = byteSize
self.count = count
self.startPosition = startPosition
}
public var startIndex: Int {
0
}
public var endIndex: Int {
count
}
public var isEmpty: Bool {
count == 0
}
public subscript(
position: Int,
Type: FlatbuffersVectorInitializable
.Type) -> FlatbuffersVectorInitializable
{
guard position < count else {
fatalError(
"Trying to read element at index \(position) in a vector of size \(count)")
}
let index = startPosition &+ Int32(position &* byteSize)
return Type.readFrom(byteBuffer: bb, index: Int(index))
}
}

View File

@@ -41,8 +41,8 @@ public struct VerifierOptions {
maxDepth: UOffset = 64, maxDepth: UOffset = 64,
maxTableCount: UOffset = 1_000_000, maxTableCount: UOffset = 1_000_000,
maxApparentSize: UOffset = 1 << 31, maxApparentSize: UOffset = 1 << 31,
ignoreMissingNullTerminators: Bool = false ignoreMissingNullTerminators: Bool = false)
) { {
_maxDepth = maxDepth _maxDepth = maxDepth
_maxTableCount = maxTableCount _maxTableCount = maxTableCount
_maxApparentSize = maxApparentSize _maxApparentSize = maxApparentSize

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// Verifiable is a protocol all swift flatbuffers object should conform to, /// Verifiable is a protocol all swift flatbuffers object should conform to,
@@ -51,8 +51,8 @@ extension Verifiable {
@discardableResult @discardableResult
public static func verifyRange<T>( public static func verifyRange<T>(
_ verifier: inout Verifier, _ verifier: inout Verifier,
at position: Int, of type: T.Type at position: Int, of type: T.Type) throws -> (start: Int, count: Int)
) throws -> (start: Int, count: Int) { {
let len: UOffset = try verifier.getValue(at: position) let len: UOffset = try verifier.getValue(at: position)
let intLen = Int(len) let intLen = Int(len)
let start = Int(clamping: (position &+ MemoryLayout<Int32>.size).magnitude) let start = Int(clamping: (position &+ MemoryLayout<Int32>.size).magnitude)
@@ -74,8 +74,8 @@ extension Verifiable where Self: Scalar {
public static func verify<T>( public static func verify<T>(
_ verifier: inout Verifier, _ verifier: inout Verifier,
at position: Int, at position: Int,
of type: T.Type of type: T.Type) throws where T: Verifiable
) throws where T: Verifiable { {
try verifier.inBuffer(position: position, of: type.self) try verifier.inBuffer(position: position, of: type.self)
} }
} }
@@ -96,8 +96,8 @@ public enum ForwardOffset<U>: Verifiable where U: Verifiable {
public static func verify<T>( public static func verify<T>(
_ verifier: inout Verifier, _ verifier: inout Verifier,
at position: Int, at position: Int,
of type: T.Type of type: T.Type) throws where T: Verifiable
) throws where T: Verifiable { {
let offset: UOffset = try verifier.getValue(at: position) let offset: UOffset = try verifier.getValue(at: position)
let nextOffset = Int(clamping: (Int(offset) &+ position).magnitude) let nextOffset = Int(clamping: (Int(offset) &+ position).magnitude)
try U.verify(&verifier, at: nextOffset, of: U.self) try U.verify(&verifier, at: nextOffset, of: U.self)
@@ -120,8 +120,8 @@ public enum Vector<U, S>: Verifiable where U: Verifiable, S: Verifiable {
public static func verify<T>( public static func verify<T>(
_ verifier: inout Verifier, _ verifier: inout Verifier,
at position: Int, at position: Int,
of type: T.Type of type: T.Type) throws where T: Verifiable
) throws where T: Verifiable { {
/// checks if the next verification type S is equal to U of type forwardOffset /// checks if the next verification type S is equal to U of type forwardOffset
/// This had to be done since I couldnt find a solution for duplicate call functions /// This had to be done since I couldnt find a solution for duplicate call functions
/// A fix will be appreciated /// A fix will be appreciated
@@ -170,8 +170,8 @@ public enum UnionVector<S> where S: UnionEnum {
fieldPosition: Int, fieldPosition: Int,
unionKeyName: String, unionKeyName: String,
fieldName: String, fieldName: String,
completion: @escaping Completion completion: @escaping Completion) throws
) throws { {
/// Get offset for union key vectors and offset vectors /// Get offset for union key vectors and offset vectors
let keyOffset: UOffset = try verifier.getValue(at: keyPosition) let keyOffset: UOffset = try verifier.getValue(at: keyPosition)
let fieldOffset: UOffset = try verifier.getValue(at: fieldPosition) let fieldOffset: UOffset = try verifier.getValue(at: fieldPosition)

View File

@@ -53,8 +53,8 @@ public struct Verifier {
public init( public init(
buffer: inout ByteBuffer, buffer: inout ByteBuffer,
options: VerifierOptions = .init(), options: VerifierOptions = .init(),
checkAlignment: Bool = true checkAlignment: Bool = true) throws
) throws { {
guard buffer.capacity < FlatBufferMaxSize else { guard buffer.capacity < FlatBufferMaxSize else {
throw FlatbuffersErrors.exceedsMaxSizeAllowed throw FlatbuffersErrors.exceedsMaxSizeAllowed
} }
@@ -187,19 +187,19 @@ public struct Verifier {
if offset > 0 { if offset > 0 {
reportedOverflow = reportedOverflow =
_int32Position _int32Position
.subtractingReportingOverflow(offset.magnitude) .subtractingReportingOverflow(offset.magnitude)
} else { } else {
reportedOverflow = reportedOverflow =
_int32Position _int32Position
.addingReportingOverflow(offset.magnitude) .addingReportingOverflow(offset.magnitude)
} }
/// since `subtractingReportingOverflow` & `addingReportingOverflow` returns true, /// since `subtractingReportingOverflow` & `addingReportingOverflow` returns true,
/// if there is overflow we return failure /// if there is overflow we return failure
if reportedOverflow.overflow if reportedOverflow.overflow
|| reportedOverflow.partialValue || reportedOverflow.partialValue
> _buffer > _buffer
.capacity .capacity
{ {
throw FlatbuffersErrors.signedOffsetOutOfBounds( throw FlatbuffersErrors.signedOffsetOutOfBounds(
offset: Int(offset), offset: Int(offset),

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object /// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object
@@ -55,8 +55,8 @@ struct _InternalByteBuffer {
capacity: Int, capacity: Int,
writerSize: Int, writerSize: Int,
currentWritingIndex: Int, currentWritingIndex: Int,
alignment: Int alignment: Int)
) { {
let newData = UnsafeMutableRawPointer.allocate( let newData = UnsafeMutableRawPointer.allocate(
byteCount: capacity, byteCount: capacity,
alignment: alignment) alignment: alignment)
@@ -144,18 +144,18 @@ struct _InternalByteBuffer {
/// Adds a `ContiguousBytes` to buffer memory /// Adds a `ContiguousBytes` to buffer memory
/// - Parameter value: bytes to copy /// - Parameter value: bytes to copy
#if swift(>=5.0) && !os(WASI) #if swift(>=5.0) && !os(WASI)
@inline(__always) @inline(__always)
@usableFromInline @usableFromInline
mutating func push(bytes: ContiguousBytes) { mutating func push(bytes: ContiguousBytes) {
bytes.withUnsafeBytes { ptr in bytes.withUnsafeBytes { ptr in
ensureSpace(size: ptr.count) ensureSpace(size: ptr.count)
memcpy( memcpy(
_storage.memory.advanced(by: writerIndex &- ptr.count), _storage.memory.advanced(by: writerIndex &- ptr.count),
ptr.baseAddress!, ptr.baseAddress!,
ptr.count) ptr.count)
_writerSize = _writerSize &+ ptr.count _writerSize = _writerSize &+ ptr.count
}
} }
}
#endif #endif
/// Adds an object of type NativeStruct into the buffer /// Adds an object of type NativeStruct into the buffer
@@ -200,7 +200,8 @@ struct _InternalByteBuffer {
mutating func push(string str: String, len: Int) { mutating func push(string str: String, len: Int) {
ensureSpace(size: len) ensureSpace(size: len)
if str.utf8 if str.utf8
.withContiguousStorageIfAvailable({ self.push(bytes: $0, len: len) }) != nil .withContiguousStorageIfAvailable({ self.push(bytes: $0, len: len) }) !=
nil
{ {
} else { } else {
let utf8View = str.utf8 let utf8View = str.utf8
@@ -218,8 +219,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
mutating func push( mutating func push(
bytes: UnsafeBufferPointer<String.UTF8View.Element>, bytes: UnsafeBufferPointer<String.UTF8View.Element>,
len: Int len: Int) -> Bool
) -> Bool { {
memcpy( memcpy(
_storage.memory.advanced(by: writerIndex &- len), _storage.memory.advanced(by: writerIndex &- len),
bytes.baseAddress!, bytes.baseAddress!,
@@ -325,8 +326,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeBytes<T>( func withUnsafeBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try body( try body(
UnsafeRawBufferPointer( UnsafeRawBufferPointer(
start: _storage.memory, start: _storage.memory,
@@ -337,8 +338,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeSlicedBytes<T>( func withUnsafeSlicedBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try body( try body(
UnsafeRawBufferPointer( UnsafeRawBufferPointer(
start: _storage.memory.advanced(by: writerIndex), start: _storage.memory.advanced(by: writerIndex),
@@ -349,8 +350,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeRawPointer<T>( func withUnsafeRawPointer<T>(
_ body: (UnsafeMutableRawPointer) throws _ body: (UnsafeMutableRawPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try body(_storage.memory) try body(_storage.memory)
} }
@@ -358,8 +359,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func readWithUnsafeRawPointer<T>( func readWithUnsafeRawPointer<T>(
position: Int, position: Int,
_ body: (UnsafeRawPointer) throws -> T _ body: (UnsafeRawPointer) throws -> T) rethrows -> T
) rethrows -> T { {
try body(_storage.memory.advanced(by: position)) try body(_storage.memory.advanced(by: position))
} }
} }

View File

@@ -29,8 +29,8 @@ public struct ByteBuffer {
@usableFromInline @usableFromInline
enum Blob { enum Blob {
#if !os(WASI) #if !os(WASI)
case data(Data) case data(Data)
case bytes(ContiguousBytes) case bytes(ContiguousBytes)
#endif #endif
case byteBuffer(_InternalByteBuffer) case byteBuffer(_InternalByteBuffer)
@@ -96,16 +96,16 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeBytes<T>( func withUnsafeBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
switch retainedBlob { switch retainedBlob {
case .byteBuffer(let byteBuffer): case .byteBuffer(let byteBuffer):
return try byteBuffer.withUnsafeBytes(body) return try byteBuffer.withUnsafeBytes(body)
#if !os(WASI) #if !os(WASI)
case .data(let data): case .data(let data):
return try data.withUnsafeBytes(body) return try data.withUnsafeBytes(body)
case .bytes(let contiguousBytes): case .bytes(let contiguousBytes):
return try contiguousBytes.withUnsafeBytes(body) return try contiguousBytes.withUnsafeBytes(body)
#endif #endif
case .array(let array): case .array(let array):
return try array.withUnsafeBytes(body) return try array.withUnsafeBytes(body)
@@ -118,21 +118,21 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeRawPointer<T>( func withUnsafeRawPointer<T>(
_ body: (UnsafeMutableRawPointer) throws _ body: (UnsafeMutableRawPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
switch retainedBlob { switch retainedBlob {
case .byteBuffer(let byteBuffer): case .byteBuffer(let byteBuffer):
return try byteBuffer.withUnsafeRawPointer(body) return try byteBuffer.withUnsafeRawPointer(body)
#if !os(WASI) #if !os(WASI)
case .data(let data): case .data(let data):
return return
try data try data
.withUnsafeBytes { .withUnsafeBytes {
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!)) try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
} }
case .bytes(let contiguousBytes): case .bytes(let contiguousBytes):
return return
try contiguousBytes try contiguousBytes
.withUnsafeBytes { .withUnsafeBytes {
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!)) try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
} }
@@ -140,9 +140,9 @@ public struct ByteBuffer {
case .array(let array): case .array(let array):
return return
try array try array
.withUnsafeBytes { .withUnsafeBytes {
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!)) try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
} }
case .pointer(let ptr): case .pointer(let ptr):
return try body(ptr) return try body(ptr)
} }
@@ -152,20 +152,20 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func readWithUnsafeRawPointer<T>( func readWithUnsafeRawPointer<T>(
position: Int, position: Int,
_ body: (UnsafeRawPointer) throws -> T _ body: (UnsafeRawPointer) throws -> T) rethrows -> T
) rethrows -> T { {
switch retainedBlob { switch retainedBlob {
case .byteBuffer(let byteBuffer): case .byteBuffer(let byteBuffer):
return try byteBuffer.readWithUnsafeRawPointer(position: position, body) return try byteBuffer.readWithUnsafeRawPointer(position: position, body)
#if !os(WASI) #if !os(WASI)
case .data(let data): case .data(let data):
return try data.withUnsafeBytes { return try data.withUnsafeBytes {
try body($0.baseAddress!.advanced(by: position)) try body($0.baseAddress!.advanced(by: position))
} }
case .bytes(let contiguousBytes): case .bytes(let contiguousBytes):
return try contiguousBytes.withUnsafeBytes { return try contiguousBytes.withUnsafeBytes {
try body($0.baseAddress!.advanced(by: position)) try body($0.baseAddress!.advanced(by: position))
} }
#endif #endif
case .array(let array): case .array(let array):
return try array.withUnsafeBytes { return try array.withUnsafeBytes {
@@ -207,8 +207,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public init( public init(
copyingMemoryBound memory: UnsafeRawPointer, copyingMemoryBound memory: UnsafeRawPointer,
capacity: Int capacity: Int)
) { {
_storage = Storage(count: capacity) _storage = Storage(count: capacity)
_storage.copy(from: memory, count: capacity) _storage.copy(from: memory, count: capacity)
_readerIndex = capacity _readerIndex = capacity
@@ -226,29 +226,29 @@ public struct ByteBuffer {
} }
#if !os(WASI) #if !os(WASI)
/// Constructor that creates a Flatbuffer from the Swift Data type object /// Constructor that creates a Flatbuffer from the Swift Data type object
/// - Parameter /// - Parameter
/// - data: Swift data Object /// - data: Swift data Object
@inline(__always) @inline(__always)
public init(data: Data) { public init(data: Data) {
_storage = Storage(blob: .data(data), capacity: data.count) _storage = Storage(blob: .data(data), capacity: data.count)
_readerIndex = data.count _readerIndex = data.count
capacity = data.count capacity = data.count
} }
/// Constructor that creates a Flatbuffer object from a ContiguousBytes /// Constructor that creates a Flatbuffer object from a ContiguousBytes
/// - Parameters: /// - Parameters:
/// - contiguousBytes: Binary stripe to use as the buffer /// - contiguousBytes: Binary stripe to use as the buffer
/// - count: amount of readable bytes /// - count: amount of readable bytes
@inline(__always) @inline(__always)
public init<Bytes: ContiguousBytes>( public init<Bytes: ContiguousBytes>(
contiguousBytes: Bytes, contiguousBytes: Bytes,
count: Int count: Int)
) { {
_storage = Storage(blob: .bytes(contiguousBytes), capacity: count) _storage = Storage(blob: .bytes(contiguousBytes), capacity: count)
_readerIndex = count _readerIndex = count
capacity = count capacity = count
} }
#endif #endif
/// Constructor that creates a Flatbuffer from unsafe memory region without copying /// Constructor that creates a Flatbuffer from unsafe memory region without copying
@@ -260,8 +260,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public init( public init(
assumingMemoryBound memory: UnsafeMutableRawPointer, assumingMemoryBound memory: UnsafeMutableRawPointer,
capacity: Int capacity: Int)
) { {
_storage = Storage( _storage = Storage(
blob: .pointer(memory), blob: .pointer(memory),
capacity: capacity) capacity: capacity)
@@ -278,8 +278,8 @@ public struct ByteBuffer {
init( init(
blob: Storage.Blob, blob: Storage.Blob,
count: Int, count: Int,
removing removeBytes: Int removing removeBytes: Int)
) { {
_storage = Storage(blob: blob, capacity: count) _storage = Storage(blob: blob, capacity: count)
_readerIndex = removeBytes _readerIndex = removeBytes
capacity = count capacity = count
@@ -371,8 +371,8 @@ public struct ByteBuffer {
t3: T3.Type, t3: T3.Type,
t4: T4.Type, t4: T4.Type,
position: Int, position: Int,
byteWidth: UInt8 byteWidth: UInt8) -> T
) -> T { {
switch byteWidth { switch byteWidth {
case 1: case 1:
numericCast(read(def: T1.self, position: position)) numericCast(read(def: T1.self, position: position))
@@ -392,8 +392,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public func readSlice<T>( public func readSlice<T>(
index: Int, index: Int,
count: Int count: Int) -> [T]
) -> [T] { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
@@ -410,8 +410,8 @@ public struct ByteBuffer {
public func readString( public func readString(
at index: Int, at index: Int,
count: Int, count: Int,
type: String.Encoding type: String.Encoding) -> String?
) -> String? { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
@@ -432,8 +432,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public func readString( public func readString(
at index: Int, at index: Int,
count: Int count: Int) -> String?
) -> String? { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
@@ -451,8 +451,8 @@ public struct ByteBuffer {
public func withUnsafePointerToSlice<T>( public func withUnsafePointerToSlice<T>(
index: Int, index: Int,
count: Int, count: Int,
body: (UnsafeRawBufferPointer) throws -> T body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T
) rethrows -> T { {
assert( assert(
index + count <= capacity, index + count <= capacity,
"Reading out of bounds is illegal") "Reading out of bounds is illegal")
@@ -465,8 +465,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
public func withUnsafeBytes<T>( public func withUnsafeBytes<T>(
body: (UnsafeRawBufferPointer) throws body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try _storage.withUnsafeBytes(body) try _storage.withUnsafeBytes(body)
} }
@@ -474,8 +474,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeMutableRawPointer<T>( func withUnsafeMutableRawPointer<T>(
body: (UnsafeMutableRawPointer) throws body: (UnsafeMutableRawPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try _storage.withUnsafeRawPointer(body) try _storage.withUnsafeRawPointer(body)
} }
@@ -483,8 +483,8 @@ public struct ByteBuffer {
@inline(__always) @inline(__always)
func readWithUnsafeRawPointer<T>( func readWithUnsafeRawPointer<T>(
position: Int, position: Int,
_ body: (UnsafeRawPointer) throws -> T _ body: (UnsafeRawPointer) throws -> T) rethrows -> T
) rethrows -> T { {
try _storage.readWithUnsafeRawPointer(position: position, body) try _storage.readWithUnsafeRawPointer(position: position, body)
} }
} }

View File

@@ -46,8 +46,7 @@ public enum FlexBufferType: UInt64 {
@available( @available(
*, *,
deprecated, deprecated,
message: "use FBT_VECTOR or FBT_VECTOR_KEY instead." message: "use FBT_VECTOR or FBT_VECTOR_KEY instead.")
)
case vectorString = 15 case vectorString = 15
/// Typed tuples (no type table, no size field). /// Typed tuples (no type table, no size field).

View File

@@ -31,8 +31,8 @@ public struct FixedTypedVector: FlexBufferVector {
offset: Int, offset: Int,
byteWidth: UInt8, byteWidth: UInt8,
type: FlexBufferType, type: FlexBufferType,
count: Int count: Int)
) { {
self.byteBuffer = byteBuffer self.byteBuffer = byteBuffer
self.offset = offset self.offset = offset
self.byteWidth = byteWidth self.byteWidth = byteWidth

View File

@@ -39,14 +39,13 @@ public protocol FlexBufferContiguousBytes {
var count: Int { get } var count: Int { get }
func withUnsafeRawBufferPointer<Result>( func withUnsafeRawBufferPointer<Result>(
_ body: (UnsafeRawBufferPointer) throws -> Result _ body: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result
) rethrows -> Result
} }
extension FlexBufferContiguousBytes { extension FlexBufferContiguousBytes {
public func withUnsafeRawBufferPointer<Result>( public func withUnsafeRawBufferPointer<Result>(
_ body: (UnsafeRawBufferPointer) throws -> Result _ body: (UnsafeRawBufferPointer) throws -> Result) rethrows -> Result
) rethrows -> Result { {
try byteBuffer.withUnsafePointerToSlice( try byteBuffer.withUnsafePointerToSlice(
index: offset, index: offset,
count: count, count: count,

View File

@@ -58,8 +58,8 @@ public struct Reference {
byteBuffer: ByteBuffer, byteBuffer: ByteBuffer,
offset: Int, offset: Int,
parentWidth: UInt8, parentWidth: UInt8,
packedType: UInt8 packedType: UInt8)
) { {
guard let type = FlexBufferType(rawValue: UInt64(packedType >> 2)) else { guard let type = FlexBufferType(rawValue: UInt64(packedType >> 2)) else {
return nil return nil
} }
@@ -76,8 +76,8 @@ public struct Reference {
offset: Int, offset: Int,
parentWidth: UInt8, parentWidth: UInt8,
byteWidth: UInt8, byteWidth: UInt8,
type: FlexBufferType type: FlexBufferType)
) { {
self.byteBuffer = byteBuffer self.byteBuffer = byteBuffer
self.offset = offset self.offset = offset
self.parentWidth = parentWidth self.parentWidth = parentWidth
@@ -241,8 +241,7 @@ public struct Reference {
@inline(__always) @inline(__always)
public func withUnsafeRawPointer<Result>( public func withUnsafeRawPointer<Result>(
_ completion: (UnsafeRawPointer) throws _ completion: (UnsafeRawPointer) throws
-> Result -> Result)
)
rethrows -> Result? rethrows -> Result?
{ {
return try byteBuffer.readWithUnsafeRawPointer( return try byteBuffer.readWithUnsafeRawPointer(

View File

@@ -30,8 +30,8 @@ public struct TypedVector: FlexBufferVector {
byteBuffer: ByteBuffer, byteBuffer: ByteBuffer,
offset: Int, offset: Int,
byteWidth: UInt8, byteWidth: UInt8,
type: FlexBufferType type: FlexBufferType)
) { {
self.byteBuffer = byteBuffer self.byteBuffer = byteBuffer
self.offset = offset self.offset = offset
self.byteWidth = byteWidth self.byteWidth = byteWidth
@@ -54,8 +54,8 @@ public struct TypedVector: FlexBufferVector {
static func mapKeys( static func mapKeys(
byteBuffer: ByteBuffer, byteBuffer: ByteBuffer,
offset: Int, offset: Int,
byteWidth: UInt8 byteWidth: UInt8) -> TypedVector
) -> TypedVector { {
let prefixedFields = 3 let prefixedFields = 3
let keysOffset = offset &- (numericCast(byteWidth) &* prefixedFields) let keysOffset = offset &- (numericCast(byteWidth) &* prefixedFields)
@@ -88,8 +88,8 @@ extension TypedVector {
byteWidth) byteWidth)
return byteBuffer.readWithUnsafeRawPointer( return byteBuffer.readWithUnsafeRawPointer(
position: indirectoffset position: indirectoffset)
) { bufPointer in { bufPointer in
target.withCString { strPointer in target.withCString { strPointer in
Int(strcmp(bufPointer, strPointer)) Int(strcmp(bufPointer, strPointer))
} }

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
extension UInt64 { extension UInt64 {

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
public struct Value: Equatable { public struct Value: Equatable {

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
@inline(__always) @inline(__always)
@@ -128,13 +128,14 @@ func toFixedTypedVectorElementType(type: FlexBufferType)
type.rawValue type.rawValue
&- FlexBufferType.vectorInt2 &- FlexBufferType.vectorInt2
.rawValue) .rawValue)
let len: Int = numericCast(fixedType.dividedReportingOverflow(by: 3).partialValue &+ 2) let len: Int = numericCast(
fixedType.dividedReportingOverflow(by: 3)
.partialValue &+ 2)
return ( return (
FlexBufferType( FlexBufferType(
rawValue: (fixedType.quotientAndRemainder(dividingBy: 3).remainder) rawValue: (fixedType.quotientAndRemainder(dividingBy: 3).remainder)
&+ FlexBufferType.int.rawValue), &+ FlexBufferType.int.rawValue),
len len)
)
} }
// MARK: - Reader functions // MARK: - Reader functions
@@ -142,8 +143,8 @@ func toFixedTypedVectorElementType(type: FlexBufferType)
@inline(__always) @inline(__always)
func binarySearch( func binarySearch(
vector: TypedVector, vector: TypedVector,
target: String target: String) -> Int?
) -> Int? { {
var left = 0 var left = 0
var right = vector.count var right = vector.count

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
private let twentyFourBytes: Int = 24 private let twentyFourBytes: Int = 24
@@ -74,21 +74,21 @@ public struct FlexBuffersWriter {
} }
#if !os(WASI) #if !os(WASI)
/// Data representation of the buffer /// Data representation of the buffer
/// ///
/// Should only be used after ``finish(offset:addPrefix:)`` is called /// Should only be used after ``finish(offset:addPrefix:)`` is called
public var data: Data { public var data: Data {
assert(finished, "Data shouldn't be called before finish()") assert(finished, "Data shouldn't be called before finish()")
return _bb.withUnsafeSlicedBytes { ptr in return _bb.withUnsafeSlicedBytes { ptr in
var data = Data() var data = Data()
data.append( data.append(
ptr.baseAddress!.bindMemory( ptr.baseAddress!.bindMemory(
to: UInt8.self, to: UInt8.self,
capacity: ptr.count), capacity: ptr.count),
count: ptr.count) count: ptr.count)
return data return data
}
} }
}
#endif #endif
/// Resets the internal state. Automatically called before building a new flexbuffer. /// Resets the internal state. Automatically called before building a new flexbuffer.
@@ -139,8 +139,8 @@ public struct FlexBuffersWriter {
public mutating func endVector( public mutating func endVector(
start: Int, start: Int,
typed: Bool = false, typed: Bool = false,
fixed: Bool = false fixed: Bool = false) -> UInt64
) -> UInt64 { {
let vec = createVector( let vec = createVector(
start: start, start: start,
count: stack.count &- start, count: stack.count &- start,
@@ -162,7 +162,8 @@ public struct FlexBuffersWriter {
@discardableResult @discardableResult
@inline(__always) @inline(__always)
public mutating func create<T>(vector: [T], key: borrowing String) -> Int public mutating func create<T>(vector: [T], key: borrowing String) -> Int
where T: Scalar { where T: Scalar
{
add(key: key) add(key: key)
return create(vector: vector, fixed: false) return create(vector: vector, fixed: false)
} }
@@ -178,8 +179,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func createFixed<T>( public mutating func createFixed<T>(
vector: [T], vector: [T],
key: borrowing String key: borrowing String) -> Int where T: Scalar
) -> Int where T: Scalar { {
assert(vector.count >= 2 && vector.count <= 4) assert(vector.count >= 2 && vector.count <= 4)
add(key: key) add(key: key)
return create(vector: vector, fixed: true) return create(vector: vector, fixed: true)
@@ -301,8 +302,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func add( public mutating func add(
uint64 value: borrowing UInt64, uint64 value: borrowing UInt64,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
add(uint64: value) add(uint64: value)
} }
@@ -315,8 +316,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func indirect( public mutating func indirect(
uint64 val: borrowing UInt64, uint64 val: borrowing UInt64,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
indirect(uint64: val) indirect(uint64: val)
} }
@@ -324,8 +325,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func indirect( public mutating func indirect(
uint val: borrowing UInt, uint val: borrowing UInt,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
indirect(uint64: numericCast(val)) indirect(uint64: numericCast(val))
} }
@@ -384,8 +385,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func add( public mutating func add(
int64 value: borrowing Int64, int64 value: borrowing Int64,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
add(int64: value) add(int64: value)
} }
@@ -398,8 +399,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func indirect( public mutating func indirect(
int64 val: borrowing Int64, int64 val: borrowing Int64,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
indirect(int64: val) indirect(int64: val)
} }
@@ -407,8 +408,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func indirect( public mutating func indirect(
int val: borrowing Int, int val: borrowing Int,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
indirect(int64: numericCast(val)) indirect(int64: numericCast(val))
} }
@@ -423,8 +424,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func add( public mutating func add(
float32 value: borrowing Float32, float32 value: borrowing Float32,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
add(float32: value) add(float32: value)
} }
@@ -437,8 +438,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func indirect( public mutating func indirect(
float32 val: borrowing Float32, float32 val: borrowing Float32,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
indirect(float32: val) indirect(float32: val)
} }
@@ -451,8 +452,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func add( public mutating func add(
double value: borrowing Double, double value: borrowing Double,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
add(double: value) add(double: value)
} }
@@ -465,8 +466,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func indirect( public mutating func indirect(
double val: borrowing Double, double val: borrowing Double,
key: borrowing String key: borrowing String)
) { {
add(key: key) add(key: key)
indirect(double: val) indirect(double: val)
} }
@@ -488,8 +489,8 @@ public struct FlexBuffersWriter {
@inline(__always) @inline(__always)
public mutating func add<T>( public mutating func add<T>(
blob: borrowing T, blob: borrowing T,
length l: Int length l: Int) -> UInt where T: ContiguousBytes
) -> UInt where T: ContiguousBytes { {
storeBlob(blob, len: l, type: .blob) storeBlob(blob, len: l, type: .blob)
} }
@@ -498,8 +499,8 @@ public struct FlexBuffersWriter {
public mutating func add<T>( public mutating func add<T>(
blob: borrowing T, blob: borrowing T,
key: borrowing String, key: borrowing String,
length l: Int length l: Int) -> UInt where T: ContiguousBytes
) -> UInt where T: ContiguousBytes { {
add(key: key) add(key: key)
return storeBlob(blob, len: l, type: .blob) return storeBlob(blob, len: l, type: .blob)
} }
@@ -540,8 +541,8 @@ public struct FlexBuffersWriter {
mutating func pushIndirect<T>( mutating func pushIndirect<T>(
value: T, value: T,
type: FlexBufferType, type: FlexBufferType,
bitWidth: BitWidth bitWidth: BitWidth)
) { {
let byteWidth = align(width: bitWidth) let byteWidth = align(width: bitWidth)
let iloc = writerIndex let iloc = writerIndex
_bb.ensureSpace(size: byteWidth) _bb.ensureSpace(size: byteWidth)
@@ -618,8 +619,8 @@ public struct FlexBuffersWriter {
mutating func storeBlob<T>( mutating func storeBlob<T>(
_ bytes: T, _ bytes: T,
len: Int, len: Int,
type: FlexBufferType type: FlexBufferType) -> UInt where T: ContiguousBytes
) -> UInt where T: ContiguousBytes { {
return bytes.withUnsafeBytes { return bytes.withUnsafeBytes {
storeBlob(pointer: $0.baseAddress!, len: len, type: type) storeBlob(pointer: $0.baseAddress!, len: len, type: type)
} }
@@ -631,8 +632,8 @@ public struct FlexBuffersWriter {
pointer: borrowing UnsafeRawPointer, pointer: borrowing UnsafeRawPointer,
len: Int, len: Int,
trailing: Int = 0, trailing: Int = 0,
type: FlexBufferType type: FlexBufferType) -> UInt
) -> UInt { {
_bb.ensureSpace(size: len &+ trailing) _bb.ensureSpace(size: len &+ trailing)
let bitWidth = widthU(numericCast(len)) let bitWidth = widthU(numericCast(len))
@@ -655,7 +656,8 @@ public struct FlexBuffersWriter {
@discardableResult @discardableResult
@usableFromInline @usableFromInline
mutating func create<T>(vector: [T], fixed: Bool) -> Int mutating func create<T>(vector: [T], fixed: Bool) -> Int
where T: Scalar { where T: Scalar
{
let length: UInt64 = numericCast(vector.count) let length: UInt64 = numericCast(vector.count)
let vectorType = getScalarType(type: T.self) let vectorType = getScalarType(type: T.self)
let byteWidth = MemoryLayout<T>.size let byteWidth = MemoryLayout<T>.size
@@ -691,8 +693,8 @@ public struct FlexBuffersWriter {
step: Int, step: Int,
typed: Bool, typed: Bool,
fixed: Bool, fixed: Bool,
keys: Value? = nil keys: Value? = nil) -> Value
) -> Value { {
assert( assert(
!fixed || typed, !fixed || typed,
"Typed false and fixed true is a combination not supported currently") "Typed false and fixed true is a combination not supported currently")
@@ -857,8 +859,8 @@ extension FlexBuffersWriter {
@discardableResult @discardableResult
public mutating func vector( public mutating func vector(
key: String, key: String,
_ closure: FlexBuffersWriterBuilder _ closure: FlexBuffersWriterBuilder) -> UInt64
) -> UInt64 { {
let start = startVector(key: key) let start = startVector(key: key)
closure(&self) closure(&self)
return endVector(start: start) return endVector(start: start)
@@ -879,8 +881,8 @@ extension FlexBuffersWriter {
@discardableResult @discardableResult
public mutating func map( public mutating func map(
key: String, key: String,
_ closure: FlexBuffersWriterBuilder _ closure: FlexBuffersWriterBuilder) -> UInt64
) -> UInt64 { {
let start = startMap(key: key) let start = startMap(key: key)
closure(&self) closure(&self)
return endMap(start: start) return endMap(start: start)

View File

@@ -17,7 +17,7 @@
import Foundation import Foundation
#if canImport(Common) #if canImport(Common)
import Common import Common
#endif #endif
/// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object /// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object
@@ -55,8 +55,8 @@ struct _InternalByteBuffer {
func reallocate( func reallocate(
capacity: Int, capacity: Int,
writerSize: Int, writerSize: Int,
alignment: Int alignment: Int)
) { {
let newData = UnsafeMutableRawPointer.allocate( let newData = UnsafeMutableRawPointer.allocate(
byteCount: capacity, byteCount: capacity,
alignment: alignment) alignment: alignment)
@@ -135,18 +135,17 @@ struct _InternalByteBuffer {
_storage.reallocate( _storage.reallocate(
capacity: capacity, capacity: capacity,
writerSize: writerIndex, writerSize: writerIndex,
alignment: alignment alignment: alignment)
)
} }
@inline(__always) @inline(__always)
mutating func addPadding(bytes: Int) { mutating func addPadding(bytes: Int) {
writerIndex = writerIndex =
writerIndex writerIndex
&+ numericCast( &+ numericCast(
padding( padding(
bufSize: numericCast(writerIndex), bufSize: numericCast(writerIndex),
elementSize: numericCast(bytes))) elementSize: numericCast(bytes)))
ensureSpace(size: writerIndex) ensureSpace(size: writerIndex)
} }
@@ -174,8 +173,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeBytes<T>( func withUnsafeBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try body( try body(
UnsafeRawBufferPointer( UnsafeRawBufferPointer(
start: _storage.memory, start: _storage.memory,
@@ -186,8 +185,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeSlicedBytes<T>( func withUnsafeSlicedBytes<T>(
_ body: (UnsafeRawBufferPointer) throws _ body: (UnsafeRawBufferPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try body( try body(
UnsafeRawBufferPointer( UnsafeRawBufferPointer(
start: _storage.memory, start: _storage.memory,
@@ -198,8 +197,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func withUnsafeRawPointer<T>( func withUnsafeRawPointer<T>(
_ body: (UnsafeMutableRawPointer) throws _ body: (UnsafeMutableRawPointer) throws
-> T -> T) rethrows -> T
) rethrows -> T { {
try body(_storage.memory) try body(_storage.memory)
} }
@@ -207,8 +206,8 @@ struct _InternalByteBuffer {
@inline(__always) @inline(__always)
func readWithUnsafeRawPointer<T>( func readWithUnsafeRawPointer<T>(
position: Int, position: Int,
_ body: (UnsafeRawPointer) throws -> T _ body: (UnsafeRawPointer) throws -> T) rethrows -> T
) rethrows -> T { {
try body(_storage.memory.advanced(by: position)) try body(_storage.memory.advanced(by: position))
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers import FlatBuffers
public struct Property: NativeStruct, Verifiable, FlatbuffersInitializable, NativeObject { public struct Property: NativeStruct, FlatbuffersVectorInitializable, Verifiable, FlatbuffersInitializable, NativeObject {
static func validateVersion() { FlatBuffersVersion_25_9_23() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }

View File

@@ -9,7 +9,7 @@ import Common
import FlatBuffers import FlatBuffers
/// Composite components of Monster color. /// 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 typealias T = UInt8
public static var byteSize: Int { return MemoryLayout<UInt8>.size } public static var byteSize: Int { return MemoryLayout<UInt8>.size }
public var value: UInt8 { return self.rawValue } 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 typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size } public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue } 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 typealias T = UInt64
public static var byteSize: Int { return MemoryLayout<UInt64>.size } public static var byteSize: Int { return MemoryLayout<UInt64>.size }
public var value: UInt64 { return self.rawValue } 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 typealias T = UInt8
public init?(value: T) { 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 typealias T = UInt8
public init?(value: T) { 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 typealias T = UInt8
public init?(value: T) { 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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) } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
internal var __buffer: ByteBuffer! { return _accessor.bb } 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) } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1111,7 +1111,7 @@ public class MyGame_Example_ReferrableT: NativeObject {
} }
/// an example documentation comment: "monster object" /// 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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) } @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 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 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 inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
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 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 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 } 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) } @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 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 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 test4: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
public var test4Count: Int32 { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var mutableTest4: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
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 withUnsafePointerToTest4<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test4.v, body: body) }
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 var testarrayofstring: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring.v, byteSize: 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) }
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
/// multiline too /// multiline too
public var hasTestarrayoftables: Bool { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? false : true } public var testarrayoftables: FlatbufferVector<MyGame_Example_Monster> { return _accessor.vector(at: VTOFFSET.testarrayoftables.v, byteSize: 4) }
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 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 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 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 testnestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testnestedflatbuffer.v, byteSize: 1) }
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 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 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 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) } 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) } @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) } @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) } 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) } @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 testarrayofbools: FlatbufferVector<Bool> { return _accessor.vector(at: VTOFFSET.testarrayofbools.v, byteSize: 1) }
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 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 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) } 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) } @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) } 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) } @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) } 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) } @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 testarrayofstring2: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring2.v, byteSize: 4) }
public var testarrayofstring2Count: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var testarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
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 mutableTestarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability_Mutable> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
public var hasTestarrayofsortedstruct: Bool { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? false : true } public func withUnsafePointerToTestarrayofsortedstruct<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofsortedstruct.v, body: body) }
public var testarrayofsortedstructCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var flex: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.flex.v, byteSize: 1) }
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 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 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 func withUnsafePointerToFlex<T>(_ body: (UnsafeRawBufferPointer, Int) 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 test5: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
public var test5Count: Int32 { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var mutableTest5: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
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 withUnsafePointerToTest5<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test5.v, body: body) }
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 var vectorOfLongs: FlatbufferVector<Int64> { return _accessor.vector(at: VTOFFSET.vectorOfLongs.v, byteSize: 8) }
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 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 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 func withUnsafePointerToVectorOfLongs<T>(_ body: (UnsafeRawBufferPointer, Int) 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 vectorOfDoubles: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vectorOfDoubles.v, byteSize: 8) }
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 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 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 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 vectorOfReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfReferrables.v, byteSize: 4) }
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 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 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) } 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) } @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 vectorOfWeakReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfWeakReferences.v, byteSize: 8) }
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 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 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 func withUnsafePointerToVectorOfWeakReferences<T>(_ body: (UnsafeRawBufferPointer, Int) 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 vectorOfStrongReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfStrongReferrables.v, byteSize: 4) }
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 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 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) } 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) } @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 vectorOfCoOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfCoOwningReferences.v, byteSize: 8) }
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 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 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) } 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) } @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 vectorOfNonOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfNonOwningReferences.v, byteSize: 8) }
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 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 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 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 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 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 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 vectorOfEnums: FlatbufferVector<MyGame_Example_Color> { return _accessor.vector(at: VTOFFSET.vectorOfEnums.v, byteSize: 1) }
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 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_ } 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) } @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 testrequirednestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testrequirednestedflatbuffer.v, byteSize: 1) }
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 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 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 func withUnsafePointerToTestrequirednestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer, Int) 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 scalarKeySortedTables: FlatbufferVector<MyGame_Example_Stat> { return _accessor.vector(at: VTOFFSET.scalarKeySortedTables.v, byteSize: 4) }
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 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 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 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) } 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 __inventory = builder.createVector(obj.inventory)
let __test = obj.test?.pack(builder: &builder) ?? Offset() let __test = obj.test?.pack(builder: &builder) ?? Offset()
MyGame_Example_Monster.startVectorOfTest4(obj.test4.count, in: &builder) MyGame_Example_Monster.startVectorOfTest4(obj.test4.count, in: &builder)
for i in obj.test4 { for val in obj.test4 {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __test4 = builder.endVector(len: obj.test4.count) let __test4 = builder.endVector(len: obj.test4.count)
let __testarrayofstring = builder.createVector(ofStrings: obj.testarrayofstring.compactMap({ $0 }) ) 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 __testarrayofbools = builder.createVector(obj.testarrayofbools)
let __testarrayofstring2 = builder.createVector(ofStrings: obj.testarrayofstring2.compactMap({ $0 }) ) let __testarrayofstring2 = builder.createVector(ofStrings: obj.testarrayofstring2.compactMap({ $0 }) )
MyGame_Example_Monster.startVectorOfTestarrayofsortedstruct(obj.testarrayofsortedstruct.count, in: &builder) MyGame_Example_Monster.startVectorOfTestarrayofsortedstruct(obj.testarrayofsortedstruct.count, in: &builder)
for i in obj.testarrayofsortedstruct { for val in obj.testarrayofsortedstruct {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __testarrayofsortedstruct = builder.endVector(len: obj.testarrayofsortedstruct.count) let __testarrayofsortedstruct = builder.endVector(len: obj.testarrayofsortedstruct.count)
let __flex = builder.createVector(obj.flex) let __flex = builder.createVector(obj.flex)
MyGame_Example_Monster.startVectorOfTest5(obj.test5.count, in: &builder) MyGame_Example_Monster.startVectorOfTest5(obj.test5.count, in: &builder)
for i in obj.test5 { for val in obj.test5 {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __test5 = builder.endVector(len: obj.test5.count) let __test5 = builder.endVector(len: obj.test5.count)
let __vectorOfLongs = builder.createVector(obj.vectorOfLongs) let __vectorOfLongs = builder.createVector(obj.vectorOfLongs)
@@ -1904,9 +1851,7 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(hp, forKey: .hp) try container.encodeIfPresent(hp, forKey: .hp)
} }
try container.encodeIfPresent(name, forKey: .name) try container.encodeIfPresent(name, forKey: .name)
if inventoryCount > 0 { try container.encodeIfPresent(inventory, forKey: .inventory)
try container.encodeIfPresent(inventory, forKey: .inventory)
}
if color != .blue { if color != .blue {
try container.encodeIfPresent(color, forKey: .color) try container.encodeIfPresent(color, forKey: .color)
} }
@@ -1925,31 +1870,11 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .test) try container.encodeIfPresent(_v, forKey: .test)
default: break; default: break;
} }
if test4Count > 0 { try container.encodeIfPresent(test4, forKey: .test4)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .test4) try container.encodeIfPresent(testarrayofstring, forKey: .testarrayofstring)
for index in 0..<test4Count { try container.encodeIfPresent(testarrayoftables, forKey: .testarrayoftables)
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(enemy, forKey: .enemy) 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) try container.encodeIfPresent(testempty, forKey: .testempty)
if testbool != false { if testbool != false {
try container.encodeIfPresent(testbool, forKey: .testbool) try container.encodeIfPresent(testbool, forKey: .testbool)
@@ -1978,9 +1903,7 @@ extension MyGame_Example_Monster: Encodable {
if testhashu64Fnv1a != 0 { if testhashu64Fnv1a != 0 {
try container.encodeIfPresent(testhashu64Fnv1a, forKey: .testhashu64Fnv1a) 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 { if testf != 3.14159 {
try container.encodeIfPresent(testf, forKey: .testf) try container.encodeIfPresent(testf, forKey: .testf)
} }
@@ -1990,69 +1913,27 @@ extension MyGame_Example_Monster: Encodable {
if testf3 != 0.0 { if testf3 != 0.0 {
try container.encodeIfPresent(testf3, forKey: .testf3) try container.encodeIfPresent(testf3, forKey: .testf3)
} }
if testarrayofstring2Count > 0 { try container.encodeIfPresent(testarrayofstring2, forKey: .testarrayofstring2)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofstring2) try container.encodeIfPresent(testarrayofsortedstruct, forKey: .testarrayofsortedstruct)
for index in 0..<testarrayofstring2Count { try container.encodeIfPresent(flex, forKey: .flex)
guard let type = testarrayofstring2(at: index) else { continue } try container.encodeIfPresent(test5, forKey: .test5)
try contentEncoder.encode(type) try container.encodeIfPresent(vectorOfLongs, forKey: .vectorOfLongs)
} try container.encodeIfPresent(vectorOfDoubles, forKey: .vectorOfDoubles)
}
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(parentNamespaceTest, forKey: .parentNamespaceTest) try container.encodeIfPresent(parentNamespaceTest, forKey: .parentNamespaceTest)
if vectorOfReferrablesCount > 0 { try container.encodeIfPresent(vectorOfReferrables, forKey: .vectorOfReferrables)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfReferrables)
for index in 0..<vectorOfReferrablesCount {
guard let type = vectorOfReferrables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if singleWeakReference != 0 { if singleWeakReference != 0 {
try container.encodeIfPresent(singleWeakReference, forKey: .singleWeakReference) try container.encodeIfPresent(singleWeakReference, forKey: .singleWeakReference)
} }
if vectorOfWeakReferencesCount > 0 { try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences)
try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences) try container.encodeIfPresent(vectorOfStrongReferrables, forKey: .vectorOfStrongReferrables)
}
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)
}
}
if coOwningReference != 0 { if coOwningReference != 0 {
try container.encodeIfPresent(coOwningReference, forKey: .coOwningReference) try container.encodeIfPresent(coOwningReference, forKey: .coOwningReference)
} }
if vectorOfCoOwningReferencesCount > 0 { try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
}
if nonOwningReference != 0 { if nonOwningReference != 0 {
try container.encodeIfPresent(nonOwningReference, forKey: .nonOwningReference) try container.encodeIfPresent(nonOwningReference, forKey: .nonOwningReference)
} }
if vectorOfNonOwningReferencesCount > 0 { try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
}
if anyUniqueType != .none_ { if anyUniqueType != .none_ {
try container.encodeIfPresent(anyUniqueType, forKey: .anyUniqueType) try container.encodeIfPresent(anyUniqueType, forKey: .anyUniqueType)
} }
@@ -2083,26 +1964,12 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .anyAmbiguous) try container.encodeIfPresent(_v, forKey: .anyAmbiguous)
default: break; default: break;
} }
if vectorOfEnumsCount > 0 { try container.encodeIfPresent(vectorOfEnums, forKey: .vectorOfEnums)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfEnums)
for index in 0..<vectorOfEnumsCount {
guard let type = vectorOfEnums(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if signedEnum != .none_ { if signedEnum != .none_ {
try container.encodeIfPresent(signedEnum, forKey: .signedEnum) try container.encodeIfPresent(signedEnum, forKey: .signedEnum)
} }
if testrequirednestedflatbufferCount > 0 { try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer)
try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer) try container.encodeIfPresent(scalarKeySortedTables, forKey: .scalarKeySortedTables)
}
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(nativeInline, forKey: .nativeInline) try container.encodeIfPresent(nativeInline, forKey: .nativeInline)
if longEnumNonEnumDefault != .longone { if longEnumNonEnumDefault != .longone {
try container.encodeIfPresent(longEnumNonEnumDefault, forKey: .longEnumNonEnumDefault) try container.encodeIfPresent(longEnumNonEnumDefault, forKey: .longEnumNonEnumDefault)
@@ -2146,7 +2013,7 @@ public class MyGame_Example_MonsterT: NativeObject {
public var inventory: [UInt8] public var inventory: [UInt8]
public var color: MyGame_Example_Color public var color: MyGame_Example_Color
public var test: MyGame_Example_Any_Union? 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 testarrayofstring: [String?]
public var testarrayoftables: [MyGame_Example_MonsterT?] public var testarrayoftables: [MyGame_Example_MonsterT?]
public var enemy: 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 testf2: Float32
public var testf3: Float32 public var testf3: Float32
public var testarrayofstring2: [String?] public var testarrayofstring2: [String?]
public var testarrayofsortedstruct: [MyGame_Example_Ability?] public var testarrayofsortedstruct: [MyGame_Example_Ability]
public var flex: [UInt8] public var flex: [UInt8]
public var test5: [MyGame_Example_Test?] public var test5: [MyGame_Example_Test]
public var vectorOfLongs: [Int64] public var vectorOfLongs: [Int64]
public var vectorOfDoubles: [Double] public var vectorOfDoubles: [Double]
public var parentNamespaceTest: MyGame_InParentNamespaceT? public var parentNamespaceTest: MyGame_InParentNamespaceT?
@@ -2204,9 +2071,7 @@ public class MyGame_Example_MonsterT: NativeObject {
hp = _t.hp hp = _t.hp
name = _t.name name = _t.name
inventory = [] inventory = []
for index in 0..<_t.inventoryCount { inventory.append(contentsOf: _t.inventory)
inventory.append(_t.inventory(at: index))
}
color = _t.color color = _t.color
switch _t.testType { switch _t.testType {
case .monster: case .monster:
@@ -2221,24 +2086,17 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break default: break
} }
test4 = [] test4 = []
for index in 0..<_t.test4Count { test4.append(contentsOf: _t.test4)
test4.append(_t.test4(at: index))
}
testarrayofstring = [] testarrayofstring = []
for index in 0..<_t.testarrayofstringCount { testarrayofstring.append(contentsOf: _t.testarrayofstring)
testarrayofstring.append(_t.testarrayofstring(at: index))
}
testarrayoftables = [] testarrayoftables = []
for index in 0..<_t.testarrayoftablesCount { for var val in _t.testarrayoftables{
var __v_ = _t.testarrayoftables(at: index) testarrayoftables.append(val.unpack())
testarrayoftables.append(__v_?.unpack())
} }
var __enemy = _t.enemy var __enemy = _t.enemy
enemy = __enemy?.unpack() enemy = __enemy?.unpack()
testnestedflatbuffer = [] testnestedflatbuffer = []
for index in 0..<_t.testnestedflatbufferCount { testnestedflatbuffer.append(contentsOf: _t.testnestedflatbuffer)
testnestedflatbuffer.append(_t.testnestedflatbuffer(at: index))
}
var __testempty = _t.testempty var __testempty = _t.testempty
testempty = __testempty?.unpack() testempty = __testempty?.unpack()
testbool = _t.testbool testbool = _t.testbool
@@ -2251,63 +2109,41 @@ public class MyGame_Example_MonsterT: NativeObject {
testhashs64Fnv1a = _t.testhashs64Fnv1a testhashs64Fnv1a = _t.testhashs64Fnv1a
testhashu64Fnv1a = _t.testhashu64Fnv1a testhashu64Fnv1a = _t.testhashu64Fnv1a
testarrayofbools = [] testarrayofbools = []
for index in 0..<_t.testarrayofboolsCount { testarrayofbools.append(contentsOf: _t.testarrayofbools)
testarrayofbools.append(_t.testarrayofbools(at: index))
}
testf = _t.testf testf = _t.testf
testf2 = _t.testf2 testf2 = _t.testf2
testf3 = _t.testf3 testf3 = _t.testf3
testarrayofstring2 = [] testarrayofstring2 = []
for index in 0..<_t.testarrayofstring2Count { testarrayofstring2.append(contentsOf: _t.testarrayofstring2)
testarrayofstring2.append(_t.testarrayofstring2(at: index))
}
testarrayofsortedstruct = [] testarrayofsortedstruct = []
for index in 0..<_t.testarrayofsortedstructCount { testarrayofsortedstruct.append(contentsOf: _t.testarrayofsortedstruct)
testarrayofsortedstruct.append(_t.testarrayofsortedstruct(at: index))
}
flex = [] flex = []
for index in 0..<_t.flexCount { flex.append(contentsOf: _t.flex)
flex.append(_t.flex(at: index))
}
test5 = [] test5 = []
for index in 0..<_t.test5Count { test5.append(contentsOf: _t.test5)
test5.append(_t.test5(at: index))
}
vectorOfLongs = [] vectorOfLongs = []
for index in 0..<_t.vectorOfLongsCount { vectorOfLongs.append(contentsOf: _t.vectorOfLongs)
vectorOfLongs.append(_t.vectorOfLongs(at: index))
}
vectorOfDoubles = [] vectorOfDoubles = []
for index in 0..<_t.vectorOfDoublesCount { vectorOfDoubles.append(contentsOf: _t.vectorOfDoubles)
vectorOfDoubles.append(_t.vectorOfDoubles(at: index))
}
var __parentNamespaceTest = _t.parentNamespaceTest var __parentNamespaceTest = _t.parentNamespaceTest
parentNamespaceTest = __parentNamespaceTest?.unpack() parentNamespaceTest = __parentNamespaceTest?.unpack()
vectorOfReferrables = [] vectorOfReferrables = []
for index in 0..<_t.vectorOfReferrablesCount { for var val in _t.vectorOfReferrables{
var __v_ = _t.vectorOfReferrables(at: index) vectorOfReferrables.append(val.unpack())
vectorOfReferrables.append(__v_?.unpack())
} }
singleWeakReference = _t.singleWeakReference singleWeakReference = _t.singleWeakReference
vectorOfWeakReferences = [] vectorOfWeakReferences = []
for index in 0..<_t.vectorOfWeakReferencesCount { vectorOfWeakReferences.append(contentsOf: _t.vectorOfWeakReferences)
vectorOfWeakReferences.append(_t.vectorOfWeakReferences(at: index))
}
vectorOfStrongReferrables = [] vectorOfStrongReferrables = []
for index in 0..<_t.vectorOfStrongReferrablesCount { for var val in _t.vectorOfStrongReferrables{
var __v_ = _t.vectorOfStrongReferrables(at: index) vectorOfStrongReferrables.append(val.unpack())
vectorOfStrongReferrables.append(__v_?.unpack())
} }
coOwningReference = _t.coOwningReference coOwningReference = _t.coOwningReference
vectorOfCoOwningReferences = [] vectorOfCoOwningReferences = []
for index in 0..<_t.vectorOfCoOwningReferencesCount { vectorOfCoOwningReferences.append(contentsOf: _t.vectorOfCoOwningReferences)
vectorOfCoOwningReferences.append(_t.vectorOfCoOwningReferences(at: index))
}
nonOwningReference = _t.nonOwningReference nonOwningReference = _t.nonOwningReference
vectorOfNonOwningReferences = [] vectorOfNonOwningReferences = []
for index in 0..<_t.vectorOfNonOwningReferencesCount { vectorOfNonOwningReferences.append(contentsOf: _t.vectorOfNonOwningReferences)
vectorOfNonOwningReferences.append(_t.vectorOfNonOwningReferences(at: index))
}
switch _t.anyUniqueType { switch _t.anyUniqueType {
case .m: case .m:
var _v = _t.anyUnique(type: MyGame_Example_Monster.self) var _v = _t.anyUnique(type: MyGame_Example_Monster.self)
@@ -2333,18 +2169,13 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break default: break
} }
vectorOfEnums = [] vectorOfEnums = []
for index in 0..<_t.vectorOfEnumsCount { vectorOfEnums.append(contentsOf: _t.vectorOfEnums)
vectorOfEnums.append(_t.vectorOfEnums(at: index)!)
}
signedEnum = _t.signedEnum signedEnum = _t.signedEnum
testrequirednestedflatbuffer = [] testrequirednestedflatbuffer = []
for index in 0..<_t.testrequirednestedflatbufferCount { testrequirednestedflatbuffer.append(contentsOf: _t.testrequirednestedflatbuffer)
testrequirednestedflatbuffer.append(_t.testrequirednestedflatbuffer(at: index))
}
scalarKeySortedTables = [] scalarKeySortedTables = []
for index in 0..<_t.scalarKeySortedTablesCount { for var val in _t.scalarKeySortedTables{
var __v_ = _t.scalarKeySortedTables(at: index) scalarKeySortedTables.append(val.unpack())
scalarKeySortedTables.append(__v_?.unpack())
} }
nativeInline = _t.nativeInline nativeInline = _t.nativeInline
longEnumNonEnumDefault = _t.longEnumNonEnumDefault 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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) } @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) } 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) } @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 v8: FlatbufferVector<Int8> { return _accessor.vector(at: VTOFFSET.v8.v, byteSize: 1) }
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 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 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 func withUnsafePointerToV8<T>(_ body: (UnsafeRawBufferPointer, Int) 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 vf64: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vf64.v, byteSize: 8) }
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 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 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 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(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) } 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 { if f64 != 0.0 {
try container.encodeIfPresent(f64, forKey: .f64) try container.encodeIfPresent(f64, forKey: .f64)
} }
if v8Count > 0 { try container.encodeIfPresent(v8, forKey: .v8)
try container.encodeIfPresent(v8, forKey: .v8) try container.encodeIfPresent(vf64, forKey: .vf64)
}
if vf64Count > 0 {
try container.encodeIfPresent(vf64, forKey: .vf64)
}
} }
} }
@@ -2655,13 +2476,9 @@ public class MyGame_Example_TypeAliasesT: NativeObject {
f32 = _t.f32 f32 = _t.f32
f64 = _t.f64 f64 = _t.f64
v8 = [] v8 = []
for index in 0..<_t.v8Count { v8.append(contentsOf: _t.v8)
v8.append(_t.v8(at: index))
}
vf64 = [] vf64 = []
for index in 0..<_t.vf64Count { vf64.append(contentsOf: _t.vf64)
vf64.append(_t.vf64(at: index))
}
} }
public init() { public init() {

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers import FlatBuffers
public enum Character: UInt8, UnionEnum { public enum Character: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8 public typealias T = UInt8
public init?(value: T) { 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 typealias T = UInt8
public init?(value: T) { 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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 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 charactersType: FlatbufferVector<Character> { return _accessor.vector(at: VTOFFSET.charactersType.v, byteSize: 1) }
public var charactersTypeCount: Int32 { let o = _accessor.offset(VTOFFSET.charactersType.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var characters: UnionFlatbufferVector { return _accessor.unionVector(at: VTOFFSET.characters.v, byteSize: 4) }
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 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 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 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) } 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) try container.encodeIfPresent(_v, forKey: .mainCharacter)
default: break; default: break;
} }
if charactersCount > 0 { try container.encode(charactersType, forKey: .charactersType)
var enumsEncoder = container.nestedUnkeyedContainer(forKey: .charactersType) var contentEncoder = container.nestedUnkeyedContainer(forKey: .characters)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .characters) let _characters = charactersType
for index in 0..<charactersCount { for index in _characters.startIndex..<_characters.endIndex {
guard let type = charactersType(at: index) else { continue } switch _characters[index] {
try enumsEncoder.encode(type) case .mulan:
switch type { let _v = characters(at: Int32(index), type: Attacker.self)
case .mulan: try contentEncoder.encode(_v)
let _v = characters(at: index, type: Attacker.self) case .rapunzel:
try contentEncoder.encode(_v) let _v = characters(at: Int32(index), type: Rapunzel.self)
case .rapunzel: try contentEncoder.encode(_v)
let _v = characters(at: index, type: Rapunzel.self) case .belle:
try contentEncoder.encode(_v) let _v = characters(at: Int32(index), type: BookReader.self)
case .belle: try contentEncoder.encode(_v)
let _v = characters(at: index, type: BookReader.self) case .bookfan:
try contentEncoder.encode(_v) let _v = characters(at: Int32(index), type: BookReader.self)
case .bookfan: try contentEncoder.encode(_v)
let _v = characters(at: index, type: BookReader.self) case .other:
try contentEncoder.encode(_v) let _v = characters(at: Int32(index), type: String.self)
case .other: try contentEncoder.encode(_v)
let _v = characters(at: index, type: String.self) case .unused:
try contentEncoder.encode(_v) let _v = characters(at: Int32(index), type: String.self)
case .unused: try contentEncoder.encode(_v)
let _v = characters(at: index, type: String.self) default: break;
try contentEncoder.encode(_v)
default: break;
}
} }
} }
} }
@@ -702,25 +696,26 @@ public class MovieT: NativeObject {
default: break default: break
} }
characters = [] characters = []
for index in 0..<_t.charactersCount { let _charactersType = _t.charactersType
switch _t.charactersType(at: index) { for index in _charactersType.startIndex..<_charactersType.endIndex {
switch _t.charactersType[index] {
case .mulan: 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)) characters.append(CharacterUnion(_v?.unpack(), type: .mulan))
case .rapunzel: 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)) characters.append(CharacterUnion(_v?.unpack(), type: .rapunzel))
case .belle: 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)) characters.append(CharacterUnion(_v?.unpack(), type: .belle))
case .bookfan: 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)) characters.append(CharacterUnion(_v?.unpack(), type: .bookfan))
case .other: 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)) characters.append(CharacterUnion(_v?.unpack(), type: .other))
case .unused: 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)) characters.append(CharacterUnion(_v?.unpack(), type: .unused))
default: break default: break
} }

View File

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

View File

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

View File

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

View File

@@ -68,6 +68,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
]) ])
// swiftformat:enable all // swiftformat:enable all
var buffer = bytes.buffer var buffer = bytes.buffer
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer) let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
readMonster(monster: monster) readMonster(monster: monster)
mutateMonster(fb: bytes.buffer) mutateMonster(fb: bytes.buffer)
@@ -130,7 +131,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let root = Monster.endMonster(&fbb, start: mStart) let root = Monster.endMonster(&fbb, start: mStart)
fbb.finish(offset: root) fbb.finish(offset: root)
var buffer = fbb.sizedBuffer var buffer = fbb.sizedBuffer
let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer) let newMonster: Monster = getRoot(byteBuffer: &buffer)
XCTAssertNil(newMonster.pos) XCTAssertNil(newMonster.pos)
XCTAssertEqual(newMonster.name, "Frodo") XCTAssertEqual(newMonster.name, "Frodo")
} }
@@ -153,30 +154,61 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
fbb.finish(offset: root) fbb.finish(offset: root)
var buffer = fbb.sizedBuffer 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.pos!.x, 10)
XCTAssertEqual(newMonster.name, "Barney") 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() { func testArrayOfBools() {
let boolArray = [false, true, false, true, false, true, false] let boolArray = [false, true, false, true, false, true, false]
var fbb = FlatBufferBuilder(initialSize: 1) var fbb = FlatBufferBuilder(initialSize: 1)
let name = fbb.create(string: "Frodo") let name = fbb.create(string: "Frodo")
let bools = fbb.createVector(boolArray) let bools = fbb.createVector(boolArray)
let root = Monster.createMonster( let root = Monster.createMonster(
&fbb, &fbb,
nameOffset: name, nameOffset: name,
testarrayofboolsVectorOffset: bools) testarrayofboolsVectorOffset: bools)
fbb.finish(offset: root) fbb.finish(offset: root)
var buffer = fbb.sizedBuffer var buffer = fbb.sizedBuffer
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer) let monster: Monster = getRoot(byteBuffer: &buffer)
let values = monster.testarrayofbools let values = monster.testarrayofbools
XCTAssertEqual(boolArray, values) XCTAssertEqual(boolArray.count, values.count)
for i in 0..<monster.testarrayofboolsCount { for (index, bool) in monster.testarrayofbools.enumerated() {
XCTAssertEqual(boolArray[Int(i)], monster.testarrayofbools(at: i)) XCTAssertEqual(bool, boolArray[index])
} }
} }
@@ -188,6 +220,87 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
byteBuffer: &byteBuffer) as MyGame_Example_Monster)) 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) { func readMonster(monster: Monster) {
var monster = monster var monster = monster
readFlatbufferMonster(monster: &monster) readFlatbufferMonster(monster: &monster)
@@ -195,12 +308,17 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
readObjectApi(monster: unpacked!) readObjectApi(monster: unpacked!)
guard var buffer = unpacked?.serialize() guard var buffer = unpacked?.serialize()
else { fatalError("Couldnt generate bytebuffer") } else { fatalError("Couldnt generate bytebuffer") }
var newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer) var newMonster: Monster = getRoot(byteBuffer: &buffer)
readFlatbufferMonster(monster: &newMonster) readFlatbufferMonster(monster: &newMonster)
} }
func createMonster(withPrefix prefix: Bool) -> FlatBufferBuilder { func createMonster(withPrefix prefix: Bool) -> FlatBufferBuilder {
var fbb = FlatBufferBuilder(initialSize: 1) var fbb = FlatBufferBuilder(initialSize: 1)
write(fbb: &fbb, prefix: prefix)
return fbb
}
func write(fbb: inout FlatBufferBuilder, prefix: Bool = false) {
let names = [ let names = [
fbb.create(string: "Frodo"), fbb.create(string: "Frodo"),
fbb.create(string: "Barney"), fbb.create(string: "Barney"),
@@ -257,7 +375,6 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
Monster.addVectorOf(testarrayoftables: sortedArray, &fbb) Monster.addVectorOf(testarrayoftables: sortedArray, &fbb)
let end = Monster.endMonster(&fbb, start: mStart) let end = Monster.endMonster(&fbb, start: mStart)
Monster.finish(&fbb, end: end, prefix: prefix) Monster.finish(&fbb, end: end, prefix: prefix)
return fbb
} }
func mutateMonster(fb: ByteBuffer) { func mutateMonster(fb: ByteBuffer) {
@@ -265,9 +382,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
let monster: Monster = getRoot(byteBuffer: &fb) let monster: Monster = getRoot(byteBuffer: &fb)
XCTAssertFalse(monster.mutate(mana: 10)) XCTAssertFalse(monster.mutate(mana: 10))
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney") XCTAssertEqual(monster.testarrayoftables[0].name, "Barney")
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo") XCTAssertEqual(monster.testarrayoftables[1].name, "Frodo")
XCTAssertEqual(monster.testarrayoftables(at: 2)?.name, "Wilma") XCTAssertEqual(monster.testarrayoftables[2].name, "Wilma")
// Example of searching for a table by the key // Example of searching for a table by the key
XCTAssertNotNil(monster.testarrayoftablesBy(key: "Frodo")) XCTAssertNotNil(monster.testarrayoftablesBy(key: "Frodo"))
@@ -276,18 +393,14 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertEqual(monster.testType, .monster) 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: 1, at: 0), true)
XCTAssertEqual(monster.mutate(inventory: 2, at: 1), true) XCTAssertEqual(monster.mutate(inventory: 2, at: 1), true)
XCTAssertEqual(monster.mutate(inventory: 3, at: 2), true) XCTAssertEqual(monster.mutate(inventory: 3, at: 2), true)
XCTAssertEqual(monster.mutate(inventory: 4, at: 3), true) XCTAssertEqual(monster.mutate(inventory: 4, at: 3), true)
XCTAssertEqual(monster.mutate(inventory: 5, at: 4), true) XCTAssertEqual(monster.mutate(inventory: 5, at: 4), true)
for i in 0..<monster.inventoryCount { for i in 0..<monster.inventory.count {
XCTAssertEqual(monster.inventory(at: i), Byte(i + 1)) XCTAssertEqual(monster.inventory[i], Byte(i + 1))
} }
XCTAssertEqual(monster.mutate(inventory: 0, at: 0), true) XCTAssertEqual(monster.mutate(inventory: 0, at: 0), true)
@@ -305,6 +418,13 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertTrue(vec?.mutate(x: 1) ?? false) XCTAssertTrue(vec?.mutate(x: 1) ?? false)
XCTAssertEqual(vec?.x, 1) XCTAssertEqual(vec?.x, 1)
XCTAssertTrue(vec?.mutate(test1: 3) ?? false) 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) { func readFlatbufferMonster(monster: inout MyGame_Example_Monster) {
@@ -327,47 +447,64 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
XCTAssertEqual(monster.mutate(mana: 10), false) XCTAssertEqual(monster.mutate(mana: 10), false)
XCTAssertEqual(monster.mana, 150) XCTAssertEqual(monster.mana, 150)
XCTAssertEqual(monster.inventoryCount, 5) XCTAssertEqual(monster.inventory.count, 5)
var sum: Byte = 0 var sum: Byte = 0
for i in 0...monster.inventoryCount { for inventory in monster.inventory {
sum += monster.inventory(at: i) sum += inventory
} }
XCTAssertEqual(sum, 10) XCTAssertEqual(sum, 10)
XCTAssertEqual(monster.test4Count, 2)
let test0 = monster.test4(at: 0) monster.withUnsafePointerToInventory { ptr, count in
let test1 = monster.test4(at: 1) 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 sum0 = 0
var sum1 = 0 for test0 in test4 {
if let a = test0?.a, let b = test0?.b { sum0 += Int(test0.a) + Int(test0.b)
sum0 = Int(a) + Int(b)
} }
if let a = test1?.a, let b = test1?.b { XCTAssertEqual(sum0, 100)
sum1 = Int(a) + Int(b)
}
XCTAssertEqual(sum0 + sum1, 100)
let mutableTest0 = monster.mutableTest4(at: 0) monster.withUnsafePointerToTest4 { ptr, count in
let mutableTest1 = monster.mutableTest4(at: 1) 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 sum2 = 0
var sum3 = 0 for test0 in mutableTest4 {
if let a = mutableTest0?.a, let b = mutableTest0?.b { sum2 += Int(test0.a) + Int(test0.b)
sum2 = Int(a) + Int(b)
} }
if let a = mutableTest1?.a, let b = mutableTest1?.b { XCTAssertEqual(sum2, 100)
sum3 = Int(a) + Int(b)
}
XCTAssertEqual(sum2 + sum3, 100)
XCTAssertEqual(monster.testarrayofstringCount, 2) let stringArray = monster.testarrayofstring
XCTAssertEqual(monster.testarrayofstring(at: 0), "test1") XCTAssertEqual(stringArray.count, 2)
XCTAssertEqual(monster.testarrayofstring(at: 1), "test2") XCTAssertEqual(stringArray[0], "test1")
XCTAssertEqual(stringArray[1], "test2")
XCTAssertEqual(monster.testbool, true) XCTAssertEqual(monster.testbool, true)
let array = monster.nameSegmentArray let array = monster.nameSegmentArray
XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster") XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster")
if 0 == monster.testarrayofboolsCount { if 0 == monster.testarrayofbools.count {
XCTAssertEqual(monster.testarrayofbools.isEmpty, true) XCTAssertEqual(monster.testarrayofbools.isEmpty, true)
} else { } else {
XCTAssertEqual(monster.testarrayofbools.isEmpty, false) XCTAssertEqual(monster.testarrayofbools.isEmpty, false)
@@ -402,20 +539,43 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
} }
XCTAssertEqual(sum, 10) XCTAssertEqual(sum, 10)
XCTAssertEqual(monster.test4.count, 2) XCTAssertEqual(monster.test4.count, 2)
let test0 = monster.test4[0]
let test1 = monster.test4[1]
var sum0 = 0 var sum0 = 0
var sum1 = 0 for test in monster.test4 {
if let a = test0?.a, let b = test0?.b { sum0 += Int(test.a) + Int(test.b)
sum0 = Int(a) + Int(b)
} }
if let a = test1?.a, let b = test1?.b { XCTAssertEqual(sum0, 100)
sum1 = Int(a) + Int(b)
}
XCTAssertEqual(sum0 + sum1, 100)
XCTAssertEqual(monster.testbool, true) 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 { 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\"} {\"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 import FlatBuffers
/// Composite components of Monster color. /// 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 typealias T = UInt8
public static var byteSize: Int { return MemoryLayout<UInt8>.size } public static var byteSize: Int { return MemoryLayout<UInt8>.size }
public var value: UInt8 { return self.rawValue } 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 typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size } public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue } 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 typealias T = UInt64
public static var byteSize: Int { return MemoryLayout<UInt64>.size } public static var byteSize: Int { return MemoryLayout<UInt64>.size }
public var value: UInt64 { return self.rawValue } 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 typealias T = UInt8
public init?(value: T) { 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 typealias T = UInt8
public init?(value: T) { 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 typealias T = UInt8
public init?(value: T) { 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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) } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
internal var __buffer: ByteBuffer! { return _accessor.bb } 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) } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -1111,7 +1111,7 @@ public class MyGame_Example_ReferrableT: NativeObject {
} }
/// an example documentation comment: "monster object" /// 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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) } @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 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 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 inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
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 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 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 } 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) } @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 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 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 test4: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
public var test4Count: Int32 { let o = _accessor.offset(VTOFFSET.test4.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var mutableTest4: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test4.v, byteSize: 4) }
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 withUnsafePointerToTest4<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test4.v, body: body) }
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 var testarrayofstring: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring.v, byteSize: 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) }
/// an example documentation comment: this will end up in the generated code /// an example documentation comment: this will end up in the generated code
/// multiline too /// multiline too
public var hasTestarrayoftables: Bool { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? false : true } public var testarrayoftables: FlatbufferVector<MyGame_Example_Monster> { return _accessor.vector(at: VTOFFSET.testarrayoftables.v, byteSize: 4) }
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 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 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 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 testnestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testnestedflatbuffer.v, byteSize: 1) }
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 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 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 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) } 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) } @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) } @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) } 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) } @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 testarrayofbools: FlatbufferVector<Bool> { return _accessor.vector(at: VTOFFSET.testarrayofbools.v, byteSize: 1) }
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 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 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) } 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) } @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) } 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) } @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) } 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) } @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 testarrayofstring2: FlatbufferVector<String?> { return _accessor.vector(at: VTOFFSET.testarrayofstring2.v, byteSize: 4) }
public var testarrayofstring2Count: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofstring2.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var testarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
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 mutableTestarrayofsortedstruct: FlatbufferVector<MyGame_Example_Ability_Mutable> { return _accessor.vector(at: VTOFFSET.testarrayofsortedstruct.v, byteSize: 8) }
public var hasTestarrayofsortedstruct: Bool { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? false : true } public func withUnsafePointerToTestarrayofsortedstruct<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.testarrayofsortedstruct.v, body: body) }
public var testarrayofsortedstructCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayofsortedstruct.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var flex: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.flex.v, byteSize: 1) }
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 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 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 func withUnsafePointerToFlex<T>(_ body: (UnsafeRawBufferPointer, Int) 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 test5: FlatbufferVector<MyGame_Example_Test> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
public var test5Count: Int32 { let o = _accessor.offset(VTOFFSET.test5.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var mutableTest5: FlatbufferVector<MyGame_Example_Test_Mutable> { return _accessor.vector(at: VTOFFSET.test5.v, byteSize: 4) }
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 withUnsafePointerToTest5<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.test5.v, body: body) }
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 var vectorOfLongs: FlatbufferVector<Int64> { return _accessor.vector(at: VTOFFSET.vectorOfLongs.v, byteSize: 8) }
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 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 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 func withUnsafePointerToVectorOfLongs<T>(_ body: (UnsafeRawBufferPointer, Int) 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 vectorOfDoubles: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vectorOfDoubles.v, byteSize: 8) }
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 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 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 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 vectorOfReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfReferrables.v, byteSize: 4) }
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 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 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) } 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) } @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 vectorOfWeakReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfWeakReferences.v, byteSize: 8) }
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 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 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 func withUnsafePointerToVectorOfWeakReferences<T>(_ body: (UnsafeRawBufferPointer, Int) 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 vectorOfStrongReferrables: FlatbufferVector<MyGame_Example_Referrable> { return _accessor.vector(at: VTOFFSET.vectorOfStrongReferrables.v, byteSize: 4) }
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 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 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) } 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) } @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 vectorOfCoOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfCoOwningReferences.v, byteSize: 8) }
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 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 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) } 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) } @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 vectorOfNonOwningReferences: FlatbufferVector<UInt64> { return _accessor.vector(at: VTOFFSET.vectorOfNonOwningReferences.v, byteSize: 8) }
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 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 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 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 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 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 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 vectorOfEnums: FlatbufferVector<MyGame_Example_Color> { return _accessor.vector(at: VTOFFSET.vectorOfEnums.v, byteSize: 1) }
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 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_ } 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) } @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 testrequirednestedflatbuffer: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.testrequirednestedflatbuffer.v, byteSize: 1) }
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 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 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 func withUnsafePointerToTestrequirednestedflatbuffer<T>(_ body: (UnsafeRawBufferPointer, Int) 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 scalarKeySortedTables: FlatbufferVector<MyGame_Example_Stat> { return _accessor.vector(at: VTOFFSET.scalarKeySortedTables.v, byteSize: 4) }
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 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 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 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) } 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 __inventory = builder.createVector(obj.inventory)
let __test = obj.test?.pack(builder: &builder) ?? Offset() let __test = obj.test?.pack(builder: &builder) ?? Offset()
MyGame_Example_Monster.startVectorOfTest4(obj.test4.count, in: &builder) MyGame_Example_Monster.startVectorOfTest4(obj.test4.count, in: &builder)
for i in obj.test4 { for val in obj.test4 {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __test4 = builder.endVector(len: obj.test4.count) let __test4 = builder.endVector(len: obj.test4.count)
let __testarrayofstring = builder.createVector(ofStrings: obj.testarrayofstring.compactMap({ $0 }) ) 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 __testarrayofbools = builder.createVector(obj.testarrayofbools)
let __testarrayofstring2 = builder.createVector(ofStrings: obj.testarrayofstring2.compactMap({ $0 }) ) let __testarrayofstring2 = builder.createVector(ofStrings: obj.testarrayofstring2.compactMap({ $0 }) )
MyGame_Example_Monster.startVectorOfTestarrayofsortedstruct(obj.testarrayofsortedstruct.count, in: &builder) MyGame_Example_Monster.startVectorOfTestarrayofsortedstruct(obj.testarrayofsortedstruct.count, in: &builder)
for i in obj.testarrayofsortedstruct { for val in obj.testarrayofsortedstruct {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __testarrayofsortedstruct = builder.endVector(len: obj.testarrayofsortedstruct.count) let __testarrayofsortedstruct = builder.endVector(len: obj.testarrayofsortedstruct.count)
let __flex = builder.createVector(obj.flex) let __flex = builder.createVector(obj.flex)
MyGame_Example_Monster.startVectorOfTest5(obj.test5.count, in: &builder) MyGame_Example_Monster.startVectorOfTest5(obj.test5.count, in: &builder)
for i in obj.test5 { for val in obj.test5 {
guard let _o = i else { continue } builder.create(struct: val)
builder.create(struct: _o)
} }
let __test5 = builder.endVector(len: obj.test5.count) let __test5 = builder.endVector(len: obj.test5.count)
let __vectorOfLongs = builder.createVector(obj.vectorOfLongs) let __vectorOfLongs = builder.createVector(obj.vectorOfLongs)
@@ -1904,9 +1851,7 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(hp, forKey: .hp) try container.encodeIfPresent(hp, forKey: .hp)
} }
try container.encodeIfPresent(name, forKey: .name) try container.encodeIfPresent(name, forKey: .name)
if inventoryCount > 0 { try container.encodeIfPresent(inventory, forKey: .inventory)
try container.encodeIfPresent(inventory, forKey: .inventory)
}
if color != .blue { if color != .blue {
try container.encodeIfPresent(color, forKey: .color) try container.encodeIfPresent(color, forKey: .color)
} }
@@ -1925,31 +1870,11 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .test) try container.encodeIfPresent(_v, forKey: .test)
default: break; default: break;
} }
if test4Count > 0 { try container.encodeIfPresent(test4, forKey: .test4)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .test4) try container.encodeIfPresent(testarrayofstring, forKey: .testarrayofstring)
for index in 0..<test4Count { try container.encodeIfPresent(testarrayoftables, forKey: .testarrayoftables)
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(enemy, forKey: .enemy) 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) try container.encodeIfPresent(testempty, forKey: .testempty)
if testbool != false { if testbool != false {
try container.encodeIfPresent(testbool, forKey: .testbool) try container.encodeIfPresent(testbool, forKey: .testbool)
@@ -1978,9 +1903,7 @@ extension MyGame_Example_Monster: Encodable {
if testhashu64Fnv1a != 0 { if testhashu64Fnv1a != 0 {
try container.encodeIfPresent(testhashu64Fnv1a, forKey: .testhashu64Fnv1a) 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 { if testf != 3.14159 {
try container.encodeIfPresent(testf, forKey: .testf) try container.encodeIfPresent(testf, forKey: .testf)
} }
@@ -1990,69 +1913,27 @@ extension MyGame_Example_Monster: Encodable {
if testf3 != 0.0 { if testf3 != 0.0 {
try container.encodeIfPresent(testf3, forKey: .testf3) try container.encodeIfPresent(testf3, forKey: .testf3)
} }
if testarrayofstring2Count > 0 { try container.encodeIfPresent(testarrayofstring2, forKey: .testarrayofstring2)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .testarrayofstring2) try container.encodeIfPresent(testarrayofsortedstruct, forKey: .testarrayofsortedstruct)
for index in 0..<testarrayofstring2Count { try container.encodeIfPresent(flex, forKey: .flex)
guard let type = testarrayofstring2(at: index) else { continue } try container.encodeIfPresent(test5, forKey: .test5)
try contentEncoder.encode(type) try container.encodeIfPresent(vectorOfLongs, forKey: .vectorOfLongs)
} try container.encodeIfPresent(vectorOfDoubles, forKey: .vectorOfDoubles)
}
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(parentNamespaceTest, forKey: .parentNamespaceTest) try container.encodeIfPresent(parentNamespaceTest, forKey: .parentNamespaceTest)
if vectorOfReferrablesCount > 0 { try container.encodeIfPresent(vectorOfReferrables, forKey: .vectorOfReferrables)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfReferrables)
for index in 0..<vectorOfReferrablesCount {
guard let type = vectorOfReferrables(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if singleWeakReference != 0 { if singleWeakReference != 0 {
try container.encodeIfPresent(singleWeakReference, forKey: .singleWeakReference) try container.encodeIfPresent(singleWeakReference, forKey: .singleWeakReference)
} }
if vectorOfWeakReferencesCount > 0 { try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences)
try container.encodeIfPresent(vectorOfWeakReferences, forKey: .vectorOfWeakReferences) try container.encodeIfPresent(vectorOfStrongReferrables, forKey: .vectorOfStrongReferrables)
}
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)
}
}
if coOwningReference != 0 { if coOwningReference != 0 {
try container.encodeIfPresent(coOwningReference, forKey: .coOwningReference) try container.encodeIfPresent(coOwningReference, forKey: .coOwningReference)
} }
if vectorOfCoOwningReferencesCount > 0 { try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
try container.encodeIfPresent(vectorOfCoOwningReferences, forKey: .vectorOfCoOwningReferences)
}
if nonOwningReference != 0 { if nonOwningReference != 0 {
try container.encodeIfPresent(nonOwningReference, forKey: .nonOwningReference) try container.encodeIfPresent(nonOwningReference, forKey: .nonOwningReference)
} }
if vectorOfNonOwningReferencesCount > 0 { try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
try container.encodeIfPresent(vectorOfNonOwningReferences, forKey: .vectorOfNonOwningReferences)
}
if anyUniqueType != .none_ { if anyUniqueType != .none_ {
try container.encodeIfPresent(anyUniqueType, forKey: .anyUniqueType) try container.encodeIfPresent(anyUniqueType, forKey: .anyUniqueType)
} }
@@ -2083,26 +1964,12 @@ extension MyGame_Example_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .anyAmbiguous) try container.encodeIfPresent(_v, forKey: .anyAmbiguous)
default: break; default: break;
} }
if vectorOfEnumsCount > 0 { try container.encodeIfPresent(vectorOfEnums, forKey: .vectorOfEnums)
var contentEncoder = container.nestedUnkeyedContainer(forKey: .vectorOfEnums)
for index in 0..<vectorOfEnumsCount {
guard let type = vectorOfEnums(at: index) else { continue }
try contentEncoder.encode(type)
}
}
if signedEnum != .none_ { if signedEnum != .none_ {
try container.encodeIfPresent(signedEnum, forKey: .signedEnum) try container.encodeIfPresent(signedEnum, forKey: .signedEnum)
} }
if testrequirednestedflatbufferCount > 0 { try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer)
try container.encodeIfPresent(testrequirednestedflatbuffer, forKey: .testrequirednestedflatbuffer) try container.encodeIfPresent(scalarKeySortedTables, forKey: .scalarKeySortedTables)
}
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(nativeInline, forKey: .nativeInline) try container.encodeIfPresent(nativeInline, forKey: .nativeInline)
if longEnumNonEnumDefault != .longone { if longEnumNonEnumDefault != .longone {
try container.encodeIfPresent(longEnumNonEnumDefault, forKey: .longEnumNonEnumDefault) try container.encodeIfPresent(longEnumNonEnumDefault, forKey: .longEnumNonEnumDefault)
@@ -2146,7 +2013,7 @@ public class MyGame_Example_MonsterT: NativeObject {
public var inventory: [UInt8] public var inventory: [UInt8]
public var color: MyGame_Example_Color public var color: MyGame_Example_Color
public var test: MyGame_Example_Any_Union? 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 testarrayofstring: [String?]
public var testarrayoftables: [MyGame_Example_MonsterT?] public var testarrayoftables: [MyGame_Example_MonsterT?]
public var enemy: 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 testf2: Float32
public var testf3: Float32 public var testf3: Float32
public var testarrayofstring2: [String?] public var testarrayofstring2: [String?]
public var testarrayofsortedstruct: [MyGame_Example_Ability?] public var testarrayofsortedstruct: [MyGame_Example_Ability]
public var flex: [UInt8] public var flex: [UInt8]
public var test5: [MyGame_Example_Test?] public var test5: [MyGame_Example_Test]
public var vectorOfLongs: [Int64] public var vectorOfLongs: [Int64]
public var vectorOfDoubles: [Double] public var vectorOfDoubles: [Double]
public var parentNamespaceTest: MyGame_InParentNamespaceT? public var parentNamespaceTest: MyGame_InParentNamespaceT?
@@ -2204,9 +2071,7 @@ public class MyGame_Example_MonsterT: NativeObject {
hp = _t.hp hp = _t.hp
name = _t.name name = _t.name
inventory = [] inventory = []
for index in 0..<_t.inventoryCount { inventory.append(contentsOf: _t.inventory)
inventory.append(_t.inventory(at: index))
}
color = _t.color color = _t.color
switch _t.testType { switch _t.testType {
case .monster: case .monster:
@@ -2221,24 +2086,17 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break default: break
} }
test4 = [] test4 = []
for index in 0..<_t.test4Count { test4.append(contentsOf: _t.test4)
test4.append(_t.test4(at: index))
}
testarrayofstring = [] testarrayofstring = []
for index in 0..<_t.testarrayofstringCount { testarrayofstring.append(contentsOf: _t.testarrayofstring)
testarrayofstring.append(_t.testarrayofstring(at: index))
}
testarrayoftables = [] testarrayoftables = []
for index in 0..<_t.testarrayoftablesCount { for var val in _t.testarrayoftables{
var __v_ = _t.testarrayoftables(at: index) testarrayoftables.append(val.unpack())
testarrayoftables.append(__v_?.unpack())
} }
var __enemy = _t.enemy var __enemy = _t.enemy
enemy = __enemy?.unpack() enemy = __enemy?.unpack()
testnestedflatbuffer = [] testnestedflatbuffer = []
for index in 0..<_t.testnestedflatbufferCount { testnestedflatbuffer.append(contentsOf: _t.testnestedflatbuffer)
testnestedflatbuffer.append(_t.testnestedflatbuffer(at: index))
}
var __testempty = _t.testempty var __testempty = _t.testempty
testempty = __testempty?.unpack() testempty = __testempty?.unpack()
testbool = _t.testbool testbool = _t.testbool
@@ -2251,63 +2109,41 @@ public class MyGame_Example_MonsterT: NativeObject {
testhashs64Fnv1a = _t.testhashs64Fnv1a testhashs64Fnv1a = _t.testhashs64Fnv1a
testhashu64Fnv1a = _t.testhashu64Fnv1a testhashu64Fnv1a = _t.testhashu64Fnv1a
testarrayofbools = [] testarrayofbools = []
for index in 0..<_t.testarrayofboolsCount { testarrayofbools.append(contentsOf: _t.testarrayofbools)
testarrayofbools.append(_t.testarrayofbools(at: index))
}
testf = _t.testf testf = _t.testf
testf2 = _t.testf2 testf2 = _t.testf2
testf3 = _t.testf3 testf3 = _t.testf3
testarrayofstring2 = [] testarrayofstring2 = []
for index in 0..<_t.testarrayofstring2Count { testarrayofstring2.append(contentsOf: _t.testarrayofstring2)
testarrayofstring2.append(_t.testarrayofstring2(at: index))
}
testarrayofsortedstruct = [] testarrayofsortedstruct = []
for index in 0..<_t.testarrayofsortedstructCount { testarrayofsortedstruct.append(contentsOf: _t.testarrayofsortedstruct)
testarrayofsortedstruct.append(_t.testarrayofsortedstruct(at: index))
}
flex = [] flex = []
for index in 0..<_t.flexCount { flex.append(contentsOf: _t.flex)
flex.append(_t.flex(at: index))
}
test5 = [] test5 = []
for index in 0..<_t.test5Count { test5.append(contentsOf: _t.test5)
test5.append(_t.test5(at: index))
}
vectorOfLongs = [] vectorOfLongs = []
for index in 0..<_t.vectorOfLongsCount { vectorOfLongs.append(contentsOf: _t.vectorOfLongs)
vectorOfLongs.append(_t.vectorOfLongs(at: index))
}
vectorOfDoubles = [] vectorOfDoubles = []
for index in 0..<_t.vectorOfDoublesCount { vectorOfDoubles.append(contentsOf: _t.vectorOfDoubles)
vectorOfDoubles.append(_t.vectorOfDoubles(at: index))
}
var __parentNamespaceTest = _t.parentNamespaceTest var __parentNamespaceTest = _t.parentNamespaceTest
parentNamespaceTest = __parentNamespaceTest?.unpack() parentNamespaceTest = __parentNamespaceTest?.unpack()
vectorOfReferrables = [] vectorOfReferrables = []
for index in 0..<_t.vectorOfReferrablesCount { for var val in _t.vectorOfReferrables{
var __v_ = _t.vectorOfReferrables(at: index) vectorOfReferrables.append(val.unpack())
vectorOfReferrables.append(__v_?.unpack())
} }
singleWeakReference = _t.singleWeakReference singleWeakReference = _t.singleWeakReference
vectorOfWeakReferences = [] vectorOfWeakReferences = []
for index in 0..<_t.vectorOfWeakReferencesCount { vectorOfWeakReferences.append(contentsOf: _t.vectorOfWeakReferences)
vectorOfWeakReferences.append(_t.vectorOfWeakReferences(at: index))
}
vectorOfStrongReferrables = [] vectorOfStrongReferrables = []
for index in 0..<_t.vectorOfStrongReferrablesCount { for var val in _t.vectorOfStrongReferrables{
var __v_ = _t.vectorOfStrongReferrables(at: index) vectorOfStrongReferrables.append(val.unpack())
vectorOfStrongReferrables.append(__v_?.unpack())
} }
coOwningReference = _t.coOwningReference coOwningReference = _t.coOwningReference
vectorOfCoOwningReferences = [] vectorOfCoOwningReferences = []
for index in 0..<_t.vectorOfCoOwningReferencesCount { vectorOfCoOwningReferences.append(contentsOf: _t.vectorOfCoOwningReferences)
vectorOfCoOwningReferences.append(_t.vectorOfCoOwningReferences(at: index))
}
nonOwningReference = _t.nonOwningReference nonOwningReference = _t.nonOwningReference
vectorOfNonOwningReferences = [] vectorOfNonOwningReferences = []
for index in 0..<_t.vectorOfNonOwningReferencesCount { vectorOfNonOwningReferences.append(contentsOf: _t.vectorOfNonOwningReferences)
vectorOfNonOwningReferences.append(_t.vectorOfNonOwningReferences(at: index))
}
switch _t.anyUniqueType { switch _t.anyUniqueType {
case .m: case .m:
var _v = _t.anyUnique(type: MyGame_Example_Monster.self) var _v = _t.anyUnique(type: MyGame_Example_Monster.self)
@@ -2333,18 +2169,13 @@ public class MyGame_Example_MonsterT: NativeObject {
default: break default: break
} }
vectorOfEnums = [] vectorOfEnums = []
for index in 0..<_t.vectorOfEnumsCount { vectorOfEnums.append(contentsOf: _t.vectorOfEnums)
vectorOfEnums.append(_t.vectorOfEnums(at: index)!)
}
signedEnum = _t.signedEnum signedEnum = _t.signedEnum
testrequirednestedflatbuffer = [] testrequirednestedflatbuffer = []
for index in 0..<_t.testrequirednestedflatbufferCount { testrequirednestedflatbuffer.append(contentsOf: _t.testrequirednestedflatbuffer)
testrequirednestedflatbuffer.append(_t.testrequirednestedflatbuffer(at: index))
}
scalarKeySortedTables = [] scalarKeySortedTables = []
for index in 0..<_t.scalarKeySortedTablesCount { for var val in _t.scalarKeySortedTables{
var __v_ = _t.scalarKeySortedTables(at: index) scalarKeySortedTables.append(val.unpack())
scalarKeySortedTables.append(__v_?.unpack())
} }
nativeInline = _t.nativeInline nativeInline = _t.nativeInline
longEnumNonEnumDefault = _t.longEnumNonEnumDefault 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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) } @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) } 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) } @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 v8: FlatbufferVector<Int8> { return _accessor.vector(at: VTOFFSET.v8.v, byteSize: 1) }
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 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 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 func withUnsafePointerToV8<T>(_ body: (UnsafeRawBufferPointer, Int) 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 vf64: FlatbufferVector<Double> { return _accessor.vector(at: VTOFFSET.vf64.v, byteSize: 8) }
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 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 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 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(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) } 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 { if f64 != 0.0 {
try container.encodeIfPresent(f64, forKey: .f64) try container.encodeIfPresent(f64, forKey: .f64)
} }
if v8Count > 0 { try container.encodeIfPresent(v8, forKey: .v8)
try container.encodeIfPresent(v8, forKey: .v8) try container.encodeIfPresent(vf64, forKey: .vf64)
}
if vf64Count > 0 {
try container.encodeIfPresent(vf64, forKey: .vf64)
}
} }
} }
@@ -2655,13 +2476,9 @@ public class MyGame_Example_TypeAliasesT: NativeObject {
f32 = _t.f32 f32 = _t.f32
f64 = _t.f64 f64 = _t.f64
v8 = [] v8 = []
for index in 0..<_t.v8Count { v8.append(contentsOf: _t.v8)
v8.append(_t.v8(at: index))
}
vf64 = [] vf64 = []
for index in 0..<_t.vf64Count { vf64.append(contentsOf: _t.vf64)
vf64.append(_t.vf64(at: index))
}
} }
public init() { public init() {

View File

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

View File

@@ -2,7 +2,7 @@
// swiftlint:disable all // swiftlint:disable all
// swiftformat: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() } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } 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 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() } static func validateVersion() { FlatBuffersVersion_25_9_23() }
public var __buffer: ByteBuffer! { return _accessor.bb } public var __buffer: ByteBuffer! { return _accessor.bb }

View File

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