[Swift] Implements FlatbuffersVector which confirms to RandomAccessCollection (#8752)

* Implements FlatbuffersVector in swift

Implements FlatbuffersVector which confirms to RandomAccessCollection,
this would give us semi-native sugary syntax to all the arrays in swift port.

This work will also be the foundation of using arrays in swift

* Fix failing tests for Swift
This commit is contained in:
mustiikhalil
2025-11-05 00:53:59 +01:00
committed by GitHub
parent 78a3d59a65
commit 5fe90a9160
63 changed files with 1554 additions and 1650 deletions

View File

@@ -99,13 +99,17 @@ final class FlatbuffersVerifierTests: XCTestCase {
func testVeriferInitPassing() {
let memory = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 1)
var buffer = ByteBuffer(assumingMemoryBound: memory, capacity: Int(FlatBufferMaxSize) - 1)
var buffer = ByteBuffer(
assumingMemoryBound: memory,
capacity: Int(FlatBufferMaxSize) - 1)
XCTAssertNoThrow(try Verifier(buffer: &buffer))
}
func testVeriferInitFailing() {
let memory = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 1)
var buffer = ByteBuffer(assumingMemoryBound: memory, capacity: Int(FlatBufferMaxSize) + 1)
var buffer = ByteBuffer(
assumingMemoryBound: memory,
capacity: Int(FlatBufferMaxSize) + 1)
XCTAssertThrowsError(try Verifier(buffer: &buffer))
}
@@ -403,8 +407,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)
}