44
55import FlatBuffers
66
7- public enum MyGame_Sample_Color : Int8 , Enum {
7+ public enum MyGame_Sample_Color : Int8 , Enum , Verifiable {
88 public typealias T = Int8
99 public static var byteSize : Int { return MemoryLayout< Int8> . size }
1010 public var value : Int8 { return self . rawValue }
1111 case red = 0
1212 case green = 1
1313 case blue = 2
1414
15-
1615 public static var max : MyGame_Sample_Color { return . blue }
1716 public static var min : MyGame_Sample_Color { return . red }
1817}
1918
20- public enum MyGame_Sample_Equipment : UInt8 , Enum {
19+
20+ public enum MyGame_Sample_Equipment : UInt8 , UnionEnum {
2121 public typealias T = UInt8
22+
23+ public init ? ( value: T ) {
24+ self . init ( rawValue: value)
25+ }
26+
2227 public static var byteSize : Int { return MemoryLayout< UInt8> . size }
2328 public var value : UInt8 { return self . rawValue }
2429 case none_ = 0
2530 case weapon = 1
2631
27-
2832 public static var max : MyGame_Sample_Equipment { return . weapon }
2933 public static var min : MyGame_Sample_Equipment { return . none_ }
3034}
3135
32- public struct MyGame_Sample_Vec3 : NativeStruct {
36+
37+ public struct MyGame_Sample_Vec3 : NativeStruct , Verifiable , FlatbuffersInitializable {
3338
3439 static func validateVersion( ) { FlatBuffersVersion_23_1_4 ( ) }
3540
3641 private var _x : Float32
3742 private var _y : Float32
3843 private var _z : Float32
3944
45+ public init ( _ bb: ByteBuffer , o: Int32 ) {
46+ let _accessor = Struct ( bb: bb, position: o)
47+ _x = _accessor. readBuffer ( of: Float32 . self, at: 0 )
48+ _y = _accessor. readBuffer ( of: Float32 . self, at: 4 )
49+ _z = _accessor. readBuffer ( of: Float32 . self, at: 8 )
50+ }
51+
4052 public init ( x: Float32 , y: Float32 , z: Float32 ) {
4153 _x = x
4254 _y = y
@@ -52,6 +64,10 @@ public struct MyGame_Sample_Vec3: NativeStruct {
5264 public var x : Float32 { _x }
5365 public var y : Float32 { _y }
5466 public var z : Float32 { _z }
67+
68+ public static func verify< T> ( _ verifier: inout Verifier , at position: Int , of type: T . Type ) throws where T: Verifiable {
69+ try verifier. inBuffer ( position: position, of: MyGame_Sample_Vec3 . self)
70+ }
5571}
5672
5773public struct MyGame_Sample_Vec3_Mutable : FlatBufferObject {
@@ -70,14 +86,12 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
7086 @discardableResult public func mutate( z: Float32 ) -> Bool { return _accessor. mutate ( z, index: 8 ) }
7187}
7288
73- public struct MyGame_Sample_Monster : FlatBufferObject {
89+ public struct MyGame_Sample_Monster : FlatBufferObject , Verifiable {
7490
7591 static func validateVersion( ) { FlatBuffersVersion_23_1_4 ( ) }
7692 public var __buffer : ByteBuffer ! { return _accessor. bb }
7793 private var _accessor : Table
7894
79- public static func getRootAsMonster( bb: ByteBuffer ) -> MyGame_Sample_Monster { return MyGame_Sample_Monster ( Table ( bb: bb, position: Int32 ( bb. read ( def: UOffset . self, position: bb. reader) ) + Int32( bb. reader) ) ) }
80-
8195 private init ( _ t: Table ) { _accessor = t }
8296 public init ( _ bb: ByteBuffer , o: Int32 ) { _accessor = Table ( bb: bb, position: o) }
8397
@@ -104,16 +118,19 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
104118 @discardableResult public func mutate( hp: Int16 ) -> Bool { let o = _accessor. offset ( VTOFFSET . hp. v) ; return _accessor. mutate ( hp, index: o) }
105119 public var name : String ? { let o = _accessor. offset ( VTOFFSET . name. v) ; return o == 0 ? nil : _accessor. string ( at: o) }
106120 public var nameSegmentArray : [ UInt8 ] ? { return _accessor. getVector ( at: VTOFFSET . name. v) }
121+ public var hasInventory : Bool { let o = _accessor. offset ( VTOFFSET . inventory. v) ; return o == 0 ? false : true }
107122 public var inventoryCount : Int32 { let o = _accessor. offset ( VTOFFSET . inventory. v) ; return o == 0 ? 0 : _accessor. vector ( count: o) }
108123 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 ) }
109124 public var inventory : [ UInt8 ] { return _accessor. getVector ( at: VTOFFSET . inventory. v) ?? [ ] }
110125 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 ) }
111126 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 }
112127 @discardableResult public func mutate( color: MyGame_Sample_Color ) -> Bool { let o = _accessor. offset ( VTOFFSET . color. v) ; return _accessor. mutate ( color. rawValue, index: o) }
128+ public var hasWeapons : Bool { let o = _accessor. offset ( VTOFFSET . weapons. v) ; return o == 0 ? false : true }
113129 public var weaponsCount : Int32 { let o = _accessor. offset ( VTOFFSET . weapons. v) ; return o == 0 ? 0 : _accessor. vector ( count: o) }
114130 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 ) ) }
115131 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_ }
116132 public func equipped< T: FlatbuffersInitializable > ( type: T . Type ) -> T ? { let o = _accessor. offset ( VTOFFSET . equipped. v) ; return o == 0 ? nil : _accessor. union ( o) }
133+ public var hasPath : Bool { let o = _accessor. offset ( VTOFFSET . path. v) ; return o == 0 ? false : true }
117134 public var pathCount : Int32 { let o = _accessor. offset ( VTOFFSET . path. v) ; return o == 0 ? 0 : _accessor. vector ( count: o) }
118135 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 ) }
119136 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 ) }
@@ -158,16 +175,35 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
158175 MyGame_Sample_Monster . addVectorOf ( path: path, & fbb)
159176 return MyGame_Sample_Monster . endMonster ( & fbb, start: __start)
160177 }
178+
179+ public static func verify< T> ( _ verifier: inout Verifier , at position: Int , of type: T . Type ) throws where T: Verifiable {
180+ var _v = try verifier. visitTable ( at: position)
181+ try _v. visit ( field: VTOFFSET . pos. p, fieldName: " pos " , required: false , type: MyGame_Sample_Vec3 . self)
182+ try _v. visit ( field: VTOFFSET . mana. p, fieldName: " mana " , required: false , type: Int16 . self)
183+ try _v. visit ( field: VTOFFSET . hp. p, fieldName: " hp " , required: false , type: Int16 . self)
184+ try _v. visit ( field: VTOFFSET . name. p, fieldName: " name " , required: false , type: ForwardOffset< String> . self )
185+ try _v. visit ( field: VTOFFSET . inventory. p, fieldName: " inventory " , required: false , type: ForwardOffset< Vector< UInt8, UInt8>>. self )
186+ try _v. visit ( field: VTOFFSET . color. p, fieldName: " color " , required: false , type: MyGame_Sample_Color . self)
187+ try _v. visit ( field: VTOFFSET . weapons. p, fieldName: " weapons " , required: false , type: ForwardOffset < Vector < ForwardOffset < MyGame_Sample_Weapon > , MyGame_Sample_Weapon > > . self)
188+ try _v. visit ( unionKey: VTOFFSET . equippedType. p, unionField: VTOFFSET . equipped. p, unionKeyName: " equippedType " , fieldName: " equipped " , required: false , completion: { ( verifier, key: MyGame_Sample_Equipment , pos) in
189+ switch key {
190+ case . none_:
191+ break // NOTE - SWIFT doesnt support none
192+ case . weapon:
193+ try ForwardOffset< MyGame_Sample_Weapon> . verify( & verifier, at: pos, of: MyGame_Sample_Weapon . self)
194+ }
195+ } )
196+ try _v. visit ( field: VTOFFSET . path. p, fieldName: " path " , required: false , type: ForwardOffset< Vector< MyGame_Sample_Vec3, MyGame_Sample_Vec3>>. self )
197+ _v. finish ( )
198+ }
161199}
162200
163- public struct MyGame_Sample_Weapon : FlatBufferObject {
201+ public struct MyGame_Sample_Weapon : FlatBufferObject , Verifiable {
164202
165203 static func validateVersion( ) { FlatBuffersVersion_23_1_4 ( ) }
166204 public var __buffer : ByteBuffer ! { return _accessor. bb }
167205 private var _accessor : Table
168206
169- public static func getRootAsWeapon( bb: ByteBuffer ) -> MyGame_Sample_Weapon { return MyGame_Sample_Weapon ( Table ( bb: bb, position: Int32 ( bb. read ( def: UOffset . self, position: bb. reader) ) + Int32( bb. reader) ) ) }
170-
171207 private init ( _ t: Table ) { _accessor = t }
172208 public init ( _ bb: ByteBuffer , o: Int32 ) { _accessor = Table ( bb: bb, position: o) }
173209
@@ -196,5 +232,12 @@ public struct MyGame_Sample_Weapon: FlatBufferObject {
196232 MyGame_Sample_Weapon . add ( damage: damage, & fbb)
197233 return MyGame_Sample_Weapon . endWeapon ( & fbb, start: __start)
198234 }
235+
236+ public static func verify< T> ( _ verifier: inout Verifier , at position: Int , of type: T . Type ) throws where T: Verifiable {
237+ var _v = try verifier. visitTable ( at: position)
238+ try _v. visit ( field: VTOFFSET . name. p, fieldName: " name " , required: false , type: ForwardOffset< String> . self )
239+ try _v. visit ( field: VTOFFSET . damage. p, fieldName: " damage " , required: false , type: Int16 . self)
240+ _v. finish ( )
241+ }
199242}
200243
0 commit comments