Skip to content

Commit

Permalink
Update generated code with the latest FlatBuffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Jun 10, 2022
1 parent 432407d commit 6520126
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dflatc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import subprocess
Expand Down
33 changes: 32 additions & 1 deletion src/tests/monster_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ public enum zzz_DflatGen_MyGame_Sample_Equipment: UInt8, UnionEnum {
public static var min: zzz_DflatGen_MyGame_Sample_Equipment { return .none_ }
}

public struct zzz_DflatGen_MyGame_Sample_Vec3: NativeStruct, Verifiable {
public struct zzz_DflatGen_MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {

static func validateVersion() { FlatBuffersVersion_2_0_0() }

private var _x: Float32
private var _y: Float32
private var _z: Float32

public init(_ bb: ByteBuffer, o: Int32) {
let _accessor = Struct(bb: bb, position: o)
_x = _accessor.readBuffer(of: Float32.self, at: 0)
_y = _accessor.readBuffer(of: Float32.self, at: 4)
_z = _accessor.readBuffer(of: Float32.self, at: 8)
}

public init(x: Float32, y: Float32, z: Float32) {
_x = x
_y = y
Expand Down Expand Up @@ -186,6 +193,10 @@ public struct zzz_DflatGen_MyGame_Sample_Monster: FlatBufferObject, Verifiable {
: zzz_DflatGen_MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o))
?? .blue
}
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)
Expand All @@ -196,6 +207,10 @@ public struct zzz_DflatGen_MyGame_Sample_Monster: FlatBufferObject, Verifiable {
? 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 hasBagType: Bool {
let o = _accessor.offset(VTOFFSET.bagType.v)
return o == 0 ? false : true
}
public var bagTypeCount: Int32 {
let o = _accessor.offset(VTOFFSET.bagType.v)
return o == 0 ? 0 : _accessor.vector(count: o)
Expand All @@ -207,6 +222,10 @@ public struct zzz_DflatGen_MyGame_Sample_Monster: FlatBufferObject, Verifiable {
: zzz_DflatGen_MyGame_Sample_Equipment(
rawValue: _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1))
}
public var hasBag: Bool {
let o = _accessor.offset(VTOFFSET.bag.v)
return o == 0 ? false : true
}
public var bagCount: Int32 {
let o = _accessor.offset(VTOFFSET.bag.v)
return o == 0 ? 0 : _accessor.vector(count: o)
Expand All @@ -215,6 +234,10 @@ public struct zzz_DflatGen_MyGame_Sample_Monster: FlatBufferObject, Verifiable {
let o = _accessor.offset(VTOFFSET.bag.v)
return o == 0 ? nil : _accessor.directUnion(_accessor.vector(at: o) + index * 4)
}
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)
Expand All @@ -237,6 +260,10 @@ public struct zzz_DflatGen_MyGame_Sample_Monster: FlatBufferObject, Verifiable {
let o = _accessor.offset(VTOFFSET.equipped.v)
return o == 0 ? nil : _accessor.union(o)
}
public var hasColors: Bool {
let o = _accessor.offset(VTOFFSET.colors.v)
return o == 0 ? false : true
}
public var colorsCount: Int32 {
let o = _accessor.offset(VTOFFSET.colors.v)
return o == 0 ? 0 : _accessor.vector(count: o)
Expand All @@ -248,6 +275,10 @@ public struct zzz_DflatGen_MyGame_Sample_Monster: FlatBufferObject, Verifiable {
: zzz_DflatGen_MyGame_Sample_Color(
rawValue: _accessor.directRead(of: Int8.self, offset: _accessor.vector(at: o) + index * 1))
}
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)
Expand Down
26 changes: 25 additions & 1 deletion src/tests/monster_v2_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ public enum zzz_DflatGen_MyGame_SampleV2_Equipment: UInt8, UnionEnum {
public static var min: zzz_DflatGen_MyGame_SampleV2_Equipment { return .none_ }
}

public struct zzz_DflatGen_MyGame_SampleV2_Vec3: NativeStruct, Verifiable {
public struct zzz_DflatGen_MyGame_SampleV2_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable
{

static func validateVersion() { FlatBuffersVersion_2_0_0() }

private var _x: Float32
private var _y: Float32
private var _z: Float32

public init(_ bb: ByteBuffer, o: Int32) {
let _accessor = Struct(bb: bb, position: o)
_x = _accessor.readBuffer(of: Float32.self, at: 0)
_y = _accessor.readBuffer(of: Float32.self, at: 4)
_z = _accessor.readBuffer(of: Float32.self, at: 8)
}

public init(x: Float32, y: Float32, z: Float32) {
_x = x
_y = y
Expand Down Expand Up @@ -171,6 +179,10 @@ public struct zzz_DflatGen_MyGame_SampleV2_Monster: FlatBufferObject, Verifiable
: zzz_DflatGen_MyGame_SampleV2_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o))
?? .blue
}
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)
Expand All @@ -181,6 +193,10 @@ public struct zzz_DflatGen_MyGame_SampleV2_Monster: FlatBufferObject, Verifiable
? 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 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)
Expand All @@ -203,6 +219,10 @@ public struct zzz_DflatGen_MyGame_SampleV2_Monster: FlatBufferObject, Verifiable
let o = _accessor.offset(VTOFFSET.equipped.v)
return o == 0 ? nil : _accessor.union(o)
}
public var hasColors: Bool {
let o = _accessor.offset(VTOFFSET.colors.v)
return o == 0 ? false : true
}
public var colorsCount: Int32 {
let o = _accessor.offset(VTOFFSET.colors.v)
return o == 0 ? 0 : _accessor.vector(count: o)
Expand All @@ -214,6 +234,10 @@ public struct zzz_DflatGen_MyGame_SampleV2_Monster: FlatBufferObject, Verifiable
: zzz_DflatGen_MyGame_SampleV2_Color(
rawValue: _accessor.directRead(of: Int8.self, offset: _accessor.vector(at: o) + index * 1))
}
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)
Expand Down
26 changes: 25 additions & 1 deletion src/tests/monster_v3_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ public enum zzz_DflatGen_MyGame_SampleV3_Equipment: UInt8, UnionEnum {
public static var min: zzz_DflatGen_MyGame_SampleV3_Equipment { return .none_ }
}

