mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
[Swift] Inline arrays (#8755)
Implements InlineArrays which allow us to use Flatbuffers arrays within Structs natively, and also implements FlatbufferVectors as a secondary API when using mutable Structs Fixes mutations within fixed sizes arrays Adds tests and remove inout and mutating from generated objects in favor of borrowing --------- Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
@@ -69,5 +69,5 @@ public protocol ObjectAPIPacker {
|
||||
static func pack(_ builder: inout FlatBufferBuilder, obj: inout T) -> Offset
|
||||
|
||||
/// ``unpack()`` unpacks a ``FlatBuffers`` object into a Native swift object.
|
||||
mutating func unpack() -> T
|
||||
func unpack() -> T
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ extension String: ObjectAPIPacker {
|
||||
builder.create(string: obj)
|
||||
}
|
||||
|
||||
public mutating func unpack() -> String {
|
||||
public func unpack() -> String {
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +48,16 @@ public struct Struct {
|
||||
let r = bb.read(def: T.self, position: Int(o &+ position))
|
||||
return r
|
||||
}
|
||||
|
||||
public func vector<T>(
|
||||
at off: Int32,
|
||||
count: Int,
|
||||
size: Int) -> FlatbufferVector<T>
|
||||
{
|
||||
FlatbufferVector(
|
||||
bb: bb,
|
||||
startPosition: position &+ off,
|
||||
count: count,
|
||||
byteSize: size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,6 @@ public struct Table {
|
||||
if offset == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
return vector(count: offset)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user