[Swift] Rebuild the way swift handles structs from scratch (#6326)

* Rebuild the way swift handles structs from scratch

* Updates docs, and sample binary

* Replaces InMemory to Mutable

* Migrates docs from inmemory

* use inline for some functions

* Renamed Mutable objects

* Updates documentation
This commit is contained in:
mustiikhalil
2020-12-18 01:55:32 +03:00
committed by GitHub
parent 05192553f4
commit 4e79d129cb
21 changed files with 1051 additions and 720 deletions

View File

@@ -2,7 +2,14 @@
import FlatBuffers
public struct Property: Readable {
public struct Property: NativeStruct {
static func validateVersion() { FlatBuffersVersion_1_12_0() }
public var property: Bool
}
public struct Property_Mutable: FlatBufferObject {
static func validateVersion() { FlatBuffersVersion_1_12_0() }
public var __buffer: ByteBuffer! { return _accessor.bb }
@@ -16,12 +23,6 @@ public struct Property: Readable {
@discardableResult public func mutate(property: Bool) -> Bool { return _accessor.mutate(property, index: 0) }
}
public func createProperty(builder: inout FlatBufferBuilder, property: Bool = false) -> Offset<UOffset> {
builder.createStructOf(size: Property.size, alignment: Property.alignment)
builder.reverseAdd(v: property, postion: 0)
return builder.endStruct()
}
public struct TestMutatingBool: FlatBufferObject {
static func validateVersion() { FlatBuffersVersion_1_12_0() }
@@ -39,9 +40,10 @@ public struct TestMutatingBool: FlatBufferObject {
var p: VOffset { self.rawValue }
}
public var b: Property? { let o = _accessor.offset(VTOFFSET.b.v); return o == 0 ? nil : Property(_accessor.bb, o: o + _accessor.postion) }
public var b: Property? { let o = _accessor.offset(VTOFFSET.b.v); return o == 0 ? nil : _accessor.readBuffer(of: Property.self, at: o) }
public var mutableB: Property_Mutable? { let o = _accessor.offset(VTOFFSET.b.v); return o == 0 ? nil : Property_Mutable(_accessor.bb, o: o + _accessor.postion) }
public static func startTestMutatingBool(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
public static func add(b: Offset<UOffset>, _ fbb: inout FlatBufferBuilder) { fbb.add(structOffset: VTOFFSET.b.p) }
public static func add(b: Property?, _ fbb: inout FlatBufferBuilder) { guard let b = b else { return }; _ = fbb.create(struct: b, position: VTOFFSET.b.p) }
public static func endTestMutatingBool(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end }
}