Implements verifier and code gen for swift (#6373)

Updates test cases on linux

Adhere to new protocol naming

Adds fuzzing

Adds documentation

Adds support for string unions

Updated fuzzer generated code
This commit is contained in:
mustiikhalil
2021-05-14 20:59:28 +03:00
committed by GitHub
parent 04b10f5a3a
commit a5175c513a
38 changed files with 2291 additions and 168 deletions

View File

@@ -52,22 +52,36 @@ final class FlatBuffersTests: XCTestCase {
func testCreateFinish() {
var b = FlatBufferBuilder(initialSize: 16)
let countryOff = Country.createCountry(builder: &b, name: country, log: 200, lan: 100)
let countryOff = Country.createCountry(
builder: &b,
name: country,
log: 200,
lan: 100)
b.finish(offset: countryOff)
// swiftformat:disable all
let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
// swiftformat:enable all
XCTAssertEqual(b.sizedByteArray, v)
}
func testCreateFinishWithPrefix() {
var b = FlatBufferBuilder(initialSize: 16)
let countryOff = Country.createCountry(builder: &b, name: country, log: 200, lan: 100)
let countryOff = Country.createCountry(
builder: &b,
name: country,
log: 200,
lan: 100)
b.finish(offset: countryOff, addPrefix: true)
// swiftformat:disable all
let v: [UInt8] = [44, 0, 0, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
// swiftformat:enable all
XCTAssertEqual(b.sizedByteArray, v)
}
func testReadCountry() {
// swiftformat:disable all
let v: [UInt8] = [16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 4, 0, 8, 0, 12, 0, 10, 0, 0, 0, 12, 0, 0, 0, 100, 0, 0, 0, 200, 0, 0, 0, 6, 0, 0, 0, 78, 111, 114, 119, 97, 121, 0, 0]
// swiftformat:enable all
let buffer = ByteBuffer(bytes: v)
let c = Country.getRootAsCountry(buffer)
XCTAssertEqual(c.lan, 100)
@@ -115,14 +129,20 @@ class Country {
__t = t
}
var lan: Int32 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(of: Int32.self, at: o) }
var log: Int32 { let o = __t.offset(8); return o == 0 ? 0 : __t.readBuffer(of: Int32.self, at: o) }
var lan: Int32 { let o = __t.offset(6); return o == 0 ? 0 : __t.readBuffer(
of: Int32.self,
at: o) }
var log: Int32 { let o = __t.offset(8); return o == 0 ? 0 : __t.readBuffer(
of: Int32.self,
at: o) }
var nameVector: [UInt8]? { __t.getVector(at: 4) }
var name: String? { let o = __t.offset(4); return o == 0 ? nil : __t.string(at: o) }
@inlinable
static func getRootAsCountry(_ bb: ByteBuffer) -> Country {
Country(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: 0))))
Country(Table(
bb: bb,
position: Int32(bb.read(def: UOffset.self, position: 0))))
}
@inlinable
@@ -132,7 +152,11 @@ class Country {
log: Int32,
lan: Int32) -> Offset
{
createCountry(builder: &builder, offset: builder.create(string: name), log: log, lan: lan)
createCountry(
builder: &builder,
offset: builder.create(string: name),
log: log,
lan: lan)
}
@inlinable