flatbuffers
242 строки · 13.9 Кб
1// automatically generated by the FlatBuffers compiler, do not modify
2// swiftlint:disable all
3// swiftformat:disable all
4
5import FlatBuffers
6
7public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
8public typealias T = Int8
9public static var byteSize: Int { return MemoryLayout<Int8>.size }
10public var value: Int8 { return self.rawValue }
11case red = 0
12case green = 1
13case blue = 2
14
15public static var max: MyGame_Sample_Color { return .blue }
16public static var min: MyGame_Sample_Color { return .red }
17}
18
19
20public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
21public typealias T = UInt8
22
23public init?(value: T) {
24self.init(rawValue: value)
25}
26
27public static var byteSize: Int { return MemoryLayout<UInt8>.size }
28public var value: UInt8 { return self.rawValue }
29case none_ = 0
30case weapon = 1
31
32public static var max: MyGame_Sample_Equipment { return .weapon }
33public static var min: MyGame_Sample_Equipment { return .none_ }
34}
35
36
37public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
38
39static func validateVersion() { FlatBuffersVersion_24_3_25() }
40
41private var _x: Float32
42private var _y: Float32
43private var _z: Float32
44
45public init(_ bb: ByteBuffer, o: Int32) {
46let _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
52public init(x: Float32, y: Float32, z: Float32) {
53_x = x
54_y = y
55_z = z
56}
57
58public init() {
59_x = 0.0
60_y = 0.0
61_z = 0.0
62}
63
64public var x: Float32 { _x }
65public var y: Float32 { _y }
66public var z: Float32 { _z }
67
68public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
69try verifier.inBuffer(position: position, of: MyGame_Sample_Vec3.self)
70}
71}
72
73public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
74
75static func validateVersion() { FlatBuffersVersion_24_3_25() }
76public var __buffer: ByteBuffer! { return _accessor.bb }
77private var _accessor: Struct
78
79public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
80
81public var x: Float32 { return _accessor.readBuffer(of: Float32.self, at: 0) }
82@discardableResult public func mutate(x: Float32) -> Bool { return _accessor.mutate(x, index: 0) }
83public var y: Float32 { return _accessor.readBuffer(of: Float32.self, at: 4) }
84@discardableResult public func mutate(y: Float32) -> Bool { return _accessor.mutate(y, index: 4) }
85public var z: Float32 { return _accessor.readBuffer(of: Float32.self, at: 8) }
86@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
87}
88
89public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
90
91static func validateVersion() { FlatBuffersVersion_24_3_25() }
92public var __buffer: ByteBuffer! { return _accessor.bb }
93private var _accessor: Table
94
95private init(_ t: Table) { _accessor = t }
96public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
97
98private enum VTOFFSET: VOffset {
99case pos = 4
100case mana = 6
101case hp = 8
102case name = 10
103case inventory = 14
104case color = 16
105case weapons = 18
106case equippedType = 20
107case equipped = 22
108case path = 24
109var v: Int32 { Int32(self.rawValue) }
110var p: VOffset { self.rawValue }
111}
112
113public var pos: MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Sample_Vec3.self, at: o) }
114public var mutablePos: MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: o + _accessor.postion) }
115public var mana: Int16 { let o = _accessor.offset(VTOFFSET.mana.v); return o == 0 ? 150 : _accessor.readBuffer(of: Int16.self, at: o) }
116@discardableResult public func mutate(mana: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.mana.v); return _accessor.mutate(mana, index: o) }
117public var hp: Int16 { let o = _accessor.offset(VTOFFSET.hp.v); return o == 0 ? 100 : _accessor.readBuffer(of: Int16.self, at: o) }
118@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
119public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
120public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
121public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
122public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
123public 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) }
124public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
125public 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) }
126public 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 }
127@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
128public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true }
129public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
130public 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)) }
131public 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_ }
132public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
133public var hasPath: Bool { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? false : true }
134public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
135public 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) }
136public 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) }
137public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 11) }
138public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
139public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) }
140public static func add(hp: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: hp, def: 100, at: VTOFFSET.hp.p) }
141public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
142public static func addVectorOf(inventory: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: inventory, at: VTOFFSET.inventory.p) }
143public static func add(color: MyGame_Sample_Color, _ fbb: inout FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 2, at: VTOFFSET.color.p) }
144public static func addVectorOf(weapons: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: weapons, at: VTOFFSET.weapons.p) }
145public static func add(equippedType: MyGame_Sample_Equipment, _ fbb: inout FlatBufferBuilder) { fbb.add(element: equippedType.rawValue, def: 0, at: VTOFFSET.equippedType.p) }
146public static func add(equipped: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: equipped, at: VTOFFSET.equipped.p) }
147public static func addVectorOf(path: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: path, at: VTOFFSET.path.p) }
148public static func startVectorOfPath(_ size: Int, in builder: inout FlatBufferBuilder) {
149builder.startVector(size * MemoryLayout<MyGame_Sample_Vec3>.size, elementSize: MemoryLayout<MyGame_Sample_Vec3>.alignment)
150}
151public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
152public static func createMonster(
153_ fbb: inout FlatBufferBuilder,
154pos: MyGame_Sample_Vec3? = nil,
155mana: Int16 = 150,
156hp: Int16 = 100,
157nameOffset name: Offset = Offset(),
158inventoryVectorOffset inventory: Offset = Offset(),
159color: MyGame_Sample_Color = .blue,
160weaponsVectorOffset weapons: Offset = Offset(),
161equippedType: MyGame_Sample_Equipment = .none_,
162equippedOffset equipped: Offset = Offset(),
163pathVectorOffset path: Offset = Offset()
164) -> Offset {
165let __start = MyGame_Sample_Monster.startMonster(&fbb)
166MyGame_Sample_Monster.add(pos: pos, &fbb)
167MyGame_Sample_Monster.add(mana: mana, &fbb)
168MyGame_Sample_Monster.add(hp: hp, &fbb)
169MyGame_Sample_Monster.add(name: name, &fbb)
170MyGame_Sample_Monster.addVectorOf(inventory: inventory, &fbb)
171MyGame_Sample_Monster.add(color: color, &fbb)
172MyGame_Sample_Monster.addVectorOf(weapons: weapons, &fbb)
173MyGame_Sample_Monster.add(equippedType: equippedType, &fbb)
174MyGame_Sample_Monster.add(equipped: equipped, &fbb)
175MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
176return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
177}
178
179public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
180var _v = try verifier.visitTable(at: position)
181try _v.visit(field: VTOFFSET.pos.p, fieldName: "pos", required: false, type: MyGame_Sample_Vec3.self)
182try _v.visit(field: VTOFFSET.mana.p, fieldName: "mana", required: false, type: Int16.self)
183try _v.visit(field: VTOFFSET.hp.p, fieldName: "hp", required: false, type: Int16.self)
184try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
185try _v.visit(field: VTOFFSET.inventory.p, fieldName: "inventory", required: false, type: ForwardOffset<Vector<UInt8, UInt8>>.self)
186try _v.visit(field: VTOFFSET.color.p, fieldName: "color", required: false, type: MyGame_Sample_Color.self)
187try _v.visit(field: VTOFFSET.weapons.p, fieldName: "weapons", required: false, type: ForwardOffset<Vector<ForwardOffset<MyGame_Sample_Weapon>, MyGame_Sample_Weapon>>.self)
188try _v.visit(unionKey: VTOFFSET.equippedType.p, unionField: VTOFFSET.equipped.p, unionKeyName: "equippedType", fieldName: "equipped", required: false, completion: { (verifier, key: MyGame_Sample_Equipment, pos) in
189switch key {
190case .none_:
191break // NOTE - SWIFT doesnt support none
192case .weapon:
193try ForwardOffset<MyGame_Sample_Weapon>.verify(&verifier, at: pos, of: MyGame_Sample_Weapon.self)
194}
195})
196try _v.visit(field: VTOFFSET.path.p, fieldName: "path", required: false, type: ForwardOffset<Vector<MyGame_Sample_Vec3, MyGame_Sample_Vec3>>.self)
197_v.finish()
198}
199}
200
201public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable {
202
203static func validateVersion() { FlatBuffersVersion_24_3_25() }
204public var __buffer: ByteBuffer! { return _accessor.bb }
205private var _accessor: Table
206
207private init(_ t: Table) { _accessor = t }
208public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
209
210private enum VTOFFSET: VOffset {
211case name = 4
212case damage = 6
213var v: Int32 { Int32(self.rawValue) }
214var p: VOffset { self.rawValue }
215}
216
217public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
218public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
219public var damage: Int16 { let o = _accessor.offset(VTOFFSET.damage.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int16.self, at: o) }
220@discardableResult public func mutate(damage: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.damage.v); return _accessor.mutate(damage, index: o) }
221public static func startWeapon(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) }
222public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
223public static func add(damage: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: damage, def: 0, at: VTOFFSET.damage.p) }
224public static func endWeapon(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
225public static func createWeapon(
226_ fbb: inout FlatBufferBuilder,
227nameOffset name: Offset = Offset(),
228damage: Int16 = 0
229) -> Offset {
230let __start = MyGame_Sample_Weapon.startWeapon(&fbb)
231MyGame_Sample_Weapon.add(name: name, &fbb)
232MyGame_Sample_Weapon.add(damage: damage, &fbb)
233return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
234}
235
236public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
237var _v = try verifier.visitTable(at: position)
238try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
239try _v.visit(field: VTOFFSET.damage.p, fieldName: "damage", required: false, type: Int16.self)
240_v.finish()
241}
242}
243
244