@@ -8,7 +8,7 @@ import Common
88
99import FlatBuffers
1010
11- public enum MyGame_Sample_Color : Int8 , Enum , Verifiable {
11+ public enum MyGame_Sample_Color : Int8 , FlatbuffersVectorInitializable , Enum , Verifiable {
1212 public typealias T = Int8
1313 public static var byteSize : Int { return MemoryLayout< Int8> . size }
1414 public var value : Int8 { return self . rawValue }
@@ -31,7 +31,7 @@ extension MyGame_Sample_Color: Encodable {
3131 }
3232}
3333
34- public enum MyGame_Sample_Equipment : UInt8 , UnionEnum {
34+ public enum MyGame_Sample_Equipment : UInt8 , FlatbuffersVectorInitializable , UnionEnum {
3535 public typealias T = UInt8
3636
3737 public init ? ( value: T ) {
@@ -73,7 +73,7 @@ public struct MyGame_Sample_EquipmentUnion {
7373 }
7474 }
7575}
76- public struct MyGame_Sample_Vec3 : NativeStruct , Verifiable , FlatbuffersInitializable , NativeObject {
76+ public struct MyGame_Sample_Vec3 : NativeStruct , FlatbuffersVectorInitializable , Verifiable , FlatbuffersInitializable , NativeObject {
7777
7878 static func validateVersion( ) { FlatBuffersVersion_25_9_23 ( ) }
7979
@@ -136,7 +136,7 @@ extension MyGame_Sample_Vec3: Encodable {
136136 }
137137}
138138
139- public struct MyGame_Sample_Vec3_Mutable : FlatBufferObject {
139+ public struct MyGame_Sample_Vec3_Mutable : FlatBufferStruct , FlatbuffersVectorInitializable {
140140
141141 static func validateVersion( ) { FlatBuffersVersion_25_9_23 ( ) }
142142 public var __buffer : ByteBuffer ! { return _accessor. bb }
@@ -165,7 +165,7 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
165165 }
166166}
167167
168- public struct MyGame_Sample_Monster : FlatBufferObject , Verifiable , ObjectAPIPacker {
168+ public struct MyGame_Sample_Monster : FlatBufferTable , FlatbuffersVectorInitializable , Verifiable , ObjectAPIPacker {
169169
170170 static func validateVersion( ) { FlatBuffersVersion_25_9_23 ( ) }
171171 public var __buffer : ByteBuffer ! { return _accessor. bb }
@@ -197,24 +197,17 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable, ObjectAPIPack
197197 @discardableResult public func mutate( hp: Int16 ) -> Bool { let o = _accessor. offset ( VTOFFSET . hp. v) ; return _accessor. mutate ( hp, index: o) }
198198 public var name : String ? { let o = _accessor. offset ( VTOFFSET . name. v) ; return o == 0 ? nil : _accessor. string ( at: o) }
199199 public var nameSegmentArray : [ UInt8 ] ? { return _accessor. getVector ( at: VTOFFSET . name. v) }
200- public var hasInventory : Bool { let o = _accessor. offset ( VTOFFSET . inventory. v) ; return o == 0 ? false : true }
201- public var inventoryCount : Int32 { let o = _accessor. offset ( VTOFFSET . inventory. v) ; return o == 0 ? 0 : _accessor. vector ( count: o) }
202- 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 ) }
203- public var inventory : [ UInt8 ] { return _accessor. getVector ( at: VTOFFSET . inventory. v) ?? [ ] }
200+ public var inventory : FlatbufferVector < UInt8 > { return _accessor. vector ( at: VTOFFSET . inventory. v, byteSize: 1 ) }
204201 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 ) }
205- public func withUnsafePointerToInventory< T> ( _ body: ( UnsafeRawBufferPointer ) throws -> T ) rethrows -> T ? { return try _accessor. withUnsafePointerToSlice ( at: VTOFFSET . inventory. v, body: body) }
202+ public func withUnsafePointerToInventory< T> ( _ body: ( UnsafeRawBufferPointer , Int ) throws -> T ) rethrows -> T ? { return try _accessor. withUnsafePointerToSlice ( at: VTOFFSET . inventory. v, body: body) }
206203 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 }
207204 @discardableResult public func mutate( color: MyGame_Sample_Color ) -> Bool { let o = _accessor. offset ( VTOFFSET . color. v) ; return _accessor. mutate ( color. rawValue, index: o) }
208- public var hasWeapons : Bool { let o = _accessor. offset ( VTOFFSET . weapons. v) ; return o == 0 ? false : true }
209- public var weaponsCount : Int32 { let o = _accessor. offset ( VTOFFSET . weapons. v) ; return o == 0 ? 0 : _accessor. vector ( count: o) }
210- 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 ) ) }
205+ public var weapons : FlatbufferVector < MyGame_Sample_Weapon > { return _accessor. vector ( at: VTOFFSET . weapons. v, byteSize: 4 ) }
211206 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_ }
212207 public func equipped< T: FlatbuffersInitializable > ( type: T . Type ) -> T ? { let o = _accessor. offset ( VTOFFSET . equipped. v) ; return o == 0 ? nil : _accessor. union ( o) }
213- public var hasPath : Bool { let o = _accessor. offset ( VTOFFSET . path. v) ; return o == 0 ? false : true }
214- public var pathCount : Int32 { let o = _accessor. offset ( VTOFFSET . path. v) ; return o == 0 ? 0 : _accessor. vector ( count: o) }
215- 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 ) }
216- 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 ) }
217- public func withUnsafePointerToPath< T> ( _ body: ( UnsafeRawBufferPointer ) throws -> T ) rethrows -> T ? { return try _accessor. withUnsafePointerToSlice ( at: VTOFFSET . path. v, body: body) }
208+ public var path : FlatbufferVector < MyGame_Sample_Vec3 > { return _accessor. vector ( at: VTOFFSET . path. v, byteSize: 12 ) }
209+ public var mutablePath : FlatbufferVector < MyGame_Sample_Vec3_Mutable > { return _accessor. vector ( at: VTOFFSET . path. v, byteSize: 12 ) }
210+ public func withUnsafePointerToPath< T> ( _ body: ( UnsafeRawBufferPointer , Int ) throws -> T ) rethrows -> T ? { return try _accessor. withUnsafePointerToSlice ( at: VTOFFSET . path. v, body: body) }
218211 public static func startMonster( _ fbb: inout FlatBufferBuilder ) -> UOffset { fbb. startTable ( with: 11 ) }
219212 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) }
220213 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
282275 let __weapons = builder. createVector ( ofOffsets: __weapons__)
283276 let __equipped = obj. equipped? . pack ( builder: & builder) ?? Offset ( )
284277 MyGame_Sample_Monster . startVectorOfPath ( obj. path. count, in: & builder)
285- for i in obj. path {
286- guard let _o = i else { continue }
287- builder. create ( struct: _o)
278+ for val in obj. path {
279+ builder. create ( struct: val)
288280 }
289281 let __path = builder. endVector ( len: obj. path. count)
290282 let __root = MyGame_Sample_Monster . startMonster ( & builder)
@@ -350,19 +342,11 @@ extension MyGame_Sample_Monster: Encodable {
350342 try container. encodeIfPresent ( hp, forKey: . hp)
351343 }
352344 try container. encodeIfPresent ( name, forKey: . name)
353- if inventoryCount > 0 {
354- try container. encodeIfPresent ( inventory, forKey: . inventory)
355- }
345+ try container. encodeIfPresent ( inventory, forKey: . inventory)
356346 if color != . blue {
357347 try container. encodeIfPresent ( color, forKey: . color)
358348 }
359- if weaponsCount > 0 {
360- var contentEncoder = container. nestedUnkeyedContainer ( forKey: . weapons)
361- for index in 0 ..< weaponsCount {
362- guard let type = weapons ( at: index) else { continue }
363- try contentEncoder. encode ( type)
364- }
365- }
349+ try container. encodeIfPresent ( weapons, forKey: . weapons)
366350 if equippedType != . none_ {
367351 try container. encodeIfPresent ( equippedType, forKey: . equippedType)
368352 }
@@ -372,13 +356,7 @@ extension MyGame_Sample_Monster: Encodable {
372356 try container. encodeIfPresent ( _v, forKey: . equipped)
373357 default : break ;
374358 }
375- if pathCount > 0 {
376- var contentEncoder = container. nestedUnkeyedContainer ( forKey: . path)
377- for index in 0 ..< pathCount {
378- guard let type = path ( at: index) else { continue }
379- try contentEncoder. encode ( type)
380- }
381- }
359+ try container. encodeIfPresent ( path, forKey: . path)
382360 }
383361}
384362
@@ -392,22 +370,19 @@ public class MyGame_Sample_MonsterT: NativeObject {
392370 public var color : MyGame_Sample_Color
393371 public var weapons : [ MyGame_Sample_WeaponT ? ]
394372 public var equipped : MyGame_Sample_EquipmentUnion ?
395- public var path : [ MyGame_Sample_Vec3 ? ]
373+ public var path : [ MyGame_Sample_Vec3 ]
396374
397375 public init ( _ _t: inout MyGame_Sample_Monster ) {
398376 pos = _t. pos
399377 mana = _t. mana
400378 hp = _t. hp
401379 name = _t. name
402380 inventory = [ ]
403- for index in 0 ..< _t. inventoryCount {
404- inventory. append ( _t. inventory ( at: index) )
405- }
381+ inventory. append ( contentsOf: _t. inventory)
406382 color = _t. color
407383 weapons = [ ]
408- for index in 0 ..< _t. weaponsCount {
409- var __v_ = _t. weapons ( at: index)
410- weapons. append ( __v_? . unpack ( ) )
384+ for var val in _t. weapons{
385+ weapons. append ( val. unpack ( ) )
411386 }
412387 switch _t. equippedType {
413388 case . weapon:
@@ -416,9 +391,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
416391 default : break
417392 }
418393 path = [ ]
419- for index in 0 ..< _t. pathCount {
420- path. append ( _t. path ( at: index) )
421- }
394+ path. append ( contentsOf: _t. path)
422395 }
423396
424397 public init ( ) {
@@ -434,7 +407,7 @@ public class MyGame_Sample_MonsterT: NativeObject {
434407 public func serialize( ) -> ByteBuffer { return serialize ( type: MyGame_Sample_Monster . self) }
435408
436409}
437- public struct MyGame_Sample_Weapon : FlatBufferObject , Verifiable , ObjectAPIPacker {
410+ public struct MyGame_Sample_Weapon : FlatBufferTable , FlatbuffersVectorInitializable , Verifiable , ObjectAPIPacker {
438411
439412 static func validateVersion( ) { FlatBuffersVersion_25_9_23 ( ) }
440413 public var __buffer : ByteBuffer ! { return _accessor. bb }
0 commit comments