Skip to content

Commit

Permalink
Updating object updates according to review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hassila committed Jan 11, 2017
1 parent 3c3107d commit c306411
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 83 deletions.
6 changes: 3 additions & 3 deletions FlatBuffersSwift/FlatBuffersBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public final class FlatBuffersBuilder {
- Returns: The current cursor position (Note: What is the use case of the return value?)
*/
@discardableResult
public func insert(propertyIndex : Int, offset : Offset) throws -> Int{
public func insert(offset : Offset, toStartedObjectAt propertyIndex : Int) throws -> Int{
guard objectStart > -1 else {
throw FlatBuffersBuildError.noOpenObject
}
Expand All @@ -268,7 +268,7 @@ public final class FlatBuffersBuilder {
- defaultValue: If configured to skip default values, a value
matching this default value will not be written to the buffer.
*/
public func insert<T : Scalar>(propertyIndex : Int, value : T, defaultValue : T) throws {
public func insert<T : Scalar>(value : T, defaultValue : T, toStartedObjectAt propertyIndex : Int) throws {
guard objectStart > -1 else {
throw FlatBuffersBuildError.noOpenObject
}
Expand All @@ -290,7 +290,7 @@ public final class FlatBuffersBuilder {
- parameters:
- propertyIndex: The index of the property to update
*/
public func insertCurrentOffsetAsProperty(propertyIndex : Int) throws {
public func insertCurrentOffsetAsProperty(toStartedObjectAt propertyIndex : Int) throws {
guard objectStart > -1 else {
throw FlatBuffersBuildError.noOpenObject
}
Expand Down
88 changes: 44 additions & 44 deletions FlatBuffersSwiftTests/BuilderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ class BuilderTest: XCTestCase {
func testObjectWithNameAndAge() {
let s = try!builder.insert(value: "maxim")
try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 1, value: UInt8(35), defaultValue: 0)
try!builder.insert(propertyIndex: 0, offset: s)
try!builder.insert(value: UInt8(35), defaultValue: 0, toStartedObjectAt: 1)
try!builder.insert(offset: s, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -397,9 +397,9 @@ class BuilderTest: XCTestCase {
let s = try!builder.insert(value: "maxim")
let s2 = try!builder.insert(value: "maxim")
try!builder.startObject(numOfProperties: 3)
try!builder.insert(propertyIndex: 1, value: UInt8(35), defaultValue: 0)
try!builder.insert(propertyIndex: 0, offset: s)
try!builder.insert(propertyIndex: 2, offset: s2)
try!builder.insert(value: UInt8(35), defaultValue: 0, toStartedObjectAt: 1)
try!builder.insert(offset: s, toStartedObjectAt: 0)
try!builder.insert(offset: s2, toStartedObjectAt: 2)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -453,9 +453,9 @@ class BuilderTest: XCTestCase {
let s = try!builder.insert(value: "maxim")
let s2 = try!builder.insert(value: "maxim")
try!builder.startObject(numOfProperties: 3)
try!builder.insert(propertyIndex: 1, value: UInt8(35), defaultValue: 0)
try!builder.insert(propertyIndex: 0, offset: s)
try!builder.insert(propertyIndex: 2, offset: s2)
try!builder.insert(value: UInt8(35), defaultValue: 0, toStartedObjectAt:1)
try!builder.insert(offset: s, toStartedObjectAt: 0)
try!builder.insert(offset: s2, toStartedObjectAt: 2)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -518,9 +518,9 @@ class BuilderTest: XCTestCase {
func testObjectWithNameAndAgeAndReferenceToSelf() {
let s = try!builder.insert(value: "maxim")
try!builder.startObject(numOfProperties: 3)
try!builder.insert(propertyIndex: 1, value: UInt8(35), defaultValue: 0)
try!builder.insert(propertyIndex: 0, offset: s)
let cursor = try!builder.insert(propertyIndex: 2, offset: 0)
try!builder.insert(value: UInt8(35), defaultValue: 0, toStartedObjectAt: 1)
try!builder.insert(offset: s, toStartedObjectAt: 0)
let cursor = try!builder.insert(offset: 0, toStartedObjectAt: 2)
let o = try!builder.endObject()
try!builder.update(offset: o, atCursor: cursor)
try!builder.finish(offset: o, fileIdentifier: nil)
Expand Down Expand Up @@ -572,9 +572,9 @@ class BuilderTest: XCTestCase {

func testObjectWithStruct(){
try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 1, value: UInt8(35), defaultValue: 0)
try!builder.insert(value: UInt8(35), defaultValue: 0, toStartedObjectAt:1)
builder.insert(value: S1(i1: 45, i2: 78))
try! builder.insertCurrentOffsetAsProperty(propertyIndex: 0)
try! builder.insertCurrentOffsetAsProperty(toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -614,7 +614,7 @@ class BuilderTest: XCTestCase {
builder.insert(value: Int16(19))
let v = builder.endVector()
try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -656,7 +656,7 @@ class BuilderTest: XCTestCase {
builder.insert(value: false)
let v = builder.endVector()
try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -697,7 +697,7 @@ class BuilderTest: XCTestCase {
builder.insert(value: S1(i1: 13, i2: 17))
let v = builder.endVector()
try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -755,15 +755,15 @@ class BuilderTest: XCTestCase {

func testObjectWithVectorToOtherTwoObjects(){
try!builder.startObject(numOfProperties: 3)
try!builder.insert(propertyIndex: 0, value: Int8(12), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int8(13), defaultValue: 0)
try!builder.insert(propertyIndex: 2, value: Int8(14), defaultValue: 0)
try!builder.insert(value: Int8(12), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int8(13), defaultValue: 0, toStartedObjectAt: 1)
try!builder.insert(value: Int8(14), defaultValue: 0, toStartedObjectAt: 2)
let o1 = try!builder.endObject()

try!builder.startObject(numOfProperties: 3)
try!builder.insert(propertyIndex: 0, value: Int8(22), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int8(23), defaultValue: 0)
try!builder.insert(propertyIndex: 2, value: Int8(24), defaultValue: 0)
try!builder.insert(value: Int8(22), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int8(23), defaultValue: 0, toStartedObjectAt: 1)
try!builder.insert(value: Int8(24), defaultValue: 0, toStartedObjectAt: 2)
let o2 = try!builder.endObject()

try!builder.startVector(count: 2, elementSize: 1)
Expand All @@ -772,7 +772,7 @@ class BuilderTest: XCTestCase {
let v = builder.endVector()

try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -855,13 +855,13 @@ class BuilderTest: XCTestCase {

func testObjectWithVectorToOtherTwoObjectsAndVTableReuese(){
try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 0, value: Int16(12), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int16(13), defaultValue: 0)
try!builder.insert(value: Int16(12), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int16(13), defaultValue: 0, toStartedObjectAt: 1)
let o1 = try!builder.endObject()

try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 0, value: Int16(22), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int16(23), defaultValue: 0)
try!builder.insert(value: Int16(22), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int16(23), defaultValue: 0, toStartedObjectAt: 1)
let o2 = try!builder.endObject()

try!builder.startVector(count: 2, elementSize: 1)
Expand All @@ -870,7 +870,7 @@ class BuilderTest: XCTestCase {
let v = builder.endVector()

try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -941,13 +941,13 @@ class BuilderTest: XCTestCase {
func testObjectWithVectorToOtherTwoObjectsAndVTableWithoutReuese(){
builder = FlatBuffersBuilder(config: FlatBuffersBuildConfig(initialCapacity: 1, uniqueStrings: true, uniqueTables: true, uniqueVTables: false, forceDefaults: false, nullTerminatedUTF8: false))
try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 0, value: Int16(12), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int16(13), defaultValue: 0)
try!builder.insert(value: Int16(12), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int16(13), defaultValue: 0, toStartedObjectAt: 1)
let o1 = try!builder.endObject()

try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 0, value: Int16(22), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int16(23), defaultValue: 0)
try!builder.insert(value: Int16(22), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int16(23), defaultValue: 0, toStartedObjectAt: 1)
let o2 = try!builder.endObject()

try!builder.startVector(count: 2, elementSize: 1)
Expand All @@ -956,7 +956,7 @@ class BuilderTest: XCTestCase {
let v = builder.endVector()

try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()
try!builder.finish(offset: o, fileIdentifier: nil)

Expand Down Expand Up @@ -1040,7 +1040,7 @@ class BuilderTest: XCTestCase {
let c2 = try!builder.insert(offset: nil)
let v = builder.endVector()
try!builder.startObject(numOfProperties: 1)
try! builder.insert(propertyIndex: 0, offset: v)
try! builder.insert(offset: v, toStartedObjectAt: 0)
let o = try!builder.endObject()

try!builder.update(offset: o, atCursor: c1)
Expand Down Expand Up @@ -1128,7 +1128,7 @@ class BuilderTest: XCTestCase {
func testAddPropertyWithoutOpenObject(){
var itThrows = false
do {
try builder.insert(propertyIndex: 0, value: 1, defaultValue: 0)
try builder.insert(value: 1, defaultValue: 0, toStartedObjectAt: 0)
} catch {
itThrows = true
}
Expand All @@ -1139,7 +1139,7 @@ class BuilderTest: XCTestCase {
var itThrows = false
try!builder.startObject(numOfProperties: 1)
do {
try builder.insert(propertyIndex: 1, value: 1, defaultValue: 0)
try builder.insert(value: 1, defaultValue: 0, toStartedObjectAt: 1)
} catch {
itThrows = true
}
Expand All @@ -1149,7 +1149,7 @@ class BuilderTest: XCTestCase {
func testAddOffsetWithoutOpenObject(){
var itThrows = false
do {
try builder.insert(propertyIndex: 0, offset: 0)
try builder.insert(offset: 0, toStartedObjectAt: 0)
} catch {
itThrows = true
}
Expand All @@ -1160,7 +1160,7 @@ class BuilderTest: XCTestCase {
var itThrows = false
try!builder.startObject(numOfProperties: 1)
do {
try builder.insert(propertyIndex: 1, offset: 0)
try builder.insert(offset: 0, toStartedObjectAt: 1)
} catch {
itThrows = true
}
Expand All @@ -1170,7 +1170,7 @@ class BuilderTest: XCTestCase {
func testAddCurrentOffsetWithoutOpenObject(){
var itThrows = false
do {
try builder.insertCurrentOffsetAsProperty(propertyIndex: 0)
try builder.insertCurrentOffsetAsProperty(toStartedObjectAt: 0)
} catch {
itThrows = true
}
Expand All @@ -1181,7 +1181,7 @@ class BuilderTest: XCTestCase {
var itThrows = false
try!builder.startObject(numOfProperties: 1)
do {
try builder.insertCurrentOffsetAsProperty(propertyIndex: 1)
try builder.insertCurrentOffsetAsProperty(toStartedObjectAt: 1)
} catch {
itThrows = true
}
Expand Down Expand Up @@ -1269,8 +1269,8 @@ class BuilderTest: XCTestCase {

func testDefaultValuesNotSet(){
try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 0, value: Int32(12), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int32(5), defaultValue: 5)
try!builder.insert(value: Int32(12), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int32(5), defaultValue: 5, toStartedObjectAt: 1)
_ = try!builder.endObject()

assertByte(with: 8)
Expand All @@ -1294,8 +1294,8 @@ class BuilderTest: XCTestCase {
func testDefaultValuesForced(){
builder = FlatBuffersBuilder(config: FlatBuffersBuildConfig(initialCapacity: 1, uniqueStrings: true, uniqueTables: true, uniqueVTables: true, forceDefaults: true, nullTerminatedUTF8: false))
try!builder.startObject(numOfProperties: 2)
try!builder.insert(propertyIndex: 0, value: Int32(12), defaultValue: 0)
try!builder.insert(propertyIndex: 1, value: Int32(5), defaultValue: 5)
try!builder.insert(value: Int32(12), defaultValue: 0, toStartedObjectAt: 0)
try!builder.insert(value: Int32(5), defaultValue: 5, toStartedObjectAt: 1)
_ = try!builder.endObject()

assertByte(with: 8)
Expand Down
8 changes: 4 additions & 4 deletions FlatBuffersSwiftTests/FBReaderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ class FlatBuffersReaderTest: XCTestCase {
)
let sOffset = try! fbb.insert(value: "max")
try! fbb.startObject(numOfProperties: 3)
try! fbb.insert(propertyIndex: 0, value: true, defaultValue: false)
try! fbb.insert(propertyIndex: 1, offset: sOffset)
try! fbb.insert(value: true, defaultValue: false, toStartedObjectAt: 0)
try! fbb.insert(offset: sOffset, toStartedObjectAt: 1)
let oOffset = try! fbb.endObject()
try! fbb.finish(offset: oOffset, fileIdentifier: nil)
let data = fbb.makeData
Expand Down Expand Up @@ -281,8 +281,8 @@ class FlatBuffersReaderTest: XCTestCase {
let bVectorOffset = fbb.endVector()

try! fbb.startObject(numOfProperties: 2)
try! fbb.insert(propertyIndex: 0, offset: sVectorOffset)
try! fbb.insert(propertyIndex: 1, offset: bVectorOffset)
try! fbb.insert(offset: sVectorOffset, toStartedObjectAt: 0)
try! fbb.insert(offset: bVectorOffset, toStartedObjectAt: 1)
let oOffset = try! fbb.endObject()
try! fbb.finish(offset: oOffset, fileIdentifier: nil)
let data = fbb.makeData
Expand Down
Loading

0 comments on commit c306411

Please sign in to comment.