mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 01:47:04 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user