[Swift] Moves VTs from enums to structs to prevent empty enum generation

Moves VTs from enums to structs to prevent empty enum generation, which would usually cause a compilation error.
This commit is contained in:
mustiikhalil
2026-02-12 19:04:26 +01:00
committed by GitHub
parent c21bda1649
commit fcf75449b8
18 changed files with 1328 additions and 1289 deletions

View File

@@ -84,13 +84,13 @@ public struct MyGame_Example_NestedStruct: NativeStruct, FlatbuffersVectorInitia
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *)
extension MyGame_Example_NestedStruct: Encodable {
enum CodingKeys: String, CodingKey {
case a = "a"
case b = "b"
case c = "c"
case d = "d"
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
var aContainer = container.nestedUnkeyedContainer(forKey: .a)
@@ -206,7 +206,6 @@ public struct MyGame_Example_ArrayStruct: NativeStruct, FlatbuffersVectorInitial
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *)
extension MyGame_Example_ArrayStruct: Encodable {
enum CodingKeys: String, CodingKey {
case a = "a"
case b = "b"
@@ -215,6 +214,7 @@ extension MyGame_Example_ArrayStruct: Encodable {
case e = "e"
case f = "f"
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
if a != 0.0 {
@@ -287,16 +287,14 @@ public struct MyGame_Example_ArrayTable: FlatBufferTable, FlatbuffersVectorIniti
private init(_ t: Table) { _accessor = t }
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
private enum VTOFFSET: VOffset {
case a = 4
var v: Int32 { Int32(self.rawValue) }
var p: VOffset { self.rawValue }
private struct VT {
static let a: VOffset = 4
}
public var a: MyGame_Example_ArrayStruct? { let o = _accessor.offset(VTOFFSET.a.v); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Example_ArrayStruct.self, at: o) }
public var mutableA: MyGame_Example_ArrayStruct_Mutable? { let o = _accessor.offset(VTOFFSET.a.v); return o == 0 ? nil : MyGame_Example_ArrayStruct_Mutable(_accessor.bb, o: o + _accessor.position) }
public var a: MyGame_Example_ArrayStruct? { let o = _accessor.offset(VT.a); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Example_ArrayStruct.self, at: o) }
public var mutableA: MyGame_Example_ArrayStruct_Mutable? { let o = _accessor.offset(VT.a); return o == 0 ? nil : MyGame_Example_ArrayStruct_Mutable(_accessor.bb, o: o + _accessor.position) }
public static func startArrayTable(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
public static func add(a: MyGame_Example_ArrayStruct?, _ fbb: inout FlatBufferBuilder) { guard let a = a else { return }; fbb.create(struct: a, position: VTOFFSET.a.p) }
public static func add(a: MyGame_Example_ArrayStruct?, _ fbb: inout FlatBufferBuilder) { guard let a = a else { return }; fbb.create(struct: a, position: VT.a) }
public static func endArrayTable(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
public static func createArrayTable(
_ fbb: inout FlatBufferBuilder,
@@ -323,17 +321,17 @@ public struct MyGame_Example_ArrayTable: FlatBufferTable, FlatbuffersVectorIniti
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
var _v = try verifier.visitTable(at: position)
try _v.visit(field: VTOFFSET.a.p, fieldName: "a", required: false, type: MyGame_Example_ArrayStruct.self)
try _v.visit(field: VT.a, fieldName: "a", required: false, type: MyGame_Example_ArrayStruct.self)
_v.finish()
}
}
@available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *)
extension MyGame_Example_ArrayTable: Encodable {
enum CodingKeys: String, CodingKey {
case a = "a"
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(a, forKey: .a)