public struct zzz_DflatGen_MyGame_SampleV3_Vec3: NativeStruct, Verifiable {
public struct zzz_DflatGen_MyGame_SampleV3_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable
{

static func validateVersion() { FlatBuffersVersion_2_0_0() }

private var _x: Float32
private var _y: Float32
private var _z: Float32

public init(_ bb: ByteBuffer, o: Int32) {
let _accessor = Struct(bb: bb, position: o)
_x = _accessor.readBuffer(of: Float32.self, at: 0)
_y = _accessor.readBuffer(of: Float32.self, at: 4)
_z = _accessor.readBuffer(of: Float32.self, at: 8)
}

public init(x: Float32, y: Float32, z: Float32) {
_x = x
_y = y
Expand Down Expand Up @@ -171,6 +179,10 @@ public struct zzz_DflatGen_MyGame_SampleV3_Monster: FlatBufferObject, Verifiable
: zzz_DflatGen_MyGame_SampleV3_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o))
?? .blue
}
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)
Expand All @@ -181,6 +193,10 @@ public struct zzz_DflatGen_MyGame_SampleV3_Monster: FlatBufferObject, Verifiable
? 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 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)
Expand All @@ -203,6 +219,10 @@ public struct zzz_DflatGen_MyGame_SampleV3_Monster: FlatBufferObject, Verifiable
let o = _accessor.offset(VTOFFSET.equipped.v)
return o == 0 ? nil : _accessor.union(o)
}
public var hasColors: Bool {
let o = _accessor.offset(VTOFFSET.colors.v)
return o == 0 ? false : true
}
public var colorsCount: Int32 {
let o = _accessor.offset(VTOFFSET.colors.v)
return o == 0 ? 0 : _accessor.vector(count: o)
Expand All @@ -214,6 +234,10 @@ public struct zzz_DflatGen_MyGame_SampleV3_Monster: FlatBufferObject, Verifiable
: zzz_DflatGen_MyGame_SampleV3_Color(
rawValue: _accessor.directRead(of: Int8.self, offset: _accessor.vector(at: o) + index * 1))
}
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)
Expand Down

0 comments on commit 6520126

Please sign in to comment.