mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-06 03:06:54 +00:00
[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:
@@ -26,11 +26,11 @@ import Foundation
|
||||
///
|
||||
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
|
||||
/// the ``ByteBuffer`` and verifies the buffer by calling ``getCheckedRoot(byteBuffer:options:)``
|
||||
public func getPrefixedSizeCheckedRoot<T: FlatBufferObject & Verifiable>(
|
||||
public func getPrefixedSizeCheckedRoot<T: FlatBufferTable & Verifiable>(
|
||||
byteBuffer: inout ByteBuffer,
|
||||
fileId: String? = nil,
|
||||
options: VerifierOptions = .init()
|
||||
) throws -> T {
|
||||
options: VerifierOptions = .init()) throws -> T
|
||||
{
|
||||
byteBuffer.skipPrefix()
|
||||
return try getCheckedRoot(
|
||||
byteBuffer: &byteBuffer,
|
||||
@@ -48,11 +48,11 @@ public func getPrefixedSizeCheckedRoot<T: FlatBufferObject & Verifiable>(
|
||||
///
|
||||
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
|
||||
/// the ``ByteBuffer`` and verifies the buffer by calling ``getCheckedRoot(byteBuffer:options:)``
|
||||
public func getCheckedPrefixedSizeRoot<T: FlatBufferObject & Verifiable>(
|
||||
public func getCheckedPrefixedSizeRoot<T: FlatBufferTable & Verifiable>(
|
||||
byteBuffer: inout ByteBuffer,
|
||||
fileId: String? = nil,
|
||||
options: VerifierOptions = .init()
|
||||
) throws -> T {
|
||||
options: VerifierOptions = .init()) throws -> T
|
||||
{
|
||||
let prefix = byteBuffer.skipPrefix()
|
||||
if prefix != byteBuffer.size {
|
||||
throw FlatbuffersErrors.prefixedSizeNotEqualToBufferSize
|
||||
@@ -70,9 +70,8 @@ public func getCheckedPrefixedSizeRoot<T: FlatBufferObject & Verifiable>(
|
||||
///
|
||||
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
|
||||
/// the ``ByteBuffer`` and then calls ``getRoot(byteBuffer:)``
|
||||
public func getPrefixedSizeRoot<T: FlatBufferObject>(
|
||||
byteBuffer: inout ByteBuffer
|
||||
)
|
||||
public func getPrefixedSizeRoot<T: FlatBufferTable>(
|
||||
byteBuffer: inout ByteBuffer)
|
||||
-> T
|
||||
{
|
||||
byteBuffer.skipPrefix()
|
||||
@@ -90,11 +89,11 @@ public func getPrefixedSizeRoot<T: FlatBufferObject>(
|
||||
/// ``getCheckedRoot(byteBuffer:options:)`` Takes in a ``ByteBuffer`` and verifies
|
||||
/// that by creating a ``Verifier`` and checkes if all the `Bytes` and correctly aligned
|
||||
/// and within the ``ByteBuffer`` range.
|
||||
public func getCheckedRoot<T: FlatBufferObject & Verifiable>(
|
||||
public func getCheckedRoot<T: FlatBufferTable & Verifiable>(
|
||||
byteBuffer: inout ByteBuffer,
|
||||
fileId: String? = nil,
|
||||
options: VerifierOptions = .init()
|
||||
) throws -> T {
|
||||
options: VerifierOptions = .init()) throws -> T
|
||||
{
|
||||
var verifier = try Verifier(buffer: &byteBuffer, options: options)
|
||||
if let fileId = fileId {
|
||||
try verifier.verify(id: fileId)
|
||||
@@ -109,7 +108,7 @@ public func getCheckedRoot<T: FlatBufferObject & Verifiable>(
|
||||
/// Returns a `NON-Checked` flatbuffers object
|
||||
/// - Parameter byteBuffer: Buffer that contains data
|
||||
/// - Returns: Returns a Flatbuffers object
|
||||
public func getRoot<T: FlatBufferObject>(byteBuffer: inout ByteBuffer) -> T {
|
||||
public func getRoot<T: FlatBufferTable>(byteBuffer: inout ByteBuffer) -> T {
|
||||
T.init(
|
||||
byteBuffer,
|
||||
o: Int32(byteBuffer.read(def: UOffset.self, position: byteBuffer.reader))
|
||||
|
||||
Reference in New Issue
Block a user