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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public struct models_HelloReply: FlatBufferObject, Verifiable {
public struct models_HelloReply: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
static func validateVersion() { FlatBuffersVersion_25_9_23() }
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() }
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.
let sayHello =
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.
do {

View File

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

View File

@@ -8,7 +8,7 @@ import Common
import FlatBuffers
public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
public enum MyGame_Sample_Color: Int8, FlatbuffersVectorInitializable, Enum, Verifiable {
public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue }
@@ -31,7 +31,7 @@ extension MyGame_Sample_Color: Encodable {
}
}
public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
public enum MyGame_Sample_Equipment: UInt8, FlatbuffersVectorInitializable, UnionEnum {
public typealias T = UInt8
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() }
@@ -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() }
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() }
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) }
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 hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
public var inventory: FlatbufferVector<UInt8> { return _accessor.vector(at: VTOFFSET.inventory.v, byteSize: 1) }
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
public var color: MyGame_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) }
public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true }
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 weapons: FlatbufferVector<MyGame_Sample_Weapon> { return _accessor.vector(at: VTOFFSET.weapons.v, byteSize: 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 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 pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
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 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 var path: FlatbufferVector<MyGame_Sample_Vec3> { return _accessor.vector(at: VTOFFSET.path.v, byteSize: 12) }
public var mutablePath: FlatbufferVector<MyGame_Sample_Vec3_Mutable> { return _accessor.vector(at: VTOFFSET.path.v, byteSize: 12) }
public func withUnsafePointerToPath<T>(_ body: (UnsafeRawBufferPointer, Int) 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 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) }
@@ -282,9 +275,8 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPack
let __weapons = builder.createVector(ofOffsets: __weapons__)
let __equipped = obj.equipped?.pack(builder: &builder) ?? Offset()
MyGame_Sample_Monster.startVectorOfPath(obj.path.count, in: &builder)
for i in obj.path {
guard let _o = i else { continue }
builder.create(struct: _o)
for val in obj.path {
builder.create(struct: val)
}
let __path = builder.endVector(len: obj.path.count)
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(name, forKey: .name)
if inventoryCount > 0 {
try container.encodeIfPresent(inventory, forKey: .inventory)
}
try container.encodeIfPresent(inventory, forKey: .inventory)
if color != .blue {
try container.encodeIfPresent(color, forKey: .color)
}
if weaponsCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .weapons)
for index in 0..<weaponsCount {
guard let type = weapons(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(weapons, forKey: .weapons)
if equippedType != .none_ {
try container.encodeIfPresent(equippedType, forKey: .equippedType)
}
@@ -372,13 +356,7 @@ extension MyGame_Sample_Monster: Encodable {
try container.encodeIfPresent(_v, forKey: .equipped)
default: break;
}
if pathCount > 0 {
var contentEncoder = container.nestedUnkeyedContainer(forKey: .path)
for index in 0..<pathCount {
guard let type = path(at: index) else { continue }
try contentEncoder.encode(type)
}
}
try container.encodeIfPresent(path, forKey: .path)
}
}
@@ -392,7 +370,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
public var color: MyGame_Sample_Color
public var weapons: [MyGame_Sample_WeaponT?]
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) {
pos = _t.pos
@@ -400,14 +378,11 @@ public class MyGame_Sample_MonsterT: NativeObject {
hp = _t.hp
name = _t.name
inventory = []
for index in 0..<_t.inventoryCount {
inventory.append(_t.inventory(at: index))
}
inventory.append(contentsOf: _t.inventory)
color = _t.color
weapons = []
for index in 0..<_t.weaponsCount {
var __v_ = _t.weapons(at: index)
weapons.append(__v_?.unpack())
for var val in _t.weapons{
weapons.append(val.unpack())
}
switch _t.equippedType {
case .weapon:
@@ -416,9 +391,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
default: break
}
path = []
for index in 0..<_t.pathCount {
path.append(_t.path(at: index))
}
path.append(contentsOf: _t.path)
}
public init() {
@@ -434,7 +407,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
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() }
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 + ")";
}
static std::string GenArrayMainBody(const std::string& optional) {
return "{{ACCESS_TYPE}} func {{FIELDMETHOD}}(at index: Int32) -> "
"{{VALUETYPE}}" +
optional + " { ";
}
} // namespace
class SwiftGenerator : public BaseGenerator {
@@ -234,7 +228,8 @@ class SwiftGenerator : public BaseGenerator {
GenComment(struct_def.doc_comment);
code_.SetValue("STRUCTNAME", namer_.NamespacedType(struct_def));
code_ +=
"{{ACCESS_TYPE}} struct {{STRUCTNAME}}: NativeStruct, Verifiable, "
"{{ACCESS_TYPE}} struct {{STRUCTNAME}}: NativeStruct, "
"FlatbuffersVectorInitializable, Verifiable, "
"FlatbuffersInitializable\\";
if (parser_.opts.generate_object_based_api) code_ += ", NativeObject\\";
code_ += " {";
@@ -473,7 +468,8 @@ class SwiftGenerator : public BaseGenerator {
code_.SetValue("OBJECTTYPE", struct_def.fixed ? "Struct" : "Table");
code_.SetValue("MUTABLE", struct_def.fixed ? Mutable() : "");
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 && parser_.opts.generate_object_based_api)
code_ += ", ObjectAPIPacker\\";
@@ -807,43 +803,23 @@ class SwiftGenerator : public BaseGenerator {
}
void GenTableReaderVectorFields(const FieldDef& field) {
std::string const_string = "return o == 0 ? {{CONSTANT}} : ";
const auto vectortype = field.value.type.VectorType();
code_.SetValue("SIZE", NumToString(InlineSize(vectortype)));
code_.SetValue("HAS_FIELDVAR", namer_.Variable("has", field));
code_ += "{{ACCESS_TYPE}} var {{HAS_FIELDVAR}}: Bool { " + GenOffset() +
"return o == 0 ? false : true }";
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_STRING) {
code_.SetValue("VALUETYPE", "String?");
}
if (vectortype.base_type != BASE_TYPE_UNION) {
code_ += GenArrayMainBody(nullable) + GenOffset() + "\\";
} else {
code_ +=
"{{ACCESS_TYPE}} func {{FIELDVAR}}<T: FlatbuffersInitializable>(at "
"index: "
"Int32, type: T.Type) -> T? { " +
GenOffset() + "\\";
"{{ACCESS_TYPE}} var {{FIELDVAR}}: "
"FlatbufferVector<{{VALUETYPE}}> "
"{ return {{ACCESS}}.vector(at: {{TABLEOFFSET}}.{{OFFSET}}.v, "
"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) &&
!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();
GenUnsafeBufferPointer(field);
return;
@@ -851,34 +827,26 @@ class SwiftGenerator : public BaseGenerator {
if (vectortype.base_type == BASE_TYPE_STRUCT &&
field.value.type.struct_def->fixed) {
code_.SetValue("FIELDVAR", namer_.Method("mutable", field));
code_ +=
"{{ACCESS}}.directRead(of: {{VALUETYPE}}.self, offset: "
"{{ACCESS}}.vector(at: o) + index * {{SIZE}}) }";
code_.SetValue("FIELDMETHOD", namer_.Method("mutable", field));
code_.SetValue("VALUETYPE", GenType(field.value.type) + Mutable());
code_ += GenArrayMainBody(nullable) + GenOffset() + const_string +
GenConstructor("{{ACCESS}}.vector(at: o) + index * {{SIZE}}");
"{{ACCESS_TYPE}} var {{FIELDVAR}}: "
"FlatbufferVector<{{VALUETYPE}}_Mutable> "
"{ return {{ACCESS}}.vector(at: {{TABLEOFFSET}}.{{OFFSET}}.v, "
"byteSize: {{SIZE}}) }";
GenUnsafeBufferPointer(field);
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) {
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_ +=
"{{ACCESS}}.directUnion({{ACCESS}}.vector(at: o) + "
"index * {{SIZE}}) }";
@@ -887,9 +855,6 @@ class SwiftGenerator : public BaseGenerator {
if (vectortype.base_type == BASE_TYPE_STRUCT &&
!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& fields = sd.fields.vec;
for (auto kit = fields.begin(); kit != fields.end(); ++kit) {
@@ -907,7 +872,8 @@ class SwiftGenerator : public BaseGenerator {
namer_.Variable("withUnsafePointerTo", field));
code_ +=
"{{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, "
"body: body) }";
}
@@ -938,16 +904,15 @@ class SwiftGenerator : public BaseGenerator {
return;
if (is_vector) {
code_ +=
"var enumsEncoder = container.nestedUnkeyedContainer(forKey: "
".{{FIELDVAR}}Type)";
"try container.encode({{FIELDVAR}}Type, forKey: .charactersType)";
code_ +=
"var contentEncoder = container.nestedUnkeyedContainer(forKey: "
".{{FIELDVAR}})";
code_ += "for index in 0..<{{FIELDVAR}}Count {";
code_ += "let _{{FIELDVAR}} = {{FIELDVAR}}Type";
code_ +=
"for index in _{{FIELDVAR}}.startIndex..<_{{FIELDVAR}}.endIndex {";
Indent();
code_ += "guard let type = {{FIELDVAR}}Type(at: index) else { continue }";
code_ += "try enumsEncoder.encode(type)";
code_ += "switch type {";
code_ += "switch _{{FIELDVAR}}[index] {";
for (auto it = union_def.Vals().begin(); it != union_def.Vals().end();
++it) {
const auto& ev = **it;
@@ -959,7 +924,8 @@ class SwiftGenerator : public BaseGenerator {
}
code_ += "case .{{KEY}}:";
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)";
Outdent();
}
@@ -998,17 +964,10 @@ class SwiftGenerator : public BaseGenerator {
if (field.deprecated) continue;
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("CONSTANT", SwiftConstant(field));
bool should_indent = true;
if (is_non_union_vector) {
code_ += "if {{FIELDVAR}}Count > 0 {";
} else if (IsEnum(type) && !field.IsOptional()) {
if (IsEnum(type) && !field.IsOptional()) {
code_.SetValue("CONSTANT", GenEnumDefaultValue(field));
code_ += "if {{FIELDVAR}} != {{CONSTANT}} {";
} else if (IsFloat(type.base_type) &&
@@ -1027,18 +986,6 @@ class SwiftGenerator : public BaseGenerator {
if (IsUnion(type) && !IsEnum(type)) {
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 {
code_ +=
"try container.encodeIfPresent({{FIELDVAR}}, forKey: "
@@ -1046,8 +993,7 @@ class SwiftGenerator : public BaseGenerator {
}
if (should_indent) Outdent();
if (is_non_union_vector ||
(IsScalar(type.base_type) && !field.IsOptional())) {
if ((IsScalar(type.base_type) && !field.IsOptional())) {
code_ += "}";
}
}
@@ -1202,7 +1148,8 @@ class SwiftGenerator : public BaseGenerator {
code_.SetValue("BASE_TYPE", GenTypeBasic(enum_def.underlying_type, false));
GenComment(enum_def.doc_comment);
code_ +=
"{{ACCESS_TYPE}} enum {{ENUM_NAME}}: {{BASE_TYPE}}, {{ENUM_TYPE}} {";
"{{ACCESS_TYPE}} enum {{ENUM_NAME}}: "
"{{BASE_TYPE}}, FlatbuffersVectorInitializable, {{ENUM_TYPE}} {";
Indent();
code_ += "{{ACCESS_TYPE}} typealias T = {{BASE_TYPE}}";
if (enum_def.is_union) {
@@ -1481,10 +1428,9 @@ class SwiftGenerator : public BaseGenerator {
std::string code;
GenerateStructArgs(*field_type.struct_def, &code, "", "", "_o", true);
code = code.substr(0, code.size() - 2);
code_ += "for i in obj." + field + " {";
code_ += "for val in obj." + field + " {";
Indent();
code_ += "guard let _o = i else { continue }";
code_ += "builder.create(struct: _o)";
code_ += "builder.create(struct: val)";
Outdent();
code_ += "}";
code_ += "let __" + var + " = builder.endVector(len: obj." + field +
@@ -1636,23 +1582,24 @@ class SwiftGenerator : public BaseGenerator {
if (vectortype.base_type != BASE_TYPE_UTYPE) {
buffer_constructor.push_back(field_var + " = []");
buffer_constructor.push_back("for index in 0..<_t." + field_field +
"Count {");
base_constructor.push_back(field_var + " = []");
}
switch (vectortype.base_type) {
case BASE_TYPE_STRUCT: {
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) {
buffer_constructor.push_back(indentation + "var __v_ = _t." +
field_field + "(at: index)");
buffer_constructor.push_back("for var val in _t." + field_field +
"{");
buffer_constructor.push_back(indentation + field_var +
".append(__v_?.unpack())");
".append(val.unpack())");
buffer_constructor.push_back("}");
} else {
buffer_constructor.push_back(indentation + field_var + ".append(_t." +
field_var + "(at: index))");
buffer_constructor.push_back(field_var + ".append(contentsOf: _t." +
field_field + ")");
}
break;
}
@@ -1674,21 +1621,11 @@ class SwiftGenerator : public BaseGenerator {
(IsString(vectortype) ? "String?" : GenType(vectortype)));
code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: [{{VALUETYPE}}]";
if (IsEnum(vectortype) && vectortype.base_type != BASE_TYPE_UNION) {
const auto default_value = IsEnum(field.value.type)
? 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))");
buffer_constructor.push_back(field_var + ".append(contentsOf: _t." +
field_field + ")");
break;
}
}
if (vectortype.base_type != BASE_TYPE_UTYPE)
buffer_constructor.push_back("}");
}
void BuildUnionEnumSwitchCaseWritter(const EnumDef& ed) {
@@ -1720,9 +1657,17 @@ class SwiftGenerator : public BaseGenerator {
code_ += "{{ACCESS_TYPE}} var {{FIELDVAR}}: \\";
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" +
vector_reader + (is_vector ? ")" : "") + " {");
vector_reader + " {");
for (auto it = ed.Vals().begin(); it < ed.Vals().end(); ++it) {
const auto ev = **it;
@@ -1733,18 +1678,28 @@ class SwiftGenerator : public BaseGenerator {
const auto type = IsStruct(ev.union_type)
? GenType(ev.union_type) + Mutable()
: GenType(ev.union_type);
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 =
ns_type + "Union(_v?.unpack(), type: ." + variant + ")";
buffer_constructor.push_back(
indentation + " " + field +
(is_vector ? ".append(" + constructor + ")" : " = " + constructor));
if (is_vector) {
buffer_constructor.push_back(indentation + " var _v = _t." + field +
"(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 + "}");
if (is_vector) {
buffer_constructor.push_back("}");
}
}
void AddMinOrMaxEnumValue(const std::string& str, const std::string& type) {

View File

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

View File

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

View File

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

View File

@@ -17,7 +17,7 @@
import Foundation
#if canImport(Common)
import Common
import Common
#endif
/// Type aliases
@@ -28,7 +28,7 @@ public typealias VOffset = UInt16
/// Maximum size for a buffer
public let FlatBufferMaxSize =
UInt32
.max << ((MemoryLayout<SOffset>.size * 8 - 1) - 1)
.max << ((MemoryLayout<SOffset>.size * 8 - 1) - 1)
/// Protocol that All Scalars should conform to
///
@@ -36,28 +36,28 @@ public let FlatBufferMaxSize =
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() {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,7 +17,7 @@
import Foundation
#if canImport(Common)
import Common
import Common
#endif
/// 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
/// - Returns: returns the encoded sized ByteBuffer
public func serialize<T: ObjectAPIPacker>(type: T.Type) -> ByteBuffer
where T.T == Self {
where T.T == Self
{
var builder = FlatBufferBuilder(initialSize: 1024)
return serialize(builder: &builder, type: type.self)
}
@@ -42,8 +43,8 @@ extension NativeObject {
/// It can be considered less expensive in terms of memory allocation
public func serialize<T: ObjectAPIPacker>(
builder: inout FlatBufferBuilder,
type: T.Type
) -> ByteBuffer where T.T == Self {
type: T.Type) -> ByteBuffer where T.T == Self
{
var s = self
let root = type.pack(&builder, obj: &s)
builder.finish(offset: root)

View File

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

View File

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

View File

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

View File

@@ -17,7 +17,7 @@
import Foundation
#if canImport(Common)
import Common
import Common
#endif
/// `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.
/// - Parameter offset: Offset of the string
public func string(at offset: Int32) -> String? {
directString(at: 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
var offset = offset &+ position
offset &+= 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
@@ -91,24 +83,7 @@ public struct Table {
/// - type: Type of Element that needs to be read from the buffer
/// - o: Offset of the Element
public func readBuffer<T>(of type: T.Type, at o: Int32) -> T {
directRead(of: T.self, offset: 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))
bb.read(def: T.self, position: Int(o &+ position))
}
/// 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)))
}
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
/// This should only be used by `Scalars`
/// - Parameter off: Readable offset
@@ -144,14 +148,15 @@ public struct Table {
@inline(__always)
public func withUnsafePointerToSlice<T>(
at off: Int32,
body: (UnsafeRawBufferPointer) throws -> T
) rethrows -> T? {
body: (UnsafeRawBufferPointer, Int) throws -> T) rethrows -> T?
{
let o = offset(off)
guard o != 0 else { return nil }
let count = Int(vector(count: o))
return try bb.withUnsafePointerToSlice(
index: Int(vector(at: o)),
count: Int(vector(count: o)),
body: body)
count: count,
body: { try body($0, count) })
}
/// Vector count gets the count of Elements within the array
@@ -192,8 +197,8 @@ public struct Table {
static public func offset(
_ o: Int32,
vOffset: Int32,
fbb: inout FlatBufferBuilder
) -> Int32 {
fbb: inout FlatBufferBuilder) -> Int32
{
let vTable = Int32(fbb.capacity) &- o
return vTable
&+ Int32(
@@ -216,8 +221,8 @@ public struct Table {
static public func compare(
_ off1: Int32,
_ off2: Int32,
fbb: inout FlatBufferBuilder
) -> Int32 {
fbb: inout FlatBufferBuilder) -> Int32
{
let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1))
let _off2 = off2 &+ fbb.read(def: Int32.self, position: Int(off2))
@@ -246,8 +251,8 @@ public struct Table {
static public func compare(
_ off1: Int32,
_ key: [Byte],
fbb: inout FlatBufferBuilder
) -> Int32 {
fbb: inout FlatBufferBuilder) -> Int32
{
let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ 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(
_ o: Int32,
vOffset: Int32,
fbb: ByteBuffer
) -> Int32 {
fbb: ByteBuffer) -> Int32
{
let vTable = Int32(fbb.capacity) &- o
return vTable
&+ Int32(
@@ -298,8 +303,8 @@ public struct Table {
static public func compare(
_ off1: Int32,
_ off2: Int32,
fbb: ByteBuffer
) -> Int32 {
fbb: ByteBuffer) -> Int32
{
let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ fbb.read(def: Int32.self, position: Int(off1))
let _off2 = off2 &+ fbb.read(def: Int32.self, position: Int(off2))
@@ -328,8 +333,8 @@ public struct Table {
static public func compare(
_ off1: Int32,
_ key: [Byte],
fbb: ByteBuffer
) -> Int32 {
fbb: ByteBuffer) -> Int32
{
let memorySize = Int32(MemoryLayout<Int32>.size)
let _off1 = off1 &+ 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,
vtable: Int,
vtableLength: Int,
verifier: inout Verifier
) {
verifier: inout Verifier)
{
_position = position
_vtable = vtable
_vtableLength = vtableLength
@@ -84,8 +84,8 @@ public struct TableVerifier {
field: VOffset,
fieldName: String,
required: Bool,
type: T.Type
) throws where T: Verifiable {
type: T.Type) throws where T: Verifiable
{
let derefValue = try dereference(field)
if let value = derefValue {
@@ -115,9 +115,9 @@ public struct TableVerifier {
unionKeyName: String,
fieldName: String,
required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void
) throws
where T: UnionEnum {
completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
where T: UnionEnum
{
let keyPos = try dereference(key)
let valPos = try dereference(field)
@@ -131,7 +131,7 @@ public struct TableVerifier {
}
if let _key = keyPos,
let _val = valPos
let _val = valPos
{
/// verifiying that the key is within the buffer
try T.T.verify(&_verifier, at: _key, of: T.T.self)
@@ -172,14 +172,14 @@ public struct TableVerifier {
unionKeyName: String,
fieldName: String,
required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void
) throws
where T: UnionEnum {
completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
where T: UnionEnum
{
let keyVectorPosition = try dereference(key)
let offsetVectorPosition = try dereference(field)
if let keyPos = keyVectorPosition,
let valPos = offsetVectorPosition
let valPos = offsetVectorPosition
{
try UnionVector<T>.verify(
&_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,
maxTableCount: UOffset = 1_000_000,
maxApparentSize: UOffset = 1 << 31,
ignoreMissingNullTerminators: Bool = false
) {
ignoreMissingNullTerminators: Bool = false)
{
_maxDepth = maxDepth
_maxTableCount = maxTableCount
_maxApparentSize = maxApparentSize

View File

@@ -17,7 +17,7 @@
import Foundation
#if canImport(Common)
import Common
import Common
#endif
/// Verifiable is a protocol all swift flatbuffers object should conform to,
@@ -51,8 +51,8 @@ extension Verifiable {
@discardableResult
public static func verifyRange<T>(
_ verifier: inout Verifier,
at position: Int, of type: T.Type
) throws -> (start: Int, count: Int) {
at position: Int, of type: T.Type) throws -> (start: Int, count: Int)
{
let len: UOffset = try verifier.getValue(at: position)
let intLen = Int(len)
let start = Int(clamping: (position &+ MemoryLayout<Int32>.size).magnitude)
@@ -74,8 +74,8 @@ extension Verifiable where Self: Scalar {
public static func verify<T>(
_ verifier: inout Verifier,
at position: Int,
of type: T.Type
) throws where T: Verifiable {
of type: T.Type) throws where T: Verifiable
{
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>(
_ verifier: inout Verifier,
at position: Int,
of type: T.Type
) throws where T: Verifiable {
of type: T.Type) throws where T: Verifiable
{
let offset: UOffset = try verifier.getValue(at: position)
let nextOffset = Int(clamping: (Int(offset) &+ position).magnitude)
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>(
_ verifier: inout Verifier,
at position: Int,
of type: T.Type
) throws where T: Verifiable {
of type: T.Type) throws where T: Verifiable
{
/// 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
/// A fix will be appreciated
@@ -170,8 +170,8 @@ public enum UnionVector<S> where S: UnionEnum {
fieldPosition: Int,
unionKeyName: String,
fieldName: String,
completion: @escaping Completion
) throws {
completion: @escaping Completion) throws
{
/// Get offset for union key vectors and offset vectors
let keyOffset: UOffset = try verifier.getValue(at: keyPosition)
let fieldOffset: UOffset = try verifier.getValue(at: fieldPosition)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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