forked from BigfootDev/flatbuffers
Removes Dead code & regenerate code (#7744)
Formats the swift project Update Sample files Update docc documentation Updates swift docs in the website Updates code for Wasm
This commit is contained in:
@@ -32,6 +32,6 @@ let package = Package(
|
|||||||
.target(
|
.target(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
path: "swift/Sources")
|
path: "swift/Sources"),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,10 @@ Now you can access values like this:
|
|||||||
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
|
var byteBuffer = ByteBuffer(bytes: data)
|
||||||
|
// Get an accessor to the root object inside the buffer.
|
||||||
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
|
|
||||||
if !monster.mutate(hp: 10) {
|
if !monster.mutate(hp: 10) {
|
||||||
fatalError("couldn't mutate")
|
fatalError("couldn't mutate")
|
||||||
|
|||||||
@@ -2472,10 +2472,10 @@ myGame.Monster monster = new myGame.Monster(data);
|
|||||||
<div class="language-swift">
|
<div class="language-swift">
|
||||||
~~~{.swift}
|
~~~{.swift}
|
||||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||||
let buf = // Get your data
|
var buf = // Get your data
|
||||||
|
|
||||||
// Get an accessor to the root object inside the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ public struct models_HelloReply: FlatBufferObject, Verifiable {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsHelloReply(bb: ByteBuffer) -> models_HelloReply { return models_HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -59,8 +57,6 @@ public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsHelloRequest(bb: ByteBuffer) -> models_HelloRequest { return models_HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import FlatBuffers
|
import FlatBuffers
|
||||||
|
|
||||||
public enum MyGame_Sample_Color: Int8, Enum {
|
public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
|
||||||
public typealias T = Int8
|
public typealias T = Int8
|
||||||
public static var byteSize: Int { return MemoryLayout<Int8>.size }
|
public static var byteSize: Int { return MemoryLayout<Int8>.size }
|
||||||
public var value: Int8 { return self.rawValue }
|
public var value: Int8 { return self.rawValue }
|
||||||
@@ -12,24 +12,29 @@ public enum MyGame_Sample_Color: Int8, Enum {
|
|||||||
case green = 1
|
case green = 1
|
||||||
case blue = 2
|
case blue = 2
|
||||||
|
|
||||||
|
|
||||||
public static var max: MyGame_Sample_Color { return .blue }
|
public static var max: MyGame_Sample_Color { return .blue }
|
||||||
public static var min: MyGame_Sample_Color { return .red }
|
public static var min: MyGame_Sample_Color { return .red }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MyGame_Sample_Equipment: UInt8, Enum {
|
|
||||||
|
public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
|
||||||
public typealias T = UInt8
|
public typealias T = UInt8
|
||||||
|
|
||||||
|
public init?(value: T) {
|
||||||
|
self.init(rawValue: value)
|
||||||
|
}
|
||||||
|
|
||||||
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
|
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
|
||||||
public var value: UInt8 { return self.rawValue }
|
public var value: UInt8 { return self.rawValue }
|
||||||
case none_ = 0
|
case none_ = 0
|
||||||
case weapon = 1
|
case weapon = 1
|
||||||
|
|
||||||
|
|
||||||
public static var max: MyGame_Sample_Equipment { return .weapon }
|
public static var max: MyGame_Sample_Equipment { return .weapon }
|
||||||
public static var min: MyGame_Sample_Equipment { return .none_ }
|
public static var min: MyGame_Sample_Equipment { return .none_ }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MyGame_Sample_Vec3: NativeStruct {
|
|
||||||
|
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||||
|
|
||||||
@@ -37,6 +42,13 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
|||||||
private var _y: Float32
|
private var _y: Float32
|
||||||
private var _z: 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) {
|
public init(x: Float32, y: Float32, z: Float32) {
|
||||||
_x = x
|
_x = x
|
||||||
_y = y
|
_y = y
|
||||||
@@ -52,6 +64,10 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
|||||||
public var x: Float32 { _x }
|
public var x: Float32 { _x }
|
||||||
public var y: Float32 { _y }
|
public var y: Float32 { _y }
|
||||||
public var z: Float32 { _z }
|
public var z: Float32 { _z }
|
||||||
|
|
||||||
|
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||||
|
try verifier.inBuffer(position: position, of: MyGame_Sample_Vec3.self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||||
@@ -70,14 +86,12 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
|||||||
@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
|
@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MyGame_Sample_Monster: FlatBufferObject {
|
public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
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))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -104,16 +118,19 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
|||||||
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
|
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
|
||||||
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
|
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
|
||||||
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
|
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
|
||||||
|
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) }
|
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||||
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) }
|
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) }
|
||||||
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
|
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
|
||||||
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) }
|
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) }
|
||||||
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 }
|
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 }
|
||||||
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
|
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
|
||||||
|
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) }
|
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||||
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)) }
|
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)) }
|
||||||
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_ }
|
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_ }
|
||||||
public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
|
public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
|
||||||
|
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) }
|
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||||
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) }
|
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) }
|
||||||
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) }
|
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 {
|
|||||||
MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
|
MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
|
||||||
return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
|
return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.pos.p, fieldName: "pos", required: false, type: MyGame_Sample_Vec3.self)
|
||||||
|
try _v.visit(field: VTOFFSET.mana.p, fieldName: "mana", required: false, type: Int16.self)
|
||||||
|
try _v.visit(field: VTOFFSET.hp.p, fieldName: "hp", required: false, type: Int16.self)
|
||||||
|
try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||||
|
try _v.visit(field: VTOFFSET.inventory.p, fieldName: "inventory", required: false, type: ForwardOffset<Vector<UInt8, UInt8>>.self)
|
||||||
|
try _v.visit(field: VTOFFSET.color.p, fieldName: "color", required: false, type: MyGame_Sample_Color.self)
|
||||||
|
try _v.visit(field: VTOFFSET.weapons.p, fieldName: "weapons", required: false, type: ForwardOffset<Vector<ForwardOffset<MyGame_Sample_Weapon>, MyGame_Sample_Weapon>>.self)
|
||||||
|
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
|
||||||
|
switch key {
|
||||||
|
case .none_:
|
||||||
|
break // NOTE - SWIFT doesnt support none
|
||||||
|
case .weapon:
|
||||||
|
try ForwardOffset<MyGame_Sample_Weapon>.verify(&verifier, at: pos, of: MyGame_Sample_Weapon.self)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
try _v.visit(field: VTOFFSET.path.p, fieldName: "path", required: false, type: ForwardOffset<Vector<MyGame_Sample_Vec3, MyGame_Sample_Vec3>>.self)
|
||||||
|
_v.finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MyGame_Sample_Weapon: FlatBufferObject {
|
public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
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))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -196,5 +232,12 @@ public struct MyGame_Sample_Weapon: FlatBufferObject {
|
|||||||
MyGame_Sample_Weapon.add(damage: damage, &fbb)
|
MyGame_Sample_Weapon.add(damage: damage, &fbb)
|
||||||
return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
|
return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||||
|
try _v.visit(field: VTOFFSET.damage.p, fieldName: "damage", required: false, type: Int16.self)
|
||||||
|
_v.finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -56,8 +56,8 @@ func main() {
|
|||||||
equippedOffset: axe)
|
equippedOffset: axe)
|
||||||
builder.finish(offset: orc)
|
builder.finish(offset: orc)
|
||||||
|
|
||||||
let buf = builder.sizedByteArray
|
var buf = ByteBuffer(bytes: builder.sizedByteArray)
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &buffer)
|
||||||
|
|
||||||
assert(monster.mana == 150)
|
assert(monster.mana == 150)
|
||||||
assert(monster.hp == 300)
|
assert(monster.hp == 300)
|
||||||
|
|||||||
@@ -470,6 +470,15 @@ flatc(
|
|||||||
cwd=swift_code_gen
|
cwd=swift_code_gen
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Swift Wasm Tests
|
||||||
|
swift_Wasm_prefix = "swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests"
|
||||||
|
flatc(
|
||||||
|
SWIFT_OPTS + BASE_OPTS,
|
||||||
|
schema="monster_test.fbs",
|
||||||
|
include="include_test",
|
||||||
|
prefix=swift_Wasm_prefix,
|
||||||
|
)
|
||||||
|
|
||||||
# Nim Tests
|
# Nim Tests
|
||||||
NIM_OPTS = BASE_OPTS + ["--nim"]
|
NIM_OPTS = BASE_OPTS + ["--nim"]
|
||||||
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
||||||
|
|||||||
@@ -483,12 +483,6 @@ class SwiftGenerator : public BaseGenerator {
|
|||||||
"fileId: "
|
"fileId: "
|
||||||
"{{STRUCTNAME}}.id, addPrefix: prefix) }";
|
"{{STRUCTNAME}}.id, addPrefix: prefix) }";
|
||||||
}
|
}
|
||||||
code_ +=
|
|
||||||
"{{ACCESS_TYPE}} static func getRootAs{{SHORT_STRUCTNAME}}(bb: "
|
|
||||||
"ByteBuffer) -> "
|
|
||||||
"{{STRUCTNAME}} { return {{STRUCTNAME}}(Table(bb: bb, position: "
|
|
||||||
"Int32(bb.read(def: UOffset.self, position: bb.reader)) + "
|
|
||||||
"Int32(bb.reader))) }\n";
|
|
||||||
code_ += "private init(_ t: Table) { {{ACCESS}} = t }";
|
code_ += "private init(_ t: Table) { {{ACCESS}} = t }";
|
||||||
}
|
}
|
||||||
code_ +=
|
code_ +=
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
--swiftversion 5.1
|
--swiftversion 5.7
|
||||||
|
|
||||||
# format
|
# format
|
||||||
--indent 2
|
--indent 2
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -429,13 +429,13 @@ public struct ByteBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the written bytes into the ``ByteBuffer``
|
/// Returns the written bytes into the ``ByteBuffer``
|
||||||
public var underlyingBytes: [UInt8] {
|
public var underlyingBytes: [UInt8] {
|
||||||
let cp = capacity &- writerIndex
|
let cp = capacity &- writerIndex
|
||||||
let start = memory.advanced(by: writerIndex)
|
let start = memory.advanced(by: writerIndex)
|
||||||
.bindMemory(to: UInt8.self, capacity: cp)
|
.bindMemory(to: UInt8.self, capacity: cp)
|
||||||
|
|
||||||
let ptr = UnsafeBufferPointer<UInt8>(start: start, count: cp)
|
let ptr = UnsafeBufferPointer<UInt8>(start: start, count: cp)
|
||||||
return Array(ptr)
|
return Array(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SkipPrefix Skips the first 4 bytes in case one of the following
|
/// SkipPrefix Skips the first 4 bytes in case one of the following
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,11 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if !os(WASI)
|
#if !os(WASI)
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
import CoreFoundation
|
import CoreFoundation
|
||||||
#else
|
#else
|
||||||
import Foundation
|
import Foundation
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
import SwiftOverlayShims
|
import SwiftOverlayShims
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import Foundation
|
|||||||
func run() {
|
func run() {
|
||||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||||
let buf = [] // Get your data
|
let buf = [] // Get your data
|
||||||
|
var byteBuffer = ByteBuffer(bytes: buf)
|
||||||
// Get an accessor to the root object inside the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
// let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import Foundation
|
|||||||
func run() {
|
func run() {
|
||||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||||
let buf = [] // Get your data
|
let buf = [] // Get your data
|
||||||
|
var byteBuffer = ByteBuffer(bytes: buf)
|
||||||
// Get an accessor to the root object inside the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
// let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
|
|
||||||
let hp = monster.hp
|
let hp = monster.hp
|
||||||
let mana = monster.mana
|
let mana = monster.mana
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import Foundation
|
|||||||
func run() {
|
func run() {
|
||||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||||
let buf = [] // Get your data
|
let buf = [] // Get your data
|
||||||
|
var byteBuffer = ByteBuffer(bytes: buf)
|
||||||
// Get an accessor to the root object inside the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
let monster: Monster = try! getCheckedRoot(byteBuffer: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
// let monster: Monster = getRoot(byteBuffer: ByteBuffer(bytes: buf))
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
|
|
||||||
let hp = monster.hp
|
let hp = monster.hp
|
||||||
let mana = monster.mana
|
let mana = monster.mana
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -66,12 +66,12 @@ public enum FlatbuffersErrors: Error, Equatable {
|
|||||||
#if !os(WASI)
|
#if !os(WASI)
|
||||||
|
|
||||||
extension FlatbuffersErrors {
|
extension FlatbuffersErrors {
|
||||||
public static func == (
|
public static func == (
|
||||||
lhs: FlatbuffersErrors,
|
lhs: FlatbuffersErrors,
|
||||||
rhs: FlatbuffersErrors) -> Bool
|
rhs: FlatbuffersErrors) -> Bool
|
||||||
{
|
{
|
||||||
lhs.localizedDescription == rhs.localizedDescription
|
lhs.localizedDescription == rhs.localizedDescription
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
1
tests/swift/Wasm.tests/.swift-version
Normal file
1
tests/swift/Wasm.tests/.swift-version
Normal file
@@ -0,0 +1 @@
|
|||||||
|
wasm-5.7-SNAPSHOT-2022-09-24-a
|
||||||
@@ -30,5 +30,5 @@ let package = Package(
|
|||||||
name: "Wasm"),
|
name: "Wasm"),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "FlatBuffers.Test.Swift.WasmTests",
|
name: "FlatBuffers.Test.Swift.WasmTests",
|
||||||
dependencies: ["FlatBuffers"])
|
dependencies: ["FlatBuffers"]),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
public struct Wasm {}
|
public struct Wasm {}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -38,7 +38,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
|
XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
|
||||||
// swiftformat:enable all
|
// swiftformat:enable all
|
||||||
let monster = MyGame_Example_Monster.getRootAsMonster(bb: bytes.buffer)
|
var buffer = bytes.buffer
|
||||||
|
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||||
readMonster(monster: monster)
|
readMonster(monster: monster)
|
||||||
mutateMonster(fb: bytes.buffer)
|
mutateMonster(fb: bytes.buffer)
|
||||||
readMonster(monster: monster)
|
readMonster(monster: monster)
|
||||||
@@ -69,7 +70,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
Monster.add(name: name, &fbb)
|
Monster.add(name: name, &fbb)
|
||||||
let root = Monster.endMonster(&fbb, start: mStart)
|
let root = Monster.endMonster(&fbb, start: mStart)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
|
var buffer = fbb.sizedBuffer
|
||||||
|
let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertNil(newMonster.pos)
|
XCTAssertNil(newMonster.pos)
|
||||||
XCTAssertEqual(newMonster.name, "Frodo")
|
XCTAssertEqual(newMonster.name, "Frodo")
|
||||||
}
|
}
|
||||||
@@ -91,7 +93,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
let root = Monster.endMonster(&fbb, start: mStart)
|
let root = Monster.endMonster(&fbb, start: mStart)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
|
|
||||||
let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
|
var buffer = fbb.sizedBuffer
|
||||||
|
let newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(newMonster.pos!.x, 10)
|
XCTAssertEqual(newMonster.pos!.x, 10)
|
||||||
XCTAssertEqual(newMonster.name, "Barney")
|
XCTAssertEqual(newMonster.name, "Barney")
|
||||||
}
|
}
|
||||||
@@ -106,7 +109,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
nameOffset: name,
|
nameOffset: name,
|
||||||
testarrayofboolsVectorOffset: bools)
|
testarrayofboolsVectorOffset: bools)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
let monster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
|
var buffer = fbb.sizedBuffer
|
||||||
|
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||||
|
|
||||||
let values = monster.testarrayofbools
|
let values = monster.testarrayofbools
|
||||||
|
|
||||||
@@ -130,9 +134,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
readFlatbufferMonster(monster: &monster)
|
readFlatbufferMonster(monster: &monster)
|
||||||
let unpacked: MyGame_Example_MonsterT? = monster.unpack()
|
let unpacked: MyGame_Example_MonsterT? = monster.unpack()
|
||||||
readObjectApi(monster: unpacked!)
|
readObjectApi(monster: unpacked!)
|
||||||
guard let buffer = unpacked?.serialize()
|
guard var buffer = unpacked?.serialize()
|
||||||
else { fatalError("Couldnt generate bytebuffer") }
|
else { fatalError("Couldnt generate bytebuffer") }
|
||||||
var newMonster = Monster.getRootAsMonster(bb: buffer)
|
var newMonster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||||
readFlatbufferMonster(monster: &newMonster)
|
readFlatbufferMonster(monster: &newMonster)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +202,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mutateMonster(fb: ByteBuffer) {
|
func mutateMonster(fb: ByteBuffer) {
|
||||||
let monster = Monster.getRootAsMonster(bb: fb)
|
var fb = fb
|
||||||
|
|
||||||
|
let monster: Monster = getRoot(byteBuffer: &fb)
|
||||||
XCTAssertFalse(monster.mutate(mana: 10))
|
XCTAssertFalse(monster.mutate(mana: 10))
|
||||||
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
|
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
|
||||||
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
|
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
|
||||||
|
|||||||
@@ -685,8 +685,6 @@ public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIP
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_InParentNamespace.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_InParentNamespace.id, addPrefix: prefix) }
|
||||||
public static func getRootAsInParentNamespace(bb: ByteBuffer) -> MyGame_InParentNamespace { return MyGame_InParentNamespace(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -739,8 +737,6 @@ public struct MyGame_Example2_Monster: FlatBufferObject, Verifiable, ObjectAPIPa
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example2_Monster.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example2_Monster.id, addPrefix: prefix) }
|
||||||
public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example2_Monster { return MyGame_Example2_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -793,8 +789,6 @@ internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferObject, Verifi
|
|||||||
|
|
||||||
internal static var id: String { "MONS" }
|
internal static var id: String { "MONS" }
|
||||||
internal static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TestSimpleTableWithEnum.id, addPrefix: prefix) }
|
internal static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TestSimpleTableWithEnum.id, addPrefix: prefix) }
|
||||||
internal static func getRootAsTestSimpleTableWithEnum(bb: ByteBuffer) -> MyGame_Example_TestSimpleTableWithEnum { return MyGame_Example_TestSimpleTableWithEnum(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -876,8 +870,6 @@ public struct MyGame_Example_Stat: FlatBufferObject, Verifiable, ObjectAPIPacker
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Stat.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Stat.id, addPrefix: prefix) }
|
||||||
public static func getRootAsStat(bb: ByteBuffer) -> MyGame_Example_Stat { return MyGame_Example_Stat(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -1017,8 +1009,6 @@ public struct MyGame_Example_Referrable: FlatBufferObject, Verifiable, ObjectAPI
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Referrable.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Referrable.id, addPrefix: prefix) }
|
||||||
public static func getRootAsReferrable(bb: ByteBuffer) -> MyGame_Example_Referrable { return MyGame_Example_Referrable(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -1125,8 +1115,6 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Monster.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Monster.id, addPrefix: prefix) }
|
||||||
public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example_Monster { return MyGame_Example_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -1344,19 +1332,19 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
|
|||||||
@discardableResult public func mutate(longEnumNormalDefault: MyGame_Example_LongEnum) -> Bool {let o = _accessor.offset(VTOFFSET.longEnumNormalDefault.v); return _accessor.mutate(longEnumNormalDefault.rawValue, index: o) }
|
@discardableResult public func mutate(longEnumNormalDefault: MyGame_Example_LongEnum) -> Bool {let o = _accessor.offset(VTOFFSET.longEnumNormalDefault.v); return _accessor.mutate(longEnumNormalDefault.rawValue, index: o) }
|
||||||
public var nanDefault: Float32 { let o = _accessor.offset(VTOFFSET.nanDefault.v); return o == 0 ? .nan : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var nanDefault: Float32 { let o = _accessor.offset(VTOFFSET.nanDefault.v); return o == 0 ? .nan : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(nanDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.nanDefault.v); return _accessor.mutate(nanDefault, index: o) }
|
@discardableResult public func mutate(nanDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.nanDefault.v); return _accessor.mutate(nanDefault, index: o) }
|
||||||
public var infDefault: Float32 { let o = _accessor.offset(VTOFFSET.infDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var infDefault: Float32 { let o = _accessor.offset(VTOFFSET.infDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(infDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.infDefault.v); return _accessor.mutate(infDefault, index: o) }
|
@discardableResult public func mutate(infDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.infDefault.v); return _accessor.mutate(infDefault, index: o) }
|
||||||
public var positiveInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var positiveInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(positiveInfDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return _accessor.mutate(positiveInfDefault, index: o) }
|
@discardableResult public func mutate(positiveInfDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.positiveInfDefault.v); return _accessor.mutate(positiveInfDefault, index: o) }
|
||||||
public var infinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.infinityDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var infinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.infinityDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(infinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.infinityDefault.v); return _accessor.mutate(infinityDefault, index: o) }
|
@discardableResult public func mutate(infinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.infinityDefault.v); return _accessor.mutate(infinityDefault, index: o) }
|
||||||
public var positiveInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var positiveInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(positiveInfinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return _accessor.mutate(positiveInfinityDefault, index: o) }
|
@discardableResult public func mutate(positiveInfinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.positiveInfinityDefault.v); return _accessor.mutate(positiveInfinityDefault, index: o) }
|
||||||
public var negativeInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.negativeInfDefault.v); return o == 0 ? -.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var negativeInfDefault: Float32 { let o = _accessor.offset(VTOFFSET.negativeInfDefault.v); return o == 0 ? -.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(negativeInfDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.negativeInfDefault.v); return _accessor.mutate(negativeInfDefault, index: o) }
|
@discardableResult public func mutate(negativeInfDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.negativeInfDefault.v); return _accessor.mutate(negativeInfDefault, index: o) }
|
||||||
public var negativeInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.negativeInfinityDefault.v); return o == 0 ? -.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
public var negativeInfinityDefault: Float32 { let o = _accessor.offset(VTOFFSET.negativeInfinityDefault.v); return o == 0 ? -.infinity : _accessor.readBuffer(of: Float32.self, at: o) }
|
||||||
@discardableResult public func mutate(negativeInfinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.negativeInfinityDefault.v); return _accessor.mutate(negativeInfinityDefault, index: o) }
|
@discardableResult public func mutate(negativeInfinityDefault: Float32) -> Bool {let o = _accessor.offset(VTOFFSET.negativeInfinityDefault.v); return _accessor.mutate(negativeInfinityDefault, index: o) }
|
||||||
public var doubleInfDefault: Double { let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return o == 0 ? +.infinity : _accessor.readBuffer(of: Double.self, at: o) }
|
public var doubleInfDefault: Double { let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return o == 0 ? .infinity : _accessor.readBuffer(of: Double.self, at: o) }
|
||||||
@discardableResult public func mutate(doubleInfDefault: Double) -> Bool {let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return _accessor.mutate(doubleInfDefault, index: o) }
|
@discardableResult public func mutate(doubleInfDefault: Double) -> Bool {let o = _accessor.offset(VTOFFSET.doubleInfDefault.v); return _accessor.mutate(doubleInfDefault, index: o) }
|
||||||
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 62) }
|
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 62) }
|
||||||
public static func add(pos: MyGame_Example_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
|
public static func add(pos: MyGame_Example_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
|
||||||
@@ -1423,13 +1411,13 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
|
|||||||
public static func add(longEnumNonEnumDefault: MyGame_Example_LongEnum, _ fbb: inout FlatBufferBuilder) { fbb.add(element: longEnumNonEnumDefault.rawValue, def: 0, at: VTOFFSET.longEnumNonEnumDefault.p) }
|
public static func add(longEnumNonEnumDefault: MyGame_Example_LongEnum, _ fbb: inout FlatBufferBuilder) { fbb.add(element: longEnumNonEnumDefault.rawValue, def: 0, at: VTOFFSET.longEnumNonEnumDefault.p) }
|
||||||
public static func add(longEnumNormalDefault: MyGame_Example_LongEnum, _ fbb: inout FlatBufferBuilder) { fbb.add(element: longEnumNormalDefault.rawValue, def: 2, at: VTOFFSET.longEnumNormalDefault.p) }
|
public static func add(longEnumNormalDefault: MyGame_Example_LongEnum, _ fbb: inout FlatBufferBuilder) { fbb.add(element: longEnumNormalDefault.rawValue, def: 2, at: VTOFFSET.longEnumNormalDefault.p) }
|
||||||
public static func add(nanDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: nanDefault, def: .nan, at: VTOFFSET.nanDefault.p) }
|
public static func add(nanDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: nanDefault, def: .nan, at: VTOFFSET.nanDefault.p) }
|
||||||
public static func add(infDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infDefault, def: +.infinity, at: VTOFFSET.infDefault.p) }
|
public static func add(infDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infDefault, def: .infinity, at: VTOFFSET.infDefault.p) }
|
||||||
public static func add(positiveInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfDefault, def: +.infinity, at: VTOFFSET.positiveInfDefault.p) }
|
public static func add(positiveInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfDefault, def: .infinity, at: VTOFFSET.positiveInfDefault.p) }
|
||||||
public static func add(infinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infinityDefault, def: +.infinity, at: VTOFFSET.infinityDefault.p) }
|
public static func add(infinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: infinityDefault, def: .infinity, at: VTOFFSET.infinityDefault.p) }
|
||||||
public static func add(positiveInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfinityDefault, def: +.infinity, at: VTOFFSET.positiveInfinityDefault.p) }
|
public static func add(positiveInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: positiveInfinityDefault, def: .infinity, at: VTOFFSET.positiveInfinityDefault.p) }
|
||||||
public static func add(negativeInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: negativeInfDefault, def: -.infinity, at: VTOFFSET.negativeInfDefault.p) }
|
public static func add(negativeInfDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: negativeInfDefault, def: -.infinity, at: VTOFFSET.negativeInfDefault.p) }
|
||||||
public static func add(negativeInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: negativeInfinityDefault, def: -.infinity, at: VTOFFSET.negativeInfinityDefault.p) }
|
public static func add(negativeInfinityDefault: Float32, _ fbb: inout FlatBufferBuilder) { fbb.add(element: negativeInfinityDefault, def: -.infinity, at: VTOFFSET.negativeInfinityDefault.p) }
|
||||||
public static func add(doubleInfDefault: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: doubleInfDefault, def: +.infinity, at: VTOFFSET.doubleInfDefault.p) }
|
public static func add(doubleInfDefault: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: doubleInfDefault, def: .infinity, at: VTOFFSET.doubleInfDefault.p) }
|
||||||
public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); fbb.require(table: end, fields: [10]); return end }
|
public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); fbb.require(table: end, fields: [10]); return end }
|
||||||
public static func createMonster(
|
public static func createMonster(
|
||||||
_ fbb: inout FlatBufferBuilder,
|
_ fbb: inout FlatBufferBuilder,
|
||||||
@@ -1487,13 +1475,13 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
|
|||||||
longEnumNonEnumDefault: MyGame_Example_LongEnum = .longone,
|
longEnumNonEnumDefault: MyGame_Example_LongEnum = .longone,
|
||||||
longEnumNormalDefault: MyGame_Example_LongEnum = .longone,
|
longEnumNormalDefault: MyGame_Example_LongEnum = .longone,
|
||||||
nanDefault: Float32 = .nan,
|
nanDefault: Float32 = .nan,
|
||||||
infDefault: Float32 = +.infinity,
|
infDefault: Float32 = .infinity,
|
||||||
positiveInfDefault: Float32 = +.infinity,
|
positiveInfDefault: Float32 = .infinity,
|
||||||
infinityDefault: Float32 = +.infinity,
|
infinityDefault: Float32 = .infinity,
|
||||||
positiveInfinityDefault: Float32 = +.infinity,
|
positiveInfinityDefault: Float32 = .infinity,
|
||||||
negativeInfDefault: Float32 = -.infinity,
|
negativeInfDefault: Float32 = -.infinity,
|
||||||
negativeInfinityDefault: Float32 = -.infinity,
|
negativeInfinityDefault: Float32 = -.infinity,
|
||||||
doubleInfDefault: Double = +.infinity
|
doubleInfDefault: Double = .infinity
|
||||||
) -> Offset {
|
) -> Offset {
|
||||||
let __start = MyGame_Example_Monster.startMonster(&fbb)
|
let __start = MyGame_Example_Monster.startMonster(&fbb)
|
||||||
MyGame_Example_Monster.add(pos: pos, &fbb)
|
MyGame_Example_Monster.add(pos: pos, &fbb)
|
||||||
@@ -2108,16 +2096,16 @@ extension MyGame_Example_Monster: Encodable {
|
|||||||
if !nanDefault.isNaN {
|
if !nanDefault.isNaN {
|
||||||
try container.encodeIfPresent(nanDefault, forKey: .nanDefault)
|
try container.encodeIfPresent(nanDefault, forKey: .nanDefault)
|
||||||
}
|
}
|
||||||
if infDefault != +.infinity {
|
if infDefault != .infinity {
|
||||||
try container.encodeIfPresent(infDefault, forKey: .infDefault)
|
try container.encodeIfPresent(infDefault, forKey: .infDefault)
|
||||||
}
|
}
|
||||||
if positiveInfDefault != +.infinity {
|
if positiveInfDefault != .infinity {
|
||||||
try container.encodeIfPresent(positiveInfDefault, forKey: .positiveInfDefault)
|
try container.encodeIfPresent(positiveInfDefault, forKey: .positiveInfDefault)
|
||||||
}
|
}
|
||||||
if infinityDefault != +.infinity {
|
if infinityDefault != .infinity {
|
||||||
try container.encodeIfPresent(infinityDefault, forKey: .infinityDefault)
|
try container.encodeIfPresent(infinityDefault, forKey: .infinityDefault)
|
||||||
}
|
}
|
||||||
if positiveInfinityDefault != +.infinity {
|
if positiveInfinityDefault != .infinity {
|
||||||
try container.encodeIfPresent(positiveInfinityDefault, forKey: .positiveInfinityDefault)
|
try container.encodeIfPresent(positiveInfinityDefault, forKey: .positiveInfinityDefault)
|
||||||
}
|
}
|
||||||
if negativeInfDefault != -.infinity {
|
if negativeInfDefault != -.infinity {
|
||||||
@@ -2126,7 +2114,7 @@ extension MyGame_Example_Monster: Encodable {
|
|||||||
if negativeInfinityDefault != -.infinity {
|
if negativeInfinityDefault != -.infinity {
|
||||||
try container.encodeIfPresent(negativeInfinityDefault, forKey: .negativeInfinityDefault)
|
try container.encodeIfPresent(negativeInfinityDefault, forKey: .negativeInfinityDefault)
|
||||||
}
|
}
|
||||||
if doubleInfDefault != +.infinity {
|
if doubleInfDefault != .infinity {
|
||||||
try container.encodeIfPresent(doubleInfDefault, forKey: .doubleInfDefault)
|
try container.encodeIfPresent(doubleInfDefault, forKey: .doubleInfDefault)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2403,13 +2391,13 @@ public class MyGame_Example_MonsterT: NativeObject {
|
|||||||
longEnumNonEnumDefault = .longone
|
longEnumNonEnumDefault = .longone
|
||||||
longEnumNormalDefault = .longone
|
longEnumNormalDefault = .longone
|
||||||
nanDefault = .nan
|
nanDefault = .nan
|
||||||
infDefault = +.infinity
|
infDefault = .infinity
|
||||||
positiveInfDefault = +.infinity
|
positiveInfDefault = .infinity
|
||||||
infinityDefault = +.infinity
|
infinityDefault = .infinity
|
||||||
positiveInfinityDefault = +.infinity
|
positiveInfinityDefault = .infinity
|
||||||
negativeInfDefault = -.infinity
|
negativeInfDefault = -.infinity
|
||||||
negativeInfinityDefault = -.infinity
|
negativeInfinityDefault = -.infinity
|
||||||
doubleInfDefault = +.infinity
|
doubleInfDefault = .infinity
|
||||||
}
|
}
|
||||||
|
|
||||||
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Monster.self) }
|
public func serialize() -> ByteBuffer { return serialize(type: MyGame_Example_Monster.self) }
|
||||||
@@ -2423,8 +2411,6 @@ public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAP
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TypeAliases.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TypeAliases.id, addPrefix: prefix) }
|
||||||
public static func getRootAsTypeAliases(bb: ByteBuffer) -> MyGame_Example_TypeAliases { return MyGame_Example_TypeAliases(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ internal struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
internal var __buffer: ByteBuffer! { return _accessor.bb }
|
internal var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
internal static func getRootAsMessage(bb: ByteBuffer) -> Message { return Message(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ public struct InternalMessage: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsInternalMessage(bb: ByteBuffer) -> InternalMessage { return InternalMessage(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -161,8 +159,6 @@ public struct Message: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsMessage(bb: ByteBuffer) -> Message { return Message(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -47,7 +47,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
|
XCTAssertEqual(bytes.sizedByteArray, [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0])
|
||||||
// swiftformat:enable all
|
// swiftformat:enable all
|
||||||
let monster = MyGame_Example_Monster.getRootAsMonster(bb: bytes.buffer)
|
var buffer = bytes.buffer
|
||||||
|
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||||
readMonster(monster: monster)
|
readMonster(monster: monster)
|
||||||
mutateMonster(fb: bytes.buffer)
|
mutateMonster(fb: bytes.buffer)
|
||||||
readMonster(monster: monster)
|
readMonster(monster: monster)
|
||||||
@@ -78,7 +79,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
Monster.add(name: name, &fbb)
|
Monster.add(name: name, &fbb)
|
||||||
let root = Monster.endMonster(&fbb, start: mStart)
|
let root = Monster.endMonster(&fbb, start: mStart)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
|
var buffer = fbb.sizedBuffer
|
||||||
|
let newMonster: Monster = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertNil(newMonster.pos)
|
XCTAssertNil(newMonster.pos)
|
||||||
XCTAssertEqual(newMonster.name, "Frodo")
|
XCTAssertEqual(newMonster.name, "Frodo")
|
||||||
}
|
}
|
||||||
@@ -100,7 +102,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
let root = Monster.endMonster(&fbb, start: mStart)
|
let root = Monster.endMonster(&fbb, start: mStart)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
|
|
||||||
let newMonster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
|
var buffer = fbb.sizedBuffer
|
||||||
|
let newMonster: Monster = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(newMonster.pos!.x, 10)
|
XCTAssertEqual(newMonster.pos!.x, 10)
|
||||||
XCTAssertEqual(newMonster.name, "Barney")
|
XCTAssertEqual(newMonster.name, "Barney")
|
||||||
}
|
}
|
||||||
@@ -110,11 +113,11 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
var array: [UInt8] = [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]
|
var array: [UInt8] = [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]
|
||||||
// swiftformat:enable all
|
// swiftformat:enable all
|
||||||
let unpacked = array
|
let unpacked = array
|
||||||
.withUnsafeMutableBytes { (memory) -> MyGame_Example_MonsterT in
|
.withUnsafeMutableBytes { memory -> MyGame_Example_MonsterT in
|
||||||
let bytes = ByteBuffer(
|
var bytes = ByteBuffer(
|
||||||
assumingMemoryBound: memory.baseAddress!,
|
assumingMemoryBound: memory.baseAddress!,
|
||||||
capacity: memory.count)
|
capacity: memory.count)
|
||||||
var monster = Monster.getRootAsMonster(bb: bytes)
|
var monster: Monster = getRoot(byteBuffer: &bytes)
|
||||||
readFlatbufferMonster(monster: &monster)
|
readFlatbufferMonster(monster: &monster)
|
||||||
let unpacked = monster.unpack()
|
let unpacked = monster.unpack()
|
||||||
return unpacked
|
return unpacked
|
||||||
@@ -132,8 +135,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
nameOffset: name,
|
nameOffset: name,
|
||||||
testarrayofboolsVectorOffset: bools)
|
testarrayofboolsVectorOffset: bools)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
let monster = Monster.getRootAsMonster(bb: fbb.sizedBuffer)
|
var buffer = fbb.sizedBuffer
|
||||||
|
let monster: Monster = getRoot(byteBuffer: &buffer)
|
||||||
let values = monster.testarrayofbools
|
let values = monster.testarrayofbools
|
||||||
|
|
||||||
XCTAssertEqual(boolArray, values)
|
XCTAssertEqual(boolArray, values)
|
||||||
@@ -156,9 +159,9 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
readFlatbufferMonster(monster: &monster)
|
readFlatbufferMonster(monster: &monster)
|
||||||
let unpacked: MyGame_Example_MonsterT? = monster.unpack()
|
let unpacked: MyGame_Example_MonsterT? = monster.unpack()
|
||||||
readObjectApi(monster: unpacked!)
|
readObjectApi(monster: unpacked!)
|
||||||
guard let buffer = unpacked?.serialize()
|
guard var buffer = unpacked?.serialize()
|
||||||
else { fatalError("Couldnt generate bytebuffer") }
|
else { fatalError("Couldnt generate bytebuffer") }
|
||||||
var newMonster = Monster.getRootAsMonster(bb: buffer)
|
var newMonster: Monster = getRoot(byteBuffer: &buffer)
|
||||||
readFlatbufferMonster(monster: &newMonster)
|
readFlatbufferMonster(monster: &newMonster)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +227,8 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mutateMonster(fb: ByteBuffer) {
|
func mutateMonster(fb: ByteBuffer) {
|
||||||
let monster = Monster.getRootAsMonster(bb: fb)
|
var fb = fb
|
||||||
|
let monster: Monster = getRoot(byteBuffer: &fb)
|
||||||
XCTAssertFalse(monster.mutate(mana: 10))
|
XCTAssertFalse(monster.mutate(mana: 10))
|
||||||
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
|
XCTAssertEqual(monster.testarrayoftables(at: 0)?.name, "Barney")
|
||||||
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
|
XCTAssertEqual(monster.testarrayoftables(at: 1)?.name, "Frodo")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2022 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,50 +19,54 @@ import XCTest
|
|||||||
|
|
||||||
final class FlatBuffersNanInfTests: XCTestCase {
|
final class FlatBuffersNanInfTests: XCTestCase {
|
||||||
|
|
||||||
func createTestTable() -> FlatBufferBuilder {
|
func createTestTable() -> FlatBufferBuilder {
|
||||||
var fbb = FlatBufferBuilder()
|
var fbb = FlatBufferBuilder()
|
||||||
let msg = Swift_Tests_NanInfTable.createNanInfTable(&fbb,
|
let msg = Swift_Tests_NanInfTable.createNanInfTable(
|
||||||
valueNan: .nan,
|
&fbb,
|
||||||
valueInf: .infinity,
|
valueNan: .nan,
|
||||||
valueNinf: -.infinity,
|
valueInf: .infinity,
|
||||||
value: 100.0
|
valueNinf: -.infinity,
|
||||||
)
|
value: 100.0)
|
||||||
fbb.finish(offset: msg)
|
fbb.finish(offset: msg)
|
||||||
return fbb
|
return fbb
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInfNanBinary() {
|
func testInfNanBinary() {
|
||||||
let fbb = createTestTable()
|
let fbb = createTestTable()
|
||||||
let data = fbb.sizedByteArray
|
let data = fbb.sizedByteArray
|
||||||
|
|
||||||
let table = Swift_Tests_NanInfTable.getRootAsNanInfTable(bb: ByteBuffer(bytes: data))
|
var buffer = ByteBuffer(bytes: data)
|
||||||
XCTAssert(table.defaultNan.isNaN)
|
let table: Swift_Tests_NanInfTable = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(table.defaultInf, .infinity)
|
XCTAssert(table.defaultNan.isNaN)
|
||||||
XCTAssertEqual(table.defaultNinf, -.infinity)
|
XCTAssertEqual(table.defaultInf, .infinity)
|
||||||
XCTAssert(table.valueNan.isNaN)
|
XCTAssertEqual(table.defaultNinf, -.infinity)
|
||||||
XCTAssertEqual(table.valueInf, .infinity)
|
XCTAssert(table.valueNan.isNaN)
|
||||||
XCTAssertEqual(table.valueNinf, -.infinity)
|
XCTAssertEqual(table.valueInf, .infinity)
|
||||||
XCTAssertEqual(table.value, 100.0)
|
XCTAssertEqual(table.valueNinf, -.infinity)
|
||||||
}
|
XCTAssertEqual(table.value, 100.0)
|
||||||
|
}
|
||||||
|
|
||||||
func testInfNanJSON() {
|
func testInfNanJSON() {
|
||||||
let fbb = createTestTable()
|
let fbb = createTestTable()
|
||||||
var bb = fbb.sizedBuffer
|
var bb = fbb.sizedBuffer
|
||||||
do {
|
do {
|
||||||
let reader: Swift_Tests_NanInfTable = try getCheckedRoot(byteBuffer: &bb)
|
let reader: Swift_Tests_NanInfTable = try getCheckedRoot(byteBuffer: &bb)
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
encoder.keyEncodingStrategy = .convertToSnakeCase
|
encoder.keyEncodingStrategy = .convertToSnakeCase
|
||||||
encoder.nonConformingFloatEncodingStrategy =
|
encoder.nonConformingFloatEncodingStrategy =
|
||||||
.convertToString(positiveInfinity: "inf", negativeInfinity: "-inf", nan: "nan")
|
.convertToString(
|
||||||
let data = try encoder.encode(reader)
|
positiveInfinity: "inf",
|
||||||
XCTAssertEqual(data, jsonData.data(using: .utf8))
|
negativeInfinity: "-inf",
|
||||||
} catch {
|
nan: "nan")
|
||||||
XCTFail(error.localizedDescription)
|
let data = try encoder.encode(reader)
|
||||||
}
|
XCTAssertEqual(data, jsonData.data(using: .utf8))
|
||||||
|
} catch {
|
||||||
|
XCTFail(error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var jsonData: String {
|
var jsonData: String {
|
||||||
"{\"value_inf\":\"inf\",\"value\":100,\"value_nan\":\"nan\",\"value_ninf\":\"-inf\"}"
|
"{\"value_inf\":\"inf\",\"value\":100,\"value_nan\":\"nan\",\"value_ninf\":\"-inf\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,8 +26,8 @@ final class FlatBuffersStructsTests: XCTestCase {
|
|||||||
let root = TestMutatingBool.endTestMutatingBool(&fbb, start: start)
|
let root = TestMutatingBool.endTestMutatingBool(&fbb, start: start)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
|
|
||||||
let testMutatingBool = TestMutatingBool
|
var buffer = fbb.sizedBuffer
|
||||||
.getRootAsTestMutatingBool(bb: fbb.sizedBuffer)
|
let testMutatingBool: TestMutatingBool = getRoot(byteBuffer: &buffer)
|
||||||
let property = testMutatingBool.mutableB
|
let property = testMutatingBool.mutableB
|
||||||
XCTAssertEqual(property?.property, false)
|
XCTAssertEqual(property?.property, false)
|
||||||
property?.mutate(property: false)
|
property?.mutate(property: false)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -108,8 +108,8 @@ final class FlatBuffersTests: XCTestCase {
|
|||||||
justEnum: .one,
|
justEnum: .one,
|
||||||
maybeEnum: nil)
|
maybeEnum: nil)
|
||||||
b.finish(offset: root)
|
b.finish(offset: root)
|
||||||
let scalarTable = optional_scalars_ScalarStuff
|
var buffer = b.sizedBuffer
|
||||||
.getRootAsScalarStuff(bb: b.sizedBuffer)
|
let scalarTable: optional_scalars_ScalarStuff = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(scalarTable.justI8, 80)
|
XCTAssertEqual(scalarTable.justI8, 80)
|
||||||
XCTAssertNil(scalarTable.maybeI8)
|
XCTAssertNil(scalarTable.maybeI8)
|
||||||
XCTAssertEqual(scalarTable.maybeBool, true)
|
XCTAssertEqual(scalarTable.maybeBool, true)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -122,7 +122,8 @@ final class FlatBuffersUnionTests: XCTestCase {
|
|||||||
charactersVectorOffset: characterVector)
|
charactersVectorOffset: characterVector)
|
||||||
Movie.finish(&fb, end: end)
|
Movie.finish(&fb, end: end)
|
||||||
|
|
||||||
var movie = Movie.getRootAsMovie(bb: fb.buffer)
|
var buffer = fb.buffer
|
||||||
|
var movie: Movie = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(movie.charactersTypeCount, Int32(characterType.count))
|
XCTAssertEqual(movie.charactersTypeCount, Int32(characterType.count))
|
||||||
XCTAssertEqual(movie.charactersCount, Int32(characters.count))
|
XCTAssertEqual(movie.charactersCount, Int32(characters.count))
|
||||||
|
|
||||||
@@ -151,7 +152,8 @@ final class FlatBuffersUnionTests: XCTestCase {
|
|||||||
let newMovie = Movie.pack(&fb, obj: &objc)
|
let newMovie = Movie.pack(&fb, obj: &objc)
|
||||||
fb.finish(offset: newMovie)
|
fb.finish(offset: newMovie)
|
||||||
|
|
||||||
let packedMovie = Movie.getRootAsMovie(bb: fb.buffer)
|
var _buffer = fb.buffer
|
||||||
|
let packedMovie: Movie = getRoot(byteBuffer: &_buffer)
|
||||||
|
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
|
packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
|
||||||
@@ -185,7 +187,8 @@ final class FlatBuffersUnionTests: XCTestCase {
|
|||||||
charactersVectorOffset: characterVector)
|
charactersVectorOffset: characterVector)
|
||||||
Movie.finish(&fb, end: end)
|
Movie.finish(&fb, end: end)
|
||||||
|
|
||||||
var movie = Movie.getRootAsMovie(bb: fb.sizedBuffer)
|
var buffer = fb.sizedBuffer
|
||||||
|
var movie: Movie = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(movie.mainCharacter(type: String.self), string)
|
XCTAssertEqual(movie.mainCharacter(type: String.self), string)
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
|
movie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
|
||||||
@@ -200,7 +203,8 @@ final class FlatBuffersUnionTests: XCTestCase {
|
|||||||
let newMovie = Movie.pack(&fb, obj: &objc)
|
let newMovie = Movie.pack(&fb, obj: &objc)
|
||||||
fb.finish(offset: newMovie)
|
fb.finish(offset: newMovie)
|
||||||
|
|
||||||
let packedMovie = Movie.getRootAsMovie(bb: fb.buffer)
|
var _buffer = fb.buffer
|
||||||
|
let packedMovie: Movie = getRoot(byteBuffer: &_buffer)
|
||||||
XCTAssertEqual(packedMovie.mainCharacter(type: String.self), string)
|
XCTAssertEqual(packedMovie.mainCharacter(type: String.self), string)
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
|
packedMovie.characters(at: 0, type: BookReader_Mutable.self)?.booksRead,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -118,7 +118,8 @@ final class FlatBuffersVectors: XCTestCase {
|
|||||||
let finish = Swift_Tests_Vectors.endVectors(&builder, start: start)
|
let finish = Swift_Tests_Vectors.endVectors(&builder, start: start)
|
||||||
builder.finish(offset: finish)
|
builder.finish(offset: finish)
|
||||||
|
|
||||||
let msg = Swift_Tests_Vectors.getRootAsVectors(bb: ByteBuffer(bytes: builder.sizedByteArray))
|
var byteBuffer = ByteBuffer(bytes: builder.sizedByteArray)
|
||||||
|
let msg: Swift_Tests_Vectors = getRoot(byteBuffer: &byteBuffer)
|
||||||
XCTAssertEqual(msg.hasNone, false)
|
XCTAssertEqual(msg.hasNone, false)
|
||||||
XCTAssertEqual(msg.hasEmpty, true)
|
XCTAssertEqual(msg.hasEmpty, true)
|
||||||
XCTAssertEqual(msg.emptyCount, 0)
|
XCTAssertEqual(msg.emptyCount, 0)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,7 +24,8 @@ class FlatBuffersMoreDefaults: XCTestCase {
|
|||||||
var fbb = FlatBufferBuilder()
|
var fbb = FlatBufferBuilder()
|
||||||
let root = MoreDefaults.createMoreDefaults(&fbb)
|
let root = MoreDefaults.createMoreDefaults(&fbb)
|
||||||
fbb.finish(offset: root)
|
fbb.finish(offset: root)
|
||||||
let defaults = MoreDefaults.getRootAsMoreDefaults(bb: fbb.sizedBuffer)
|
var byteBuffer = fbb.sizedBuffer
|
||||||
|
let defaults: MoreDefaults = getRoot(byteBuffer: &byteBuffer)
|
||||||
XCTAssertEqual(defaults.emptyString, "")
|
XCTAssertEqual(defaults.emptyString, "")
|
||||||
XCTAssertEqual(defaults.someString, "some")
|
XCTAssertEqual(defaults.someString, "some")
|
||||||
XCTAssertEqual(defaults.ints, [])
|
XCTAssertEqual(defaults.ints, [])
|
||||||
@@ -46,8 +47,8 @@ class FlatBuffersMoreDefaults: XCTestCase {
|
|||||||
XCTAssertEqual(defaults.abcs, [])
|
XCTAssertEqual(defaults.abcs, [])
|
||||||
XCTAssertEqual(defaults.bools, [])
|
XCTAssertEqual(defaults.bools, [])
|
||||||
|
|
||||||
let buffer = defaults.serialize(builder: &fbb, type: MoreDefaults.self)
|
var buffer = defaults.serialize(builder: &fbb, type: MoreDefaults.self)
|
||||||
let fDefaults = MoreDefaults.getRootAsMoreDefaults(bb: buffer)
|
let fDefaults: MoreDefaults = getRoot(byteBuffer: &buffer)
|
||||||
XCTAssertEqual(fDefaults.emptyString, "")
|
XCTAssertEqual(fDefaults.emptyString, "")
|
||||||
XCTAssertEqual(fDefaults.someString, "some")
|
XCTAssertEqual(fDefaults.someString, "some")
|
||||||
XCTAssertEqual(fDefaults.ints, [])
|
XCTAssertEqual(fDefaults.ints, [])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -205,7 +205,9 @@ final class FlatbuffersVerifierTests: XCTestCase {
|
|||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
var byteBuffer = ByteBuffer(bytes: [20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
|
var byteBuffer = ByteBuffer(bytes: [20, 0, 0, 0, 77, 79, 86, 73, 12, 0, 12, 0, 0, 0, 0, 0, 8, 0, 4, 0, 12, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 3, 0, 0, 0, 24, 0, 0, 0, 32, 0, 0, 0, 12, 0, 0, 0, 3, 0, 0, 0, 3, 1, 4, 0, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 8, 0, 0, 0])
|
||||||
// swiftformat:enable all
|
// swiftformat:enable all
|
||||||
XCTAssertThrowsError(try getCheckedRoot(byteBuffer: &byteBuffer, fileId: "FLEX") as Movie)
|
XCTAssertThrowsError(try getCheckedRoot(
|
||||||
|
byteBuffer: &byteBuffer,
|
||||||
|
fileId: "FLEX") as Movie)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVerifyPrefixedBuffer() {
|
func testVerifyPrefixedBuffer() {
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ public struct TestMutatingBool: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsTestMutatingBool(bb: ByteBuffer) -> TestMutatingBool { return TestMutatingBool(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -685,8 +685,6 @@ public struct MyGame_InParentNamespace: FlatBufferObject, Verifiable, ObjectAPIP
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_InParentNamespace.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_InParentNamespace.id, addPrefix: prefix) }
|
||||||
public static func getRootAsInParentNamespace(bb: ByteBuffer) -> MyGame_InParentNamespace { return MyGame_InParentNamespace(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -739,8 +737,6 @@ public struct MyGame_Example2_Monster: FlatBufferObject, Verifiable, ObjectAPIPa
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example2_Monster.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example2_Monster.id, addPrefix: prefix) }
|
||||||
public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example2_Monster { return MyGame_Example2_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -793,8 +789,6 @@ internal struct MyGame_Example_TestSimpleTableWithEnum: FlatBufferObject, Verifi
|
|||||||
|
|
||||||
internal static var id: String { "MONS" }
|
internal static var id: String { "MONS" }
|
||||||
internal static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TestSimpleTableWithEnum.id, addPrefix: prefix) }
|
internal static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TestSimpleTableWithEnum.id, addPrefix: prefix) }
|
||||||
internal static func getRootAsTestSimpleTableWithEnum(bb: ByteBuffer) -> MyGame_Example_TestSimpleTableWithEnum { return MyGame_Example_TestSimpleTableWithEnum(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
internal init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -876,8 +870,6 @@ public struct MyGame_Example_Stat: FlatBufferObject, Verifiable, ObjectAPIPacker
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Stat.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Stat.id, addPrefix: prefix) }
|
||||||
public static func getRootAsStat(bb: ByteBuffer) -> MyGame_Example_Stat { return MyGame_Example_Stat(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -1017,8 +1009,6 @@ public struct MyGame_Example_Referrable: FlatBufferObject, Verifiable, ObjectAPI
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Referrable.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Referrable.id, addPrefix: prefix) }
|
||||||
public static func getRootAsReferrable(bb: ByteBuffer) -> MyGame_Example_Referrable { return MyGame_Example_Referrable(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -1125,8 +1115,6 @@ public struct MyGame_Example_Monster: FlatBufferObject, Verifiable, ObjectAPIPac
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Monster.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_Monster.id, addPrefix: prefix) }
|
||||||
public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Example_Monster { return MyGame_Example_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -2423,8 +2411,6 @@ public struct MyGame_Example_TypeAliases: FlatBufferObject, Verifiable, ObjectAP
|
|||||||
|
|
||||||
public static var id: String { "MONS" }
|
public static var id: String { "MONS" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TypeAliases.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: MyGame_Example_TypeAliases.id, addPrefix: prefix) }
|
||||||
public static func getRootAsTypeAliases(bb: ByteBuffer) -> MyGame_Example_TypeAliases { return MyGame_Example_TypeAliases(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ public struct MoreDefaults: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsMoreDefaults(bb: ByteBuffer) -> MoreDefaults { return MoreDefaults(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ public struct Swift_Tests_NanInfTable: FlatBufferObject, Verifiable {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsNanInfTable(bb: ByteBuffer) -> Swift_Tests_NanInfTable { return Swift_Tests_NanInfTable(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ public struct optional_scalars_ScalarStuff: FlatBufferObject, Verifiable {
|
|||||||
|
|
||||||
public static var id: String { "NULL" }
|
public static var id: String { "NULL" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: optional_scalars_ScalarStuff.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: optional_scalars_ScalarStuff.id, addPrefix: prefix) }
|
||||||
public static func getRootAsScalarStuff(bb: ByteBuffer) -> optional_scalars_ScalarStuff { return optional_scalars_ScalarStuff(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -330,8 +330,6 @@ public struct Attacker: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
|
|
||||||
public static var id: String { "MOVI" }
|
public static var id: String { "MOVI" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Attacker.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Attacker.id, addPrefix: prefix) }
|
||||||
public static func getRootAsAttacker(bb: ByteBuffer) -> Attacker { return Attacker(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -413,8 +411,6 @@ public struct HandFan: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
|
|
||||||
public static var id: String { "MOVI" }
|
public static var id: String { "MOVI" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: HandFan.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: HandFan.id, addPrefix: prefix) }
|
||||||
public static func getRootAsHandFan(bb: ByteBuffer) -> HandFan { return HandFan(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -496,8 +492,6 @@ public struct Movie: FlatBufferObject, Verifiable, ObjectAPIPacker {
|
|||||||
|
|
||||||
public static var id: String { "MOVI" }
|
public static var id: String { "MOVI" }
|
||||||
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Movie.id, addPrefix: prefix) }
|
public static func finish(_ fbb: inout FlatBufferBuilder, end: Offset, prefix: Bool = false) { fbb.finish(offset: end, fileId: Movie.id, addPrefix: prefix) }
|
||||||
public static func getRootAsMovie(bb: ByteBuffer) -> Movie { return Movie(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ public struct Swift_Tests_Vectors: FlatBufferObject, Verifiable {
|
|||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
public static func getRootAsVectors(bb: ByteBuffer) -> Swift_Tests_Vectors { return Swift_Tests_Vectors(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
Reference in New Issue
Block a user