mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 20:36: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:
@@ -17,7 +17,7 @@
|
||||
import Foundation
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
import Common
|
||||
#endif
|
||||
|
||||
/// Enum is a protocol that all flatbuffers enums should conform to
|
||||
@@ -28,8 +28,13 @@ public protocol Enum {
|
||||
associatedtype T: Scalar & Verifiable
|
||||
/// Size of the current associatedtype in the enum
|
||||
static var byteSize: Int { get }
|
||||
/// Provides a static min value in case we fail to decode
|
||||
/// in vectors
|
||||
static var min: Self { get }
|
||||
/// The current value the enum hosts
|
||||
var value: T { get }
|
||||
|
||||
init?(rawValue: T)
|
||||
}
|
||||
|
||||
extension Enum where Self: Verifiable {
|
||||
@@ -44,8 +49,8 @@ extension Enum where Self: Verifiable {
|
||||
public static func verify<T>(
|
||||
_ verifier: inout Verifier,
|
||||
at position: Int,
|
||||
of type: T.Type
|
||||
) throws where T: Verifiable {
|
||||
of type: T.Type) throws where T: Verifiable
|
||||
{
|
||||
try verifier.inBuffer(position: position, of: type.self)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user