[Swift] Flexbuffers native swift port (#8577)

* Offical Swift port for FlexBuffers

This is the offical port for FlexBuffers within
swift, and it introcudes a Common Module where code
is shared between flatbuffers and flexbuffers.

Writing most supported values like maps, vectors,
nil and scalars into a flexbuffer buffer. And includes
tests to verify that its similar to cpp

* Reading a flexbuffer

Implementing reading from a flexbuffer, enabling
most of the buffers features, like most types, maps, vectors,
typedvectors, and fixedtypedvectors.

Currently, if an offset/object cant be read we default to a swift
nil instead of the default flexbuffers 'null' with all values.

* Fixes bazel breaking due to new project structure

Address warnings within the library

* Adds comment on why we added the code & properly enforce the amout of bytes needed
This commit is contained in:
mustiikhalil
2025-06-22 08:36:38 +02:00
committed by GitHub
parent 595ac94a6a
commit 5a95b7b6bc
34 changed files with 3423 additions and 100 deletions

View File

@@ -343,19 +343,6 @@ public struct FlatBufferBuilder {
}
}
/// Gets the padding for the current element
/// - Parameters:
/// - bufSize: Current size of the buffer + the offset of the object to be written
/// - elementSize: Element size
@inline(__always)
@usableFromInline
mutating internal func padding(
bufSize: UInt32,
elementSize: UInt32) -> UInt32
{
((~bufSize) &+ 1) & (elementSize &- 1)
}
/// Prealigns the buffer before writting a new object into the buffer
/// - Parameters:
/// - len:Length of the object
@@ -364,11 +351,9 @@ public struct FlatBufferBuilder {
@usableFromInline
mutating internal func preAlign(len: Int, alignment: Int) {
minAlignment(size: alignment)
_bb.fill(
padding: Int(
padding(
bufSize: _bb.size &+ UOffset(len),
elementSize: UOffset(alignment))))
_bb.fill(padding: numericCast(padding(
bufSize: numericCast(_bb.size) &+ numericCast(len),
elementSize: numericCast(alignment))))
}
/// Prealigns the buffer before writting a new object into the buffer