Fix vector of strings for Go
Mirrors Java patch 39d4b7e2bf
Change-Id: If8d0ab29f6eb508a156d468aeb0a9d5410149e53
This commit is contained in:
parent
7b8053570e
commit
ef03cf46e4
|
@ -26,7 +26,6 @@ func (t *Table) Indirect(off UOffsetT) UOffsetT {
|
|||
|
||||
// String gets a string from data stored inside the flatbuffer.
|
||||
func (t *Table) String(off UOffsetT) string {
|
||||
off += t.Pos
|
||||
off += GetUOffsetT(t.Bytes[off:])
|
||||
start := off + UOffsetT(SizeUOffsetT)
|
||||
length := GetUOffsetT(t.Bytes[off:])
|
||||
|
|
|
@ -235,7 +235,7 @@ static void GetStringField(const StructDef &struct_def,
|
|||
code += " " + MakeCamel(field.name);
|
||||
code += "() " + TypeName(field) + " ";
|
||||
code += OffsetPrefix(field) + "\t\treturn " + GenGetter(field.value.type);
|
||||
code += "(o)\n\t}\n\treturn \"\"\n";
|
||||
code += "(o + rcv._tab.Pos)\n\t}\n\treturn \"\"\n";
|
||||
code += "}\n\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func (rcv *Monster) Hp() int16 {
|
|||
func (rcv *Monster) Name() string {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
|
||||
if o != 0 {
|
||||
return rcv._tab.String(o)
|
||||
return rcv._tab.String(o + rcv._tab.Pos)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -235,6 +235,18 @@ func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string,
|
|||
if 100 != sum {
|
||||
fail(FailString("test0 and test1 sum", 100, sum))
|
||||
}
|
||||
|
||||
if got := monster.TestarrayofstringLength(); 2 != got {
|
||||
fail(FailString("Testarrayofstring length", 2, got))
|
||||
}
|
||||
|
||||
if got := monster.Testarrayofstring(0); "test1" != got {
|
||||
fail(FailString("Testarrayofstring(0)", "test1", got))
|
||||
}
|
||||
|
||||
if got := monster.Testarrayofstring(1); "test2" != got {
|
||||
fail(FailString("Testarrayofstring(1)", "test2", got))
|
||||
}
|
||||
}
|
||||
|
||||
// Low level stress/fuzz test: serialize/deserialize a variety of
|
||||
|
@ -891,6 +903,9 @@ func CheckManualBuild(fail func(string, ...interface{})) ([]byte, flatbuffers.UO
|
|||
func CheckGeneratedBuild(fail func(string, ...interface{})) ([]byte, flatbuffers.UOffsetT) {
|
||||
b := flatbuffers.NewBuilder(0)
|
||||
str := b.CreateString("MyMonster")
|
||||
test1 := b.CreateString("test1")
|
||||
test2 := b.CreateString("test2")
|
||||
|
||||
example.MonsterStartInventoryVector(b, 5)
|
||||
b.PrependByte(4)
|
||||
b.PrependByte(3)
|
||||
|
@ -908,6 +923,11 @@ func CheckGeneratedBuild(fail func(string, ...interface{})) ([]byte, flatbuffers
|
|||
example.CreateTest(b, 30, 40)
|
||||
test4 := b.EndVector(2)
|
||||
|
||||
example.MonsterStartTestarrayofstringVector(b, 2)
|
||||
b.PrependUOffsetT(test2)
|
||||
b.PrependUOffsetT(test1)
|
||||
testArrayOfString := b.EndVector(2)
|
||||
|
||||
example.MonsterStart(b)
|
||||
|
||||
pos := example.CreateVec3(b, 1.0, 2.0, 3.0, 3.0, 4, 5, 6)
|
||||
|
@ -919,6 +939,7 @@ func CheckGeneratedBuild(fail func(string, ...interface{})) ([]byte, flatbuffers
|
|||
example.MonsterAddTestType(b, 1)
|
||||
example.MonsterAddTest(b, mon2)
|
||||
example.MonsterAddTest4(b, test4)
|
||||
example.MonsterAddTestarrayofstring(b, testArrayOfString)
|
||||
mon := example.MonsterEnd(b)
|
||||
|
||||
b.Finish(mon)
|
||||
|
|
Loading…
Reference in New Issue