[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

@@ -45,8 +45,8 @@ public struct TableVerifier {
position: Int,
vtable: Int,
vtableLength: Int,
verifier: inout Verifier
) {
verifier: inout Verifier)
{
_position = position
_vtable = vtable
_vtableLength = vtableLength
@@ -84,8 +84,8 @@ public struct TableVerifier {
field: VOffset,
fieldName: String,
required: Bool,
type: T.Type
) throws where T: Verifiable {
type: T.Type) throws where T: Verifiable
{
let derefValue = try dereference(field)
if let value = derefValue {
@@ -115,9 +115,9 @@ public struct TableVerifier {
unionKeyName: String,
fieldName: String,
required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void
) throws
where T: UnionEnum {
completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
where T: UnionEnum
{
let keyPos = try dereference(key)
let valPos = try dereference(field)
@@ -131,7 +131,7 @@ public struct TableVerifier {
}
if let _key = keyPos,
let _val = valPos
let _val = valPos
{
/// verifiying that the key is within the buffer
try T.T.verify(&_verifier, at: _key, of: T.T.self)
@@ -172,14 +172,14 @@ public struct TableVerifier {
unionKeyName: String,
fieldName: String,
required: Bool,
completion: @escaping (inout Verifier, T, Int) throws -> Void
) throws
where T: UnionEnum {
completion: @escaping (inout Verifier, T, Int) throws -> Void) throws
where T: UnionEnum
{
let keyVectorPosition = try dereference(key)
let offsetVectorPosition = try dereference(field)
if let keyPos = keyVectorPosition,
let valPos = offsetVectorPosition
let valPos = offsetVectorPosition
{
try UnionVector<T>.verify(
&_verifier,