mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-17 01:26:45 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class ByteBufferTests: XCTestCase {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
typealias Test = MyGame_Example_Test
|
||||
@@ -27,7 +28,20 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
|
||||
func testData() {
|
||||
// swiftformat:disable all
|
||||
let data = Data([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])
|
||||
let data = Data([
|
||||
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
|
||||
let _data = ByteBuffer(data: data)
|
||||
readVerifiedMonster(fb: _data)
|
||||
@@ -74,7 +88,22 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testCreateMonster() {
|
||||
let bytes = createMonster(withPrefix: false)
|
||||
// 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
|
||||
var buffer = bytes.buffer
|
||||
|
||||
@@ -87,7 +116,22 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testCreateMonsterResizedBuffer() {
|
||||
let bytes = createMonster(withPrefix: false)
|
||||
// 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
|
||||
readVerifiedMonster(fb: bytes.sizedBuffer)
|
||||
}
|
||||
@@ -95,7 +139,22 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testCreateMonsterPrefixed() {
|
||||
let bytes = createMonster(withPrefix: true)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(bytes.sizedByteArray, [44, 1, 0, 0, 44, 0, 0, 0, 77, 79, 78, 83, 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,
|
||||
[
|
||||
44, 1, 0, 0, 44, 0, 0, 0, 77, 79, 78, 83, 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
|
||||
|
||||
var buffer = bytes.buffer
|
||||
@@ -140,9 +199,23 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
|
||||
func testReadMonsterFromUnsafePointerWithoutCopying() {
|
||||
// swiftformat:disable all
|
||||
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
|
||||
let unpacked = array
|
||||
let unpacked =
|
||||
array
|
||||
.withUnsafeMutableBytes { memory -> MyGame_Example_MonsterT in
|
||||
var bytes = ByteBuffer(
|
||||
assumingMemoryBound: memory.baseAddress!,
|
||||
@@ -263,7 +336,20 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testForceRetainedObject() {
|
||||
let byteBuffer = {
|
||||
// swiftformat:disable all
|
||||
var data: Data? = Data([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 data: Data? = Data([
|
||||
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
|
||||
let buffer = ByteBuffer(data: data!)
|
||||
data = nil
|
||||
@@ -451,8 +537,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
count: Int(monster.test4Count))
|
||||
var pointerSum = 0
|
||||
for pointee in bindedMemory.startIndex..<bindedMemory.endIndex {
|
||||
pointerSum += Int(bindedMemory[pointee].a) +
|
||||
Int(bindedMemory[pointee].b)
|
||||
pointerSum += Int(bindedMemory[pointee].a) + Int(bindedMemory[pointee].b)
|
||||
}
|
||||
XCTAssertEqual(pointerSum, 100)
|
||||
}
|
||||
@@ -477,7 +562,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
let array = monster.nameSegmentArray
|
||||
XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster")
|
||||
|
||||
if 0 == monster.testarrayofboolsCount {
|
||||
if 0 == monster.testarrayofboolsCount {
|
||||
XCTAssertEqual(monster.testarrayofbools.isEmpty, true)
|
||||
} else {
|
||||
XCTAssertEqual(monster.testarrayofbools.isEmpty, false)
|
||||
@@ -563,14 +648,14 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
|
||||
private var path: String {
|
||||
#if os(macOS)
|
||||
// Gets the current path of this test file then
|
||||
// strips out the nested directories.
|
||||
let filePath = URL(filePath: #file)
|
||||
.deletingLastPathComponent()
|
||||
return filePath.absoluteString
|
||||
// Gets the current path of this test file then
|
||||
// strips out the nested directories.
|
||||
let filePath = URL(filePath: #file)
|
||||
.deletingLastPathComponent()
|
||||
return filePath.absoluteString
|
||||
#else
|
||||
return FileManager.default.currentDirectoryPath
|
||||
.appending("/tests/swift/Tests/Flatbuffers")
|
||||
return FileManager.default.currentDirectoryPath
|
||||
.appending("/tests/swift/Tests/Flatbuffers")
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class FlatBuffersNanInfTests: XCTestCase {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class FlatBuffersStructsTests: XCTestCase {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import Common
|
||||
@testable import FlatBuffers
|
||||
|
||||
@@ -60,7 +61,10 @@ final class FlatBuffersTests: XCTestCase {
|
||||
lan: 100)
|
||||
b.finish(offset: countryOff)
|
||||
// swiftformat:disable all
|
||||
let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
|
||||
let v: [UInt8] = [
|
||||
16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0,
|
||||
200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0,
|
||||
]
|
||||
// swiftformat:enable all
|
||||
XCTAssertEqual(b.sizedByteArray, v)
|
||||
}
|
||||
@@ -74,14 +78,20 @@ final class FlatBuffersTests: XCTestCase {
|
||||
lan: 100)
|
||||
b.finish(offset: countryOff, addPrefix: true)
|
||||
// swiftformat:disable all
|
||||
let v: [UInt8] = [44, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
|
||||
let v: [UInt8] = [
|
||||
44, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0,
|
||||
100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0,
|
||||
]
|
||||
// swiftformat:enable all
|
||||
XCTAssertEqual(b.sizedByteArray, v)
|
||||
}
|
||||
|
||||
func testReadCountry() {
|
||||
// swiftformat:disable all
|
||||
let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
|
||||
let v: [UInt8] = [
|
||||
16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0,
|
||||
200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0,
|
||||
]
|
||||
// swiftformat:enable all
|
||||
let buffer = ByteBuffer(bytes: v)
|
||||
let c = Country.getRootAsCountry(buffer)
|
||||
@@ -122,19 +132,19 @@ final class FlatBuffersTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testAlignmentCrash() {
|
||||
var builder = FlatBufferBuilder(initialSize: 256)
|
||||
var builder = FlatBufferBuilder(initialSize: 256)
|
||||
|
||||
// Create two identical tables to trigger vtable deduplication
|
||||
let str1 = builder.create(string: "test")
|
||||
let start1 = builder.startTable(with: 1)
|
||||
builder.add(offset: str1, at: 0)
|
||||
_ = builder.endTable(at: start1)
|
||||
// Create two identical tables to trigger vtable deduplication
|
||||
let str1 = builder.create(string: "test")
|
||||
let start1 = builder.startTable(with: 1)
|
||||
builder.add(offset: str1, at: 0)
|
||||
_ = builder.endTable(at: start1)
|
||||
|
||||
// Second table triggers vtable comparison where crash occurs
|
||||
let str2 = builder.create(string: "crash")
|
||||
let start2 = builder.startTable(with: 1)
|
||||
builder.add(offset: str2, at: 0)
|
||||
_ = builder.endTable(at: start2) // ← Crashes here on ARM64
|
||||
// Second table triggers vtable comparison where crash occurs
|
||||
let str2 = builder.create(string: "crash")
|
||||
let start2 = builder.startTable(with: 1)
|
||||
builder.add(offset: str2, at: 0)
|
||||
_ = builder.endTable(at: start2) // ← Crashes here on ARM64
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,21 +157,34 @@ class Country {
|
||||
__t = t
|
||||
}
|
||||
|
||||
var lan: Int32 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(
|
||||
of: Int32.self,
|
||||
at: o) }
|
||||
var log: Int32 { let o = __t.offset(8); return o == 0 ? 0 : __t.readBuffer(
|
||||
of: Int32.self,
|
||||
at: o) }
|
||||
var lan: Int32 {
|
||||
let o = __t.offset(6)
|
||||
return o == 0
|
||||
? 0
|
||||
: __t.readBuffer(
|
||||
of: Int32.self,
|
||||
at: o)
|
||||
}
|
||||
var log: Int32 {
|
||||
let o = __t.offset(8)
|
||||
return o == 0
|
||||
? 0
|
||||
: __t.readBuffer(
|
||||
of: Int32.self,
|
||||
at: o)
|
||||
}
|
||||
var nameVector: [UInt8]? { __t.getVector(at: 4) }
|
||||
var name: String? {
|
||||
let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) }
|
||||
let o = __t.offset(4)
|
||||
return o == 0 ? nil : __t.string(at: o)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func getRootAsCountry(_ bb: ByteBuffer) -> Country {
|
||||
Country(Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: 0))))
|
||||
Country(
|
||||
Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: 0))))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@@ -169,8 +192,8 @@ class Country {
|
||||
builder: inout FlatBufferBuilder,
|
||||
name: String,
|
||||
log: Int32,
|
||||
lan: Int32) -> Offset
|
||||
{
|
||||
lan: Int32
|
||||
) -> Offset {
|
||||
createCountry(
|
||||
builder: &builder,
|
||||
offset: builder.create(string: name),
|
||||
@@ -183,8 +206,8 @@ class Country {
|
||||
builder: inout FlatBufferBuilder,
|
||||
offset: Offset,
|
||||
log: Int32,
|
||||
lan: Int32) -> Offset
|
||||
{
|
||||
lan: Int32
|
||||
) -> Offset {
|
||||
let _start = builder.startTable(with: 3)
|
||||
Country.add(builder: &builder, lng: log)
|
||||
Country.add(builder: &builder, lan: lan)
|
||||
@@ -195,8 +218,8 @@ class Country {
|
||||
@inlinable
|
||||
static func end(
|
||||
builder: inout FlatBufferBuilder,
|
||||
startOffset: UOffset) -> Offset
|
||||
{
|
||||
startOffset: UOffset
|
||||
) -> Offset {
|
||||
Offset(offset: builder.endTable(at: startOffset))
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class FlatBuffersUnionTests: XCTestCase {
|
||||
@@ -35,7 +36,13 @@ final class FlatBuffersUnionTests: XCTestCase {
|
||||
b.finish(offset: root)
|
||||
let buffer = b.sizedByteArray
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(buffer, [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 8, 0, 7, 0, 12, 0, 10, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 0, 20, 0, 0, 0, 1, 0, 0, 0, 12, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 5, 0, 4, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0])
|
||||
XCTAssertEqual(
|
||||
buffer,
|
||||
[
|
||||
16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 8, 0, 7, 0, 12, 0, 10, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 0, 20,
|
||||
0, 0, 0, 1, 0, 0, 0, 12, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 5, 0, 4, 0, 0,
|
||||
0, 3, 0, 0, 0, 65, 120, 101, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
let monster = LocalMonster.getRootAsMonster(bb: ByteBuffer(bytes: buffer))
|
||||
XCTAssertEqual(monster.weapon(at: 0)?.dmg, dmg)
|
||||
@@ -77,7 +84,18 @@ final class FlatBuffersUnionTests: XCTestCase {
|
||||
path: path)
|
||||
builder.finish(offset: orc)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(builder.sizedByteArray, [32, 0, 0, 0, 0, 0, 26, 0, 48, 0, 36, 0, 0, 0, 34, 0, 28, 0, 0, 0, 24, 0, 23, 0, 16, 0, 15, 0, 8, 0, 4, 0, 26, 0, 0, 0, 44, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 76, 0, 0, 0, 0, 0, 44, 1, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0, 52, 0, 0, 0, 28, 0, 0, 0, 10, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 3, 0, 0, 0, 79, 114, 99, 0, 244, 255, 255, 255, 0, 0, 5, 0, 24, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0, 0, 0, 0, 0, 3, 0, 12, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0, 5, 0, 0, 0, 83, 119, 111, 114, 100, 0, 0, 0])
|
||||
XCTAssertEqual(
|
||||
builder.sizedByteArray,
|
||||
[
|
||||
32, 0, 0, 0, 0, 0, 26, 0, 48, 0, 36, 0, 0, 0, 34, 0, 28, 0, 0, 0, 24, 0, 23, 0, 16, 0, 15,
|
||||
0, 8, 0, 4, 0, 26, 0, 0, 0, 44, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 0, 0, 0, 0,
|
||||
64, 0, 0, 0, 76, 0, 0, 0, 0, 0, 44, 1, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0, 0, 0,
|
||||
0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 2, 0,
|
||||
0, 0, 52, 0, 0, 0, 28, 0, 0, 0, 10, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 3, 0, 0, 0,
|
||||
79, 114, 99, 0, 244, 255, 255, 255, 0, 0, 5, 0, 24, 0, 0, 0, 8, 0, 12, 0, 8, 0, 6, 0, 8, 0,
|
||||
0, 0, 0, 0, 3, 0, 12, 0, 0, 0, 3, 0, 0, 0, 65, 120, 101, 0, 5, 0, 0, 0, 83, 119, 111, 114,
|
||||
100, 0, 0, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
@@ -91,7 +109,12 @@ final class FlatBuffersUnionTests: XCTestCase {
|
||||
let end = ColorsNameSpace.Monster.endMonster(&builder, start: start)
|
||||
builder.finish(offset: end)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(builder.sizedByteArray, [12, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0])
|
||||
XCTAssertEqual(
|
||||
builder.sizedByteArray,
|
||||
[
|
||||
12, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0,
|
||||
0, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
let monster = ColorsNameSpace.Monster
|
||||
.getRootAsMonster(bb: builder.sizedBuffer)
|
||||
@@ -269,41 +292,62 @@ public enum ColorsNameSpace {
|
||||
var __buffer: ByteBuffer! { _accessor.bb }
|
||||
|
||||
private var _accessor: Table
|
||||
static func getRootAsMonster(bb: ByteBuffer) -> Monster { Monster(Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: bb.reader)) +
|
||||
Int32(bb.reader))) }
|
||||
static func getRootAsMonster(bb: ByteBuffer) -> Monster {
|
||||
Monster(
|
||||
Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader)))
|
||||
}
|
||||
|
||||
init(_ t: Table) { _accessor = t }
|
||||
init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
public var colorsCount: Int32 {
|
||||
let o = _accessor.offset(4); return o == 0 ? 0 : _accessor
|
||||
.vector(count: o) }
|
||||
let o = _accessor.offset(4)
|
||||
return o == 0
|
||||
? 0
|
||||
: _accessor
|
||||
.vector(count: o)
|
||||
}
|
||||
public func colors(at index: Int32) -> ColorsNameSpace
|
||||
.RGB?
|
||||
{ let o = _accessor.offset(4); return o == 0 ? ColorsNameSpace
|
||||
.RGB(rawValue: 0)! : ColorsNameSpace.RGB(rawValue: _accessor.directRead(
|
||||
of: Int32.self,
|
||||
offset: _accessor.vector(at: o) + index * 4)) }
|
||||
static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb
|
||||
.startTable(with: 1) }
|
||||
static func add(colors: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(
|
||||
offset: colors,
|
||||
at: 4) }
|
||||
{
|
||||
let o = _accessor.offset(4)
|
||||
return o == 0
|
||||
? ColorsNameSpace
|
||||
.RGB(rawValue: 0)!
|
||||
: ColorsNameSpace.RGB(
|
||||
rawValue: _accessor.directRead(
|
||||
of: Int32.self,
|
||||
offset: _accessor.vector(at: o) + index * 4))
|
||||
}
|
||||
static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset {
|
||||
fbb
|
||||
.startTable(with: 1)
|
||||
}
|
||||
static func add(colors: Offset, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(
|
||||
offset: colors,
|
||||
at: 4)
|
||||
}
|
||||
static func endMonster(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
start: UOffset)
|
||||
start: UOffset
|
||||
)
|
||||
-> Offset
|
||||
{ let end = Offset(offset: fbb.endTable(at: start)); return end
|
||||
{
|
||||
let end = Offset(offset: fbb.endTable(at: start))
|
||||
return end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum Equipment: Byte { case none, Weapon }
|
||||
|
||||
enum Color3: Int8 { case red = 0, green, blue }
|
||||
enum Color3: Int8 {
|
||||
case red = 0
|
||||
case green, blue
|
||||
}
|
||||
|
||||
struct FinalMonster {
|
||||
|
||||
@@ -318,8 +362,8 @@ struct FinalMonster {
|
||||
weapons: Offset,
|
||||
equipment: Equipment = .none,
|
||||
equippedOffset: Offset,
|
||||
path: Offset) -> Offset
|
||||
{
|
||||
path: Offset
|
||||
) -> Offset {
|
||||
let start = builder.startTable(with: 11)
|
||||
builder.create(struct: position, position: 4)
|
||||
builder.add(element: hp, def: 100, at: 8)
|
||||
@@ -344,19 +388,27 @@ struct LocalMonster {
|
||||
init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o) }
|
||||
init(_ t: Table) { __t = t }
|
||||
|
||||
func weapon(at index: Int32) -> Weapon? { let o = __t
|
||||
.offset(4); return o == 0 ? nil : Weapon.assign(
|
||||
__t.indirect(__t.vector(at: o) + (index * 4)),
|
||||
__t.bb) }
|
||||
func weapon(at index: Int32) -> Weapon? {
|
||||
let o =
|
||||
__t
|
||||
.offset(4)
|
||||
return o == 0
|
||||
? nil
|
||||
: Weapon.assign(
|
||||
__t.indirect(__t.vector(at: o) + (index * 4)),
|
||||
__t.bb)
|
||||
}
|
||||
|
||||
func equiped<T: FlatBufferObject>() -> T? {
|
||||
let o = __t.offset(8); return o == 0 ? nil : __t.union(o)
|
||||
let o = __t.offset(8)
|
||||
return o == 0 ? nil : __t.union(o)
|
||||
}
|
||||
|
||||
static func getRootAsMonster(bb: ByteBuffer) -> LocalMonster {
|
||||
LocalMonster(Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: 0))))
|
||||
LocalMonster(
|
||||
Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: 0))))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@@ -364,8 +416,8 @@ struct LocalMonster {
|
||||
builder: inout FlatBufferBuilder,
|
||||
offset: Offset,
|
||||
equipment: Equipment = .none,
|
||||
equippedOffset: UOffset) -> Offset
|
||||
{
|
||||
equippedOffset: UOffset
|
||||
) -> Offset {
|
||||
let start = builder.startTable(with: 3)
|
||||
builder.add(element: equippedOffset, def: 0, at: 8)
|
||||
builder.add(offset: offset, at: 4)
|
||||
@@ -385,25 +437,35 @@ struct Weapon: FlatBufferObject {
|
||||
private var __t: Table
|
||||
|
||||
init(_ t: Table) { __t = t }
|
||||
init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o)}
|
||||
init(_ fb: ByteBuffer, o: Int32) { __t = Table(bb: fb, position: o) }
|
||||
|
||||
var dmg: Int16 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(
|
||||
of: Int16.self,
|
||||
at: o) }
|
||||
var dmg: Int16 {
|
||||
let o = __t.offset(6)
|
||||
return o == 0
|
||||
? 0
|
||||
: __t.readBuffer(
|
||||
of: Int16.self,
|
||||
at: o)
|
||||
}
|
||||
var nameVector: [UInt8]? { __t.getVector(at: 4) }
|
||||
var name: String? {
|
||||
let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) }
|
||||
let o = __t.offset(4)
|
||||
return o == 0 ? nil : __t.string(at: o)
|
||||
}
|
||||
|
||||
static func assign(_ i: Int32, _ bb: ByteBuffer) -> Weapon { Weapon(Table(
|
||||
bb: bb,
|
||||
position: i)) }
|
||||
static func assign(_ i: Int32, _ bb: ByteBuffer) -> Weapon {
|
||||
Weapon(
|
||||
Table(
|
||||
bb: bb,
|
||||
position: i))
|
||||
}
|
||||
|
||||
@inlinable
|
||||
static func createWeapon(
|
||||
builder: inout FlatBufferBuilder,
|
||||
offset: Offset,
|
||||
dmg: Int16) -> Offset
|
||||
{
|
||||
dmg: Int16
|
||||
) -> Offset {
|
||||
let _start = builder.startTable(with: 2)
|
||||
Weapon.add(builder: &builder, name: offset)
|
||||
Weapon.add(builder: &builder, dmg: dmg)
|
||||
@@ -413,8 +475,8 @@ struct Weapon: FlatBufferObject {
|
||||
@inlinable
|
||||
static func end(
|
||||
builder: inout FlatBufferBuilder,
|
||||
startOffset: UOffset) -> Offset
|
||||
{
|
||||
startOffset: UOffset
|
||||
) -> Offset {
|
||||
Offset(offset: builder.endTable(at: startOffset))
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class FlatBuffersVectors: XCTestCase {
|
||||
@@ -39,7 +40,14 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
let vectorOffset = b.createVector(ofOffsets: vector)
|
||||
b.finish(offset: vectorOffset)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 2, 0, 0, 0, 48, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 18, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 40, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 24, 0, 0, 0, 188, 2, 0, 0, 120, 3, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0])
|
||||
XCTAssertEqual(
|
||||
b.sizedByteArray,
|
||||
[
|
||||
4, 0, 0, 0, 2, 0, 0, 0, 48, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 18, 0, 4, 0, 8, 0, 12, 0, 10,
|
||||
0, 0, 0, 40, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10,
|
||||
0, 0, 0, 24, 0, 0, 0, 188, 2, 0, 0, 120, 3, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114,
|
||||
107, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
@@ -49,7 +57,9 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
let o = b.createVector(numbers, size: numbers.count)
|
||||
b.finish(offset: o)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0])
|
||||
XCTAssertEqual(
|
||||
b.sizedByteArray,
|
||||
[4, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
@@ -66,7 +76,12 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
let o = b.createVector(ofStructs: vector)
|
||||
b.finish(offset: o)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 3, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160, 64, 0, 0, 192, 64, 0, 0, 224, 64, 0, 0, 0, 65, 0, 0, 16, 65])
|
||||
XCTAssertEqual(
|
||||
b.sizedByteArray,
|
||||
[
|
||||
4, 0, 0, 0, 3, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 160,
|
||||
64, 0, 0, 192, 64, 0, 0, 224, 64, 0, 0, 0, 65, 0, 0, 16, 65,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
@@ -84,7 +99,12 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
let o = b.createVector(ofStrings: strs)
|
||||
b.finish(offset: o)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 2, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0])
|
||||
XCTAssertEqual(
|
||||
b.sizedByteArray,
|
||||
[
|
||||
4, 0, 0, 0, 2, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0,
|
||||
0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
func testCreateSharedStringVector() {
|
||||
@@ -99,7 +119,12 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
let end = b.createVector(ofOffsets: v)
|
||||
b.finish(offset: end)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(b.sizedByteArray, [4, 0, 0, 0, 4, 0, 0, 0, 28, 0, 0, 0, 12, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 7, 0, 0, 0, 68, 101, 110, 109, 97, 114, 107, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0])
|
||||
XCTAssertEqual(
|
||||
b.sizedByteArray,
|
||||
[
|
||||
4, 0, 0, 0, 4, 0, 0, 0, 28, 0, 0, 0, 12, 0, 0, 0, 20, 0, 0, 0, 4, 0, 0, 0, 7, 0, 0, 0, 68,
|
||||
101, 110, 109, 97, 114, 107, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
@@ -144,7 +169,6 @@ final class FlatBuffersVectors: XCTestCase {
|
||||
XCTAssertEqual(msg.arrayCount, 3)
|
||||
XCTAssertEqual(msg.array, [1, 2, 3])
|
||||
|
||||
|
||||
let array = msg.withUnsafePointerToArray { ptr in
|
||||
let ptr: UnsafeBufferPointer<UInt64> = UnsafeBufferPointer(
|
||||
start: ptr.baseAddress?.bindMemory(
|
||||
@@ -168,9 +192,10 @@ struct Numbers {
|
||||
|
||||
@inlinable
|
||||
static func getRootAsNumbers(_ bb: ByteBuffer) -> Numbers {
|
||||
Numbers(Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: 0))))
|
||||
Numbers(
|
||||
Table(
|
||||
bb: bb,
|
||||
position: Int32(bb.read(def: UOffset.self, position: 0))))
|
||||
}
|
||||
|
||||
var vArrayInt: [Int]? { __t.getVector(at: 4) }
|
||||
@@ -180,29 +205,29 @@ struct Numbers {
|
||||
|
||||
static func createNumbersVector(
|
||||
b: inout FlatBufferBuilder,
|
||||
array: [Int]) -> Offset
|
||||
{
|
||||
array: [Int]
|
||||
) -> Offset {
|
||||
b.createVector(array, size: array.count)
|
||||
}
|
||||
|
||||
static func createNumbersVector(
|
||||
b: inout FlatBufferBuilder,
|
||||
array: [Int32]) -> Offset
|
||||
{
|
||||
array: [Int32]
|
||||
) -> Offset {
|
||||
b.createVector(array, size: array.count)
|
||||
}
|
||||
|
||||
static func createNumbersVector(
|
||||
b: inout FlatBufferBuilder,
|
||||
array: [Double]) -> Offset
|
||||
{
|
||||
array: [Double]
|
||||
) -> Offset {
|
||||
b.createVector(array, size: array.count)
|
||||
}
|
||||
|
||||
static func createNumbersVector(
|
||||
b: inout FlatBufferBuilder,
|
||||
array: [Float32]) -> Offset
|
||||
{
|
||||
array: [Float32]
|
||||
) -> Offset {
|
||||
b.createVector(array, size: array.count)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class FlatBuffersDoubleTests: XCTestCase {
|
||||
@@ -34,7 +35,7 @@ final class FlatBuffersDoubleTests: XCTestCase {
|
||||
16, 0, 0, 0, 0, 0, 10, 0, 28, 0, 4, 0, 8, 0, 16, 0, 10,
|
||||
0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 64, 0, 0, 0,
|
||||
0, 0, 0, 105, 64, 0, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119,
|
||||
97, 121, 0, 0
|
||||
97, 121, 0, 0,
|
||||
]
|
||||
// swiftformat:enable all
|
||||
XCTAssertEqual(b.sizedByteArray, v)
|
||||
@@ -50,10 +51,10 @@ final class FlatBuffersDoubleTests: XCTestCase {
|
||||
b.finish(offset: countryOff, addPrefix: true)
|
||||
// swiftformat:disable all
|
||||
let v: [UInt8] = [
|
||||
60, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 28
|
||||
, 0, 4, 0, 8, 0, 16, 0, 10, 0, 0, 0, 24, 0, 0, 0, 0, 0,
|
||||
60, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 28, 0, 4, 0, 8, 0, 16, 0, 10, 0, 0, 0, 24,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 89, 64, 0, 0, 0, 0, 0, 0, 105, 64, 0, 0, 0,
|
||||
0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0
|
||||
0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0,
|
||||
]
|
||||
// swiftformat:enable all
|
||||
XCTAssertEqual(b.sizedByteArray, v)
|
||||
@@ -77,8 +78,8 @@ class CountryDouble {
|
||||
builder: inout FlatBufferBuilder,
|
||||
name: String,
|
||||
log: Double,
|
||||
lan: Double) -> Offset
|
||||
{
|
||||
lan: Double
|
||||
) -> Offset {
|
||||
createCountry(
|
||||
builder: &builder,
|
||||
offset: builder.create(string: name),
|
||||
@@ -90,8 +91,8 @@ class CountryDouble {
|
||||
builder: inout FlatBufferBuilder,
|
||||
offset: Offset,
|
||||
log: Double,
|
||||
lan: Double) -> Offset
|
||||
{
|
||||
lan: Double
|
||||
) -> Offset {
|
||||
let _start = builder.startTable(with: 3)
|
||||
CountryDouble.add(builder: &builder, lng: log)
|
||||
CountryDouble.add(builder: &builder, lan: lan)
|
||||
@@ -101,8 +102,8 @@ class CountryDouble {
|
||||
|
||||
static func end(
|
||||
builder: inout FlatBufferBuilder,
|
||||
startOffset: UOffset) -> Offset
|
||||
{
|
||||
startOffset: UOffset
|
||||
) -> Offset {
|
||||
Offset(offset: builder.endTable(at: startOffset))
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
class FlatBuffersMoreDefaults: XCTestCase {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
final class FlatbuffersVerifierTests: XCTestCase {
|
||||
@@ -32,15 +33,67 @@ final class FlatbuffersVerifierTests: XCTestCase {
|
||||
add(buffer: &buffer, v: 4, p: 16)
|
||||
add(buffer: &buffer, v: 4, p: 20)
|
||||
|
||||
validFlatbuffersObject = ByteBuffer(bytes: [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])
|
||||
validFlatbuffersObject = ByteBuffer(bytes: [
|
||||
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,
|
||||
])
|
||||
|
||||
invalidFlatbuffersObject = ByteBuffer(bytes: [0, 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])
|
||||
invalidFlatbuffersObject = ByteBuffer(bytes: [
|
||||
0, 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,
|
||||
])
|
||||
|
||||
// Array failure within a the inventory array
|
||||
invalidFlatbuffersObject2 = ByteBuffer(bytes: [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, 0x00, 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])
|
||||
invalidFlatbuffersObject2 = ByteBuffer(bytes: [
|
||||
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, 0x00, 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,
|
||||
])
|
||||
|
||||
// Array failure within a the strings array
|
||||
invalidFlatbuffersObject3 = ByteBuffer(bytes: [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, 0x00, 111, 0, 0, 0])
|
||||
invalidFlatbuffersObject3 = ByteBuffer(bytes: [
|
||||
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,
|
||||
0x00, 111, 0, 0, 0,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
|
||||
@@ -57,8 +110,8 @@ final class FlatbuffersVerifierTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testFailingID() {
|
||||
let dutData : [UInt8] = [1,2,3,4,5,6,7]
|
||||
var buff = ByteBuffer(bytes: dutData)
|
||||
let dutData: [UInt8] = [1, 2, 3, 4, 5, 6, 7]
|
||||
var buff = ByteBuffer(bytes: dutData)
|
||||
do {
|
||||
let _: Monster = try getCheckedRoot(byteBuffer: &buff, fileId: "ABCD")
|
||||
XCTFail("This should always fail")
|
||||
@@ -130,41 +183,47 @@ final class FlatbuffersVerifierTests: XCTestCase {
|
||||
XCTAssertEqual(verifier.depth, 1)
|
||||
XCTAssertEqual(verifier.tableCount, 1)
|
||||
|
||||
XCTAssertNoThrow(try tableVerifer.visit(
|
||||
field: 4,
|
||||
fieldName: "Vec",
|
||||
required: false,
|
||||
type: Vec3.self))
|
||||
XCTAssertNoThrow(try tableVerifer.visit(
|
||||
field: 8,
|
||||
fieldName: "hp",
|
||||
required: false,
|
||||
type: Int16.self))
|
||||
XCTAssertNoThrow(
|
||||
try tableVerifer.visit(
|
||||
field: 4,
|
||||
fieldName: "Vec",
|
||||
required: false,
|
||||
type: Vec3.self))
|
||||
XCTAssertNoThrow(
|
||||
try tableVerifer.visit(
|
||||
field: 8,
|
||||
fieldName: "hp",
|
||||
required: false,
|
||||
type: Int16.self))
|
||||
|
||||
XCTAssertNoThrow(try tableVerifer.visit(
|
||||
field: 10,
|
||||
fieldName: "name",
|
||||
required: true,
|
||||
type: ForwardOffset<String>.self))
|
||||
XCTAssertNoThrow(
|
||||
try tableVerifer.visit(
|
||||
field: 10,
|
||||
fieldName: "name",
|
||||
required: true,
|
||||
type: ForwardOffset<String>.self))
|
||||
|
||||
XCTAssertNoThrow(try tableVerifer.visit(
|
||||
field: 14,
|
||||
fieldName: "inventory",
|
||||
required: false,
|
||||
type: ForwardOffset<Vector<UInt8, UInt8>>.self))
|
||||
XCTAssertNoThrow(
|
||||
try tableVerifer.visit(
|
||||
field: 14,
|
||||
fieldName: "inventory",
|
||||
required: false,
|
||||
type: ForwardOffset<Vector<UInt8, UInt8>>.self))
|
||||
|
||||
XCTAssertNoThrow(try tableVerifer.visit(
|
||||
field: 22,
|
||||
fieldName: "test4",
|
||||
required: false,
|
||||
type: ForwardOffset<Vector<MyGame_Example_Test, MyGame_Example_Test>>
|
||||
.self))
|
||||
XCTAssertNoThrow(
|
||||
try tableVerifer.visit(
|
||||
field: 22,
|
||||
fieldName: "test4",
|
||||
required: false,
|
||||
type: ForwardOffset<Vector<MyGame_Example_Test, MyGame_Example_Test>>
|
||||
.self))
|
||||
|
||||
XCTAssertNoThrow(try tableVerifer.visit(
|
||||
field: 24,
|
||||
fieldName: "Vector of strings",
|
||||
required: false,
|
||||
type: ForwardOffset<Vector<ForwardOffset<String>, String>>.self))
|
||||
XCTAssertNoThrow(
|
||||
try tableVerifer.visit(
|
||||
field: 24,
|
||||
fieldName: "Vector of strings",
|
||||
required: false,
|
||||
type: ForwardOffset<Vector<ForwardOffset<String>, String>>.self))
|
||||
|
||||
do {
|
||||
try tableVerifer.visit(
|
||||
@@ -212,23 +271,36 @@ final class FlatbuffersVerifierTests: XCTestCase {
|
||||
|
||||
func testVerifyUnionVectors() {
|
||||
// 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
|
||||
XCTAssertNoThrow(try getCheckedRoot(byteBuffer: &byteBuffer) as Movie)
|
||||
}
|
||||
|
||||
func testErrorWrongFileId() {
|
||||
// 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
|
||||
XCTAssertThrowsError(try getCheckedRoot(
|
||||
byteBuffer: &byteBuffer,
|
||||
fileId: "FLEX") as Movie)
|
||||
XCTAssertThrowsError(
|
||||
try getCheckedRoot(
|
||||
byteBuffer: &byteBuffer,
|
||||
fileId: "FLEX") as Movie)
|
||||
}
|
||||
|
||||
func testVerifyPrefixedBuffer() {
|
||||
// swiftformat:disable all
|
||||
var byteBuffer = ByteBuffer(bytes: [0, 0, 0, 1, 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: [
|
||||
0, 0, 0, 1, 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
|
||||
XCTAssertThrowsError(
|
||||
try getCheckedPrefixedSizeRoot(byteBuffer: &byteBuffer) as Movie)
|
||||
@@ -331,8 +403,8 @@ final class FlatbuffersVerifierTests: XCTestCase {
|
||||
|
||||
private func getOffset(
|
||||
at value: Int,
|
||||
within verifier: Verifier) throws -> Int
|
||||
{
|
||||
within verifier: Verifier
|
||||
) throws -> Int {
|
||||
let offset: UOffset = try verifier.getValue(at: value)
|
||||
return Int(clamping: (Int(offset) &+ 0).magnitude)
|
||||
}
|
||||
|
||||
@@ -32,9 +32,10 @@ final class FlexBuffersJSONTests: XCTestCase {
|
||||
// swiftformat:enable all
|
||||
|
||||
let data = json.data(using: .utf8)!
|
||||
let decodedData = try JSONSerialization.jsonObject(
|
||||
with: data,
|
||||
options: []) as! [String: Any]
|
||||
let decodedData =
|
||||
try JSONSerialization.jsonObject(
|
||||
with: data,
|
||||
options: []) as! [String: Any]
|
||||
|
||||
XCTAssertEqual(decodedData["bar"] as! [Int], [1, 2, 3])
|
||||
XCTAssertEqual(decodedData["bar3"] as! [Int], [1, 2, 3])
|
||||
|
||||
@@ -79,7 +79,7 @@ final class FlexBuffersReaderTests: XCTestCase {
|
||||
XCTAssertEqual(blob?[0], 77)
|
||||
XCTAssertEqual(vec[4]?.type, .bool)
|
||||
XCTAssertEqual(vec[4]?.bool, false)
|
||||
XCTAssertEqual(vec[5]?.double, 4.0) // Shared with vec[2]
|
||||
XCTAssertEqual(vec[5]?.double, 4.0) // Shared with vec[2]
|
||||
|
||||
let barVec = map["bar"]!.typedVector!
|
||||
XCTAssertEqual(barVec.count, 3)
|
||||
@@ -125,15 +125,15 @@ final class FlexBuffersReaderTests: XCTestCase {
|
||||
|
||||
private var path: String {
|
||||
#if os(macOS)
|
||||
// Gets the current path of this test file then
|
||||
// strips out the nested directories.
|
||||
let filePath = URL(filePath: #file)
|
||||
.deletingLastPathComponent()
|
||||
.deletingLastPathComponent()
|
||||
.deletingLastPathComponent()
|
||||
return filePath.absoluteString
|
||||
// Gets the current path of this test file then
|
||||
// strips out the nested directories.
|
||||
let filePath = URL(filePath: #file)
|
||||
.deletingLastPathComponent()
|
||||
.deletingLastPathComponent()
|
||||
.deletingLastPathComponent()
|
||||
return filePath.absoluteString
|
||||
#else
|
||||
return FileManager.default.currentDirectoryPath
|
||||
return FileManager.default.currentDirectoryPath
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,10 @@ final class FlexBuffersWriterTests: XCTestCase {
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(
|
||||
Array($0),
|
||||
[10, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 20, 0, 0, 0, 1, 41, 46, 2, 40, 1])
|
||||
[
|
||||
10, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7, 0,
|
||||
0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 20, 0, 0, 0, 1, 41, 46, 2, 40, 1,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
}
|
||||
@@ -65,7 +68,12 @@ final class FlexBuffersWriterTests: XCTestCase {
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(
|
||||
Array($0),
|
||||
[10, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 1, 81, 51, 2, 40, 1])
|
||||
[
|
||||
10, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
|
||||
0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
|
||||
0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
81, 51, 2, 40, 1,
|
||||
])
|
||||
// swiftformat:enable all
|
||||
}
|
||||
}
|
||||
@@ -100,7 +108,10 @@ final class FlexBuffersWriterTests: XCTestCase {
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(
|
||||
Array($0),
|
||||
[98, 111, 111, 108, 50, 0, 98, 111, 111, 108, 49, 0, 2, 7, 14, 2, 1, 2, 1, 0, 104, 104, 4, 36, 1]
|
||||
[
|
||||
98, 111, 111, 108, 50, 0, 98, 111, 111, 108, 49, 0, 2, 7, 14, 2, 1, 2, 1, 0, 104, 104, 4,
|
||||
36, 1,
|
||||
]
|
||||
)
|
||||
// swiftformat:enable all
|
||||
}
|
||||
@@ -119,7 +130,10 @@ final class FlexBuffersWriterTests: XCTestCase {
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(
|
||||
Array($0),
|
||||
[119, 101, 108, 99, 111, 109, 101, 0, 7, 119, 101, 108, 99, 111, 109, 101, 0, 3, 18, 19, 20, 3, 1, 3, 15, 16, 17, 20, 20, 20, 6, 36, 1]
|
||||
[
|
||||
119, 101, 108, 99, 111, 109, 101, 0, 7, 119, 101, 108, 99, 111, 109, 101, 0, 3, 18, 19,
|
||||
20, 3, 1, 3, 15, 16, 17, 20, 20, 20, 6, 36, 1,
|
||||
]
|
||||
)
|
||||
// swiftformat:enable all
|
||||
}
|
||||
@@ -191,7 +205,6 @@ final class FlexBuffersWriterTests: XCTestCase {
|
||||
|
||||
fbx.endMap(start: outerMap)
|
||||
|
||||
|
||||
fbx.finish()
|
||||
let buf: ByteBuffer = fbx.sizedByteBuffer
|
||||
buf.withUnsafeBytes {
|
||||
|
||||
@@ -17,9 +17,24 @@
|
||||
import FlexBuffers
|
||||
|
||||
// swiftformat:disable all
|
||||
let flexbufferGolden: [UInt8] = [118, 101, 99, 0, 4, 70, 114, 101, 100, 0, 0, 0, 0, 0, 128, 64, 1, 77, 6, 156, 15, 9, 5, 0, 12, 4, 20, 34, 100, 104, 34, 98, 97, 114, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 98, 97, 114, 51, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 98, 111, 111, 108, 115, 0, 4, 1, 0, 1, 0, 98, 111, 111, 108, 0, 102, 111, 111, 0, 109, 121, 109, 97, 112, 0, 1, 11, 1, 1, 1, 98, 20, 7, 75, 55, 25, 37, 22, 19, 112, 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 88, 0, 0, 0, 72, 0, 0, 0, 1, 0, 0, 0, 61, 0, 0, 0, 0, 0, 200, 66, 45, 0, 0, 0, 133, 0, 0, 0, 46, 78, 106, 144, 14, 36, 40, 35, 38, 1]
|
||||
let flexbufferGolden: [UInt8] = [
|
||||
118, 101, 99, 0, 4, 70, 114, 101, 100, 0, 0, 0, 0, 0, 128, 64, 1, 77, 6, 156, 15, 9, 5, 0, 12, 4,
|
||||
20, 34, 100, 104, 34, 98, 97, 114, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 98, 97,
|
||||
114, 51, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 98, 111, 111, 108, 115, 0, 4, 1, 0, 1, 0,
|
||||
98, 111, 111, 108, 0, 102, 111, 111, 0, 109, 121, 109, 97, 112, 0, 1, 11, 1, 1, 1, 98, 20, 7, 75,
|
||||
55, 25, 37, 22, 19, 112, 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 88, 0, 0, 0, 72, 0, 0, 0,
|
||||
1, 0, 0, 0, 61, 0, 0, 0, 0, 0, 200, 66, 45, 0, 0, 0, 133, 0, 0, 0, 46, 78, 106, 144, 14, 36, 40,
|
||||
35, 38, 1,
|
||||
]
|
||||
|
||||
let allTypesGolden: [UInt8] = [9, 9, 0, 0, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 247, 255, 255, 255, 255, 255, 255, 255, 9, 0, 0, 0, 0, 0, 0, 0, 51, 51, 51, 51, 51, 51, 3, 64, 0, 0, 0, 64, 51, 51, 3, 64, 51, 51, 51, 51, 51, 51, 3, 192, 0, 0, 0, 64, 51, 51, 3, 192, 24, 28, 34, 34, 3, 107, 7, 7, 11, 15, 15, 15, 15, 117, 43, 1]
|
||||
let allTypesGolden: [UInt8] = [
|
||||
9, 9, 0, 0, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0,
|
||||
0, 31, 0, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 247, 255, 255, 255, 255, 255, 255, 255, 9, 0,
|
||||
0, 0, 0, 0, 0, 0, 51, 51, 51, 51, 51, 51, 3, 64, 0, 0, 0, 64, 51, 51, 3, 64, 51, 51, 51, 51, 51,
|
||||
51, 3, 192, 0, 0, 0, 64, 51, 51, 3, 192, 24, 28, 34, 34, 3, 107, 7, 7, 11, 15, 15, 15, 15, 117,
|
||||
43, 1,
|
||||
]
|
||||
// swiftformat:enable all
|
||||
|
||||
@inline(__always)
|
||||
|
||||
@@ -20,7 +20,7 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "FlatBuffers.Test.Swift.Wasm",
|
||||
platforms: [
|
||||
.macOS(.v10_14),
|
||||
.macOS(.v10_14)
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../../.."),
|
||||
@@ -31,6 +31,6 @@ let package = Package(
|
||||
.testTarget(
|
||||
name: "FlatBuffers.Test.Swift.WasmTests",
|
||||
dependencies: [
|
||||
.product(name: "FlatBuffers", package: "flatbuffers"),
|
||||
.product(name: "FlatBuffers", package: "flatbuffers")
|
||||
]),
|
||||
])
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
public struct Wasm {}
|
||||
public struct Wasm {}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
import XCTest
|
||||
|
||||
@testable import FlatBuffers
|
||||
|
||||
typealias Test = MyGame_Example_Test
|
||||
@@ -27,7 +28,20 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
|
||||
func testData() {
|
||||
// swiftformat:disable all
|
||||
let data: [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]
|
||||
let data: [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
|
||||
let _data = ByteBuffer(bytes: data)
|
||||
readVerifiedMonster(fb: _data)
|
||||
@@ -36,7 +50,22 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testCreateMonster() {
|
||||
let bytes = createMonster(withPrefix: false)
|
||||
// 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
|
||||
var buffer = bytes.buffer
|
||||
let monster: MyGame_Example_Monster = getRoot(byteBuffer: &buffer)
|
||||
@@ -48,7 +77,22 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testCreateMonsterResizedBuffer() {
|
||||
let bytes = createMonster(withPrefix: false)
|
||||
// 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
|
||||
readVerifiedMonster(fb: bytes.sizedBuffer)
|
||||
}
|
||||
@@ -56,7 +100,22 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
func testCreateMonsterPrefixed() {
|
||||
let bytes = createMonster(withPrefix: true)
|
||||
// swiftformat:disable all
|
||||
XCTAssertEqual(bytes.sizedByteArray, [44, 1, 0, 0, 44, 0, 0, 0, 77, 79, 78, 83, 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,
|
||||
[
|
||||
44, 1, 0, 0, 44, 0, 0, 0, 77, 79, 78, 83, 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
|
||||
|
||||
var buffer = bytes.buffer
|
||||
@@ -308,7 +367,7 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
||||
let array = monster.nameSegmentArray
|
||||
XCTAssertEqual(String(bytes: array ?? [], encoding: .utf8), "MyMonster")
|
||||
|
||||
if 0 == monster.testarrayofboolsCount {
|
||||
if 0 == monster.testarrayofboolsCount {
|
||||
XCTAssertEqual(monster.testarrayofbools.isEmpty, true)
|
||||
} else {
|
||||
XCTAssertEqual(monster.testarrayofbools.isEmpty, false)
|
||||
|
||||
@@ -24,12 +24,12 @@ let package = Package(
|
||||
.macOS(.v10_14),
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../../.."),
|
||||
.package(path: "../../..")
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "fuzzer",
|
||||
dependencies: [
|
||||
.product(name: "FlatBuffers", package: "flatbuffers"),
|
||||
]),
|
||||
.product(name: "FlatBuffers", package: "flatbuffers")
|
||||
])
|
||||
])
|
||||
|
||||
@@ -57,7 +57,8 @@ public struct Test: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||
public var a: Int16 { _a }
|
||||
public var b: Int8 { _b }
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
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: Test.self)
|
||||
}
|
||||
}
|
||||
@@ -140,7 +141,8 @@ public struct Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||
public var test2: Color { Color(rawValue: _test2)! }
|
||||
public var test3: Test { _test3 }
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
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: Vec3.self)
|
||||
}
|
||||
}
|
||||
@@ -188,7 +190,9 @@ public struct Vec3_Mutable: FlatBufferObject {
|
||||
public var y: Float32 { return _accessor.readBuffer(of: Float32.self, at: 4) }
|
||||
public var z: Float32 { return _accessor.readBuffer(of: Float32.self, at: 8) }
|
||||
public var test1: Double { return _accessor.readBuffer(of: Double.self, at: 16) }
|
||||
public var test2: Color { return Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: 24)) ?? .red }
|
||||
public var test2: Color {
|
||||
return Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: 24)) ?? .red
|
||||
}
|
||||
public var test3: Test_Mutable { return Test_Mutable(_accessor.bb, o: _accessor.position + 26) }
|
||||
}
|
||||
|
||||
@@ -214,31 +218,96 @@ public struct Monster: FlatBufferObject, Verifiable {
|
||||
var p: VOffset { self.rawValue }
|
||||
}
|
||||
|
||||
public var pos: Vec3? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : _accessor.readBuffer(of: Vec3.self, at: o) }
|
||||
public var mutablePos: Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : Vec3_Mutable(_accessor.bb, o: o + _accessor.position) }
|
||||
public var mana: Int16 { let o = _accessor.offset(VTOFFSET.mana.v); return o == 0 ? 150 : _accessor.readBuffer(of: Int16.self, at: o) }
|
||||
public var hp: Int16 { let o = _accessor.offset(VTOFFSET.hp.v); return o == 0 ? 100 : _accessor.readBuffer(of: Int16.self, at: o) }
|
||||
public var name: String! { let o = _accessor.offset(VTOFFSET.name.v); return _accessor.string(at: o) }
|
||||
public var pos: Vec3? {
|
||||
let o = _accessor.offset(VTOFFSET.pos.v)
|
||||
return o == 0 ? nil : _accessor.readBuffer(of: Vec3.self, at: o)
|
||||
}
|
||||
public var mutablePos: Vec3_Mutable? {
|
||||
let o = _accessor.offset(VTOFFSET.pos.v)
|
||||
return o == 0 ? nil : Vec3_Mutable(_accessor.bb, o: o + _accessor.position)
|
||||
}
|
||||
public var mana: Int16 {
|
||||
let o = _accessor.offset(VTOFFSET.mana.v)
|
||||
return o == 0 ? 150 : _accessor.readBuffer(of: Int16.self, at: o)
|
||||
}
|
||||
public var hp: Int16 {
|
||||
let o = _accessor.offset(VTOFFSET.hp.v)
|
||||
return o == 0 ? 100 : _accessor.readBuffer(of: Int16.self, at: o)
|
||||
}
|
||||
public var name: String! {
|
||||
let o = _accessor.offset(VTOFFSET.name.v)
|
||||
return _accessor.string(at: o)
|
||||
}
|
||||
public var nameSegmentArray: [UInt8]! { return _accessor.getVector(at: VTOFFSET.name.v) }
|
||||
public var hasTestarrayoftables: Bool { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? false : true }
|
||||
public var testarrayoftablesCount: Int32 { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func testarrayoftables(at index: Int32) -> Monster? { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? nil : Monster(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
|
||||
public func testarrayoftablesBy(key: String) -> Monster? { let o = _accessor.offset(VTOFFSET.testarrayoftables.v); return o == 0 ? nil : Monster.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb) }
|
||||
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 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 hasTestarrayoftables: Bool {
|
||||
let o = _accessor.offset(VTOFFSET.testarrayoftables.v)
|
||||
return o == 0 ? false : true
|
||||
}
|
||||
public var testarrayoftablesCount: Int32 {
|
||||
let o = _accessor.offset(VTOFFSET.testarrayoftables.v)
|
||||
return o == 0 ? 0 : _accessor.vector(count: o)
|
||||
}
|
||||
public func testarrayoftables(at index: Int32) -> Monster? {
|
||||
let o = _accessor.offset(VTOFFSET.testarrayoftables.v)
|
||||
return o == 0
|
||||
? nil : Monster(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4))
|
||||
}
|
||||
public func testarrayoftablesBy(key: String) -> Monster? {
|
||||
let o = _accessor.offset(VTOFFSET.testarrayoftables.v)
|
||||
return o == 0
|
||||
? nil : Monster.lookupByKey(vector: _accessor.vector(at: o), key: key, fbb: _accessor.bb)
|
||||
}
|
||||
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 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 func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows -> T? { return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
|
||||
public var color: Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .blue }
|
||||
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 7) }
|
||||
public static func add(pos: Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
|
||||
public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) }
|
||||
public static func add(hp: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: hp, def: 100, at: VTOFFSET.hp.p) }
|
||||
public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
|
||||
public static func addVectorOf(testarrayoftables: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: testarrayoftables, at: VTOFFSET.testarrayoftables.p) }
|
||||
public static func addVectorOf(inventory: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: inventory, at: VTOFFSET.inventory.p) }
|
||||
public static func add(color: Color, _ fbb: inout FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 8, at: VTOFFSET.color.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 func withUnsafePointerToInventory<T>(_ body: (UnsafeRawBufferPointer) throws -> T) rethrows
|
||||
-> T?
|
||||
{ return try _accessor.withUnsafePointerToSlice(at: VTOFFSET.inventory.v, body: body) }
|
||||
public var color: Color {
|
||||
let o = _accessor.offset(VTOFFSET.color.v)
|
||||
return o == 0 ? .blue : Color(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .blue
|
||||
}
|
||||
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset {
|
||||
fbb.startTable(with: 7)
|
||||
}
|
||||
public static func add(pos: Vec3?, _ fbb: inout FlatBufferBuilder) {
|
||||
guard let pos = pos else { return }
|
||||
fbb.create(struct: pos, position: VTOFFSET.pos.p)
|
||||
}
|
||||
public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p)
|
||||
}
|
||||
public static func add(hp: Int16, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(element: hp, def: 100, at: VTOFFSET.hp.p)
|
||||
}
|
||||
public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(offset: name, at: VTOFFSET.name.p)
|
||||
}
|
||||
public static func addVectorOf(testarrayoftables: Offset, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(offset: testarrayoftables, at: VTOFFSET.testarrayoftables.p)
|
||||
}
|
||||
public static func addVectorOf(inventory: Offset, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(offset: inventory, at: VTOFFSET.inventory.p)
|
||||
}
|
||||
public static func add(color: Color, _ fbb: inout FlatBufferBuilder) {
|
||||
fbb.add(element: color.rawValue, def: 8, at: VTOFFSET.color.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 createMonster(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
pos: Vec3? = nil,
|
||||
@@ -259,9 +328,15 @@ public struct Monster: FlatBufferObject, Verifiable {
|
||||
Monster.add(color: color, &fbb)
|
||||
return Monster.endMonster(&fbb, start: __start)
|
||||
}
|
||||
public static func sortVectorOfMonster(offsets:[Offset], _ fbb: inout FlatBufferBuilder) -> Offset {
|
||||
public static func sortVectorOfMonster(offsets: [Offset], _ fbb: inout FlatBufferBuilder)
|
||||
-> Offset
|
||||
{
|
||||
var off = offsets
|
||||
off.sort { Table.compare(Table.offset(Int32($1.o), vOffset: 10, fbb: &fbb), Table.offset(Int32($0.o), vOffset: 10, fbb: &fbb), fbb: &fbb) < 0 }
|
||||
off.sort {
|
||||
Table.compare(
|
||||
Table.offset(Int32($1.o), vOffset: 10, fbb: &fbb),
|
||||
Table.offset(Int32($0.o), vOffset: 10, fbb: &fbb), fbb: &fbb) < 0
|
||||
}
|
||||
return fbb.createVector(ofOffsets: off)
|
||||
}
|
||||
fileprivate static func lookupByKey(vector: Int32, key: String, fbb: ByteBuffer) -> Monster? {
|
||||
@@ -271,7 +346,8 @@ public struct Monster: FlatBufferObject, Verifiable {
|
||||
while span != 0 {
|
||||
var middle = span / 2
|
||||
let tableOffset = Table.indirect(vector + 4 * (start + middle), fbb)
|
||||
let comp = Table.compare(Table.offset(Int32(fbb.capacity) - tableOffset, vOffset: 10, fbb: fbb), key, fbb: fbb)
|
||||
let comp = Table.compare(
|
||||
Table.offset(Int32(fbb.capacity) - tableOffset, vOffset: 10, fbb: fbb), key, fbb: fbb)
|
||||
if comp > 0 {
|
||||
span = middle
|
||||
} else if comp < 0 {
|
||||
@@ -285,14 +361,20 @@ public struct Monster: FlatBufferObject, Verifiable {
|
||||
return nil
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
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: 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: true, type: ForwardOffset<String>.self)
|
||||
try _v.visit(field: VTOFFSET.testarrayoftables.p, fieldName: "testarrayoftables", required: false, type: ForwardOffset<Vector<ForwardOffset<Monster>, Monster>>.self)
|
||||
try _v.visit(field: VTOFFSET.inventory.p, fieldName: "inventory", required: false, type: ForwardOffset<Vector<UInt8, UInt8>>.self)
|
||||
try _v.visit(
|
||||
field: VTOFFSET.name.p, fieldName: "name", required: true, type: ForwardOffset<String>.self)
|
||||
try _v.visit(
|
||||
field: VTOFFSET.testarrayoftables.p, fieldName: "testarrayoftables", required: false,
|
||||
type: ForwardOffset<Vector<ForwardOffset<Monster>, Monster>>.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: Color.self)
|
||||
_v.finish()
|
||||
}
|
||||
@@ -334,4 +416,3 @@ extension Monster: Encodable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user