Commit bee1df96 authored by Somo's avatar Somo Committed by Wouter van Oortmerssen

[Go] Replace references to hardcoded ”Monster" etc with idiomatic go wherever possible (#5716)

* go: replace objAPI-generated Pack func with method

See discussion at https://github.com/google/flatbuffers/issues/5668

* go: replace generated union type UnPack func with method

Similar to discussion https://github.com/google/flatbuffers/issues/5668

But signature:
```
func AnyUnPack(t Any, table flatbuffers.Table) *AnyT
```

Becomes,
```
func (rcv Any) UnPack(table flatbuffers.Table) *AnyT
```
parent 01189d7e
...@@ -816,8 +816,8 @@ class GoGenerator : public BaseGenerator { ...@@ -816,8 +816,8 @@ class GoGenerator : public BaseGenerator {
void GenNativeUnionPack(const EnumDef &enum_def, std::string *code_ptr) { void GenNativeUnionPack(const EnumDef &enum_def, std::string *code_ptr) {
std::string &code = *code_ptr; std::string &code = *code_ptr;
code += "func " + enum_def.name + "Pack(builder *flatbuffers.Builder, t *" + code += "func (t *" + NativeName(enum_def) +
NativeName(enum_def) + ") flatbuffers.UOffsetT {\n"; ") Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {\n";
code += "\tif t == nil {\n\t\treturn 0\n\t}\n"; code += "\tif t == nil {\n\t\treturn 0\n\t}\n";
code += "\tswitch t.Type {\n"; code += "\tswitch t.Type {\n";
...@@ -826,9 +826,8 @@ class GoGenerator : public BaseGenerator { ...@@ -826,9 +826,8 @@ class GoGenerator : public BaseGenerator {
const EnumVal &ev = **it2; const EnumVal &ev = **it2;
if (ev.IsZero()) continue; if (ev.IsZero()) continue;
code += "\tcase " + enum_def.name + ev.name + ":\n"; code += "\tcase " + enum_def.name + ev.name + ":\n";
code += "\t\treturn " + code += "\t\treturn t.Value.(" + NativeType(ev.union_type) +
WrapInNameSpaceAndTrack(*ev.union_type.struct_def) + ").Pack(builder)\n";
"Pack(builder, t.Value.(" + NativeType(ev.union_type) + "))\n";
} }
code += "\t}\n"; code += "\t}\n";
code += "\treturn 0\n"; code += "\treturn 0\n";
...@@ -838,9 +837,10 @@ class GoGenerator : public BaseGenerator { ...@@ -838,9 +837,10 @@ class GoGenerator : public BaseGenerator {
void GenNativeUnionUnPack(const EnumDef &enum_def, std::string *code_ptr) { void GenNativeUnionUnPack(const EnumDef &enum_def, std::string *code_ptr) {
std::string &code = *code_ptr; std::string &code = *code_ptr;
code += "func " + enum_def.name + "UnPack(t " + enum_def.name + code += "func (rcv " + enum_def.name +
", table flatbuffers.Table) *" + NativeName(enum_def) + " {\n"; ") UnPack(table flatbuffers.Table) *" + NativeName(enum_def) +
code += "\tswitch t {\n"; " {\n";
code += "\tswitch rcv {\n";
for (auto it2 = enum_def.Vals().begin(); it2 != enum_def.Vals().end(); for (auto it2 = enum_def.Vals().begin(); it2 != enum_def.Vals().end();
++it2) { ++it2) {
...@@ -862,9 +862,8 @@ class GoGenerator : public BaseGenerator { ...@@ -862,9 +862,8 @@ class GoGenerator : public BaseGenerator {
void GenNativeTablePack(const StructDef &struct_def, std::string *code_ptr) { void GenNativeTablePack(const StructDef &struct_def, std::string *code_ptr) {
std::string &code = *code_ptr; std::string &code = *code_ptr;
code += "func " + struct_def.name + code += "func (t *" + NativeName(struct_def) +
"Pack(builder *flatbuffers.Builder, t *" + NativeName(struct_def) + ") Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {\n";
") flatbuffers.UOffsetT {\n";
code += "\tif t == nil { return 0 }\n"; code += "\tif t == nil { return 0 }\n";
for (auto it = struct_def.fields.vec.begin(); for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end(); ++it) { it != struct_def.fields.vec.end(); ++it) {
...@@ -903,9 +902,8 @@ class GoGenerator : public BaseGenerator { ...@@ -903,9 +902,8 @@ class GoGenerator : public BaseGenerator {
code += "\t\t" + offsets + " := make([]flatbuffers.UOffsetT, " + code += "\t\t" + offsets + " := make([]flatbuffers.UOffsetT, " +
length + ")\n"; length + ")\n";
code += "\t\tfor j := 0; j < " + length + "; j++ {\n"; code += "\t\tfor j := 0; j < " + length + "; j++ {\n";
code += "\t\t\t" + offsets + "[j] = " + code += "\t\t\t" + offsets + "[j] = t." + MakeCamel(field.name) +
WrapInNameSpaceAndTrack(*field.value.type.struct_def) + "[j].Pack(builder)\n";
"Pack(builder, t." + MakeCamel(field.name) + "[j])\n";
code += "\t\t}\n"; code += "\t\t}\n";
} }
code += "\t\t" + struct_def.name + "Start" + MakeCamel(field.name) + code += "\t\t" + struct_def.name + "Start" + MakeCamel(field.name) +
...@@ -919,9 +917,7 @@ class GoGenerator : public BaseGenerator { ...@@ -919,9 +917,7 @@ class GoGenerator : public BaseGenerator {
")\n"; ")\n";
} else if (field.value.type.element == BASE_TYPE_STRUCT && } else if (field.value.type.element == BASE_TYPE_STRUCT &&
field.value.type.struct_def->fixed) { field.value.type.struct_def->fixed) {
code += "\t\t\t" + code += "\t\t\tt." + MakeCamel(field.name) + "[j].Pack(builder)\n";
WrapInNameSpaceAndTrack(*field.value.type.struct_def) +
"Pack(builder, t." + MakeCamel(field.name) + "[j])\n";
} else { } else {
code += "\t\t\tbuilder.PrependUOffsetT(" + offsets + "[j])\n"; code += "\t\t\tbuilder.PrependUOffsetT(" + offsets + "[j])\n";
} }
...@@ -930,13 +926,11 @@ class GoGenerator : public BaseGenerator { ...@@ -930,13 +926,11 @@ class GoGenerator : public BaseGenerator {
code += "\t}\n"; code += "\t}\n";
} else if (field.value.type.base_type == BASE_TYPE_STRUCT) { } else if (field.value.type.base_type == BASE_TYPE_STRUCT) {
if (field.value.type.struct_def->fixed) continue; if (field.value.type.struct_def->fixed) continue;
code += "\t" + offset + code += "\t" + offset + " := t." + MakeCamel(field.name) +
" := " + WrapInNameSpaceAndTrack(*field.value.type.struct_def) + ".Pack(builder)\n";
"Pack(builder, t." + MakeCamel(field.name) + ")\n";
} else if (field.value.type.base_type == BASE_TYPE_UNION) { } else if (field.value.type.base_type == BASE_TYPE_UNION) {
code += "\t" + offset + code += "\t" + offset + " := t." + MakeCamel(field.name) +
" := " + WrapInNameSpaceAndTrack(*field.value.type.enum_def) + ".Pack(builder)\n";
"Pack(builder, t." + MakeCamel(field.name) + ")\n";
code += "\t\n"; code += "\t\n";
} else { } else {
FLATBUFFERS_ASSERT(0); FLATBUFFERS_ASSERT(0);
...@@ -958,9 +952,8 @@ class GoGenerator : public BaseGenerator { ...@@ -958,9 +952,8 @@ class GoGenerator : public BaseGenerator {
} else { } else {
if (field.value.type.base_type == BASE_TYPE_STRUCT && if (field.value.type.base_type == BASE_TYPE_STRUCT &&
field.value.type.struct_def->fixed) { field.value.type.struct_def->fixed) {
code += "\t" + offset + " := " + code += "\t" + offset + " := t." + MakeCamel(field.name) +
WrapInNameSpaceAndTrack(*field.value.type.struct_def) + ".Pack(builder)\n";
"Pack(builder, t." + MakeCamel(field.name) + ")\n";
} else if (field.value.type.enum_def != nullptr && } else if (field.value.type.enum_def != nullptr &&
field.value.type.enum_def->is_union) { field.value.type.enum_def->is_union) {
code += "\tif t." + MakeCamel(field.name) + " != nil {\n"; code += "\tif t." + MakeCamel(field.name) + " != nil {\n";
...@@ -1029,14 +1022,13 @@ class GoGenerator : public BaseGenerator { ...@@ -1029,14 +1022,13 @@ class GoGenerator : public BaseGenerator {
code += "\tt." + field_name_camel + " = rcv." + field_name_camel + code += "\tt." + field_name_camel + " = rcv." + field_name_camel +
"(nil).UnPack()\n"; "(nil).UnPack()\n";
} else if (field.value.type.base_type == BASE_TYPE_UNION) { } else if (field.value.type.base_type == BASE_TYPE_UNION) {
const EnumDef &enum_def = *field.value.type.enum_def;
std::string field_table = MakeCamel(field.name, false) + "Table"; std::string field_table = MakeCamel(field.name, false) + "Table";
code += "\t" + field_table + " := flatbuffers.Table{}\n"; code += "\t" + field_table + " := flatbuffers.Table{}\n";
code += code +=
"\tif rcv." + MakeCamel(field.name) + "(&" + field_table + ") {\n"; "\tif rcv." + MakeCamel(field.name) + "(&" + field_table + ") {\n";
code += "\t\tt." + field_name_camel + " = " + enum_def.name + code += "\t\tt." + field_name_camel + " = rcv." +
"UnPack(rcv." + MakeCamel(field.name + UnionTypeFieldSuffix()) + MakeCamel(field.name + UnionTypeFieldSuffix()) + "().UnPack(" +
"(), " + field_table + ")\n"; field_table + ")\n";
code += "\t}\n"; code += "\t}\n";
} else { } else {
FLATBUFFERS_ASSERT(0); FLATBUFFERS_ASSERT(0);
...@@ -1056,9 +1048,8 @@ class GoGenerator : public BaseGenerator { ...@@ -1056,9 +1048,8 @@ class GoGenerator : public BaseGenerator {
void GenNativeStructPack(const StructDef &struct_def, std::string *code_ptr) { void GenNativeStructPack(const StructDef &struct_def, std::string *code_ptr) {
std::string &code = *code_ptr; std::string &code = *code_ptr;
code += "func " + struct_def.name + code += "func (t *" + NativeName(struct_def) +
"Pack(builder *flatbuffers.Builder, t *" + NativeName(struct_def) + ") Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {\n";
") flatbuffers.UOffsetT {\n";
code += "\tif t == nil { return 0 }\n"; code += "\tif t == nil { return 0 }\n";
code += "\treturn Create" + struct_def.name + "(builder"; code += "\treturn Create" + struct_def.name + "(builder";
StructPackArgs(struct_def, "", code_ptr); StructPackArgs(struct_def, "", code_ptr);
......
...@@ -11,7 +11,7 @@ type AbilityT struct { ...@@ -11,7 +11,7 @@ type AbilityT struct {
Distance uint32 Distance uint32
} }
func AbilityPack(builder *flatbuffers.Builder, t *AbilityT) flatbuffers.UOffsetT { func (t *AbilityT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
return CreateAbility(builder, t.Id, t.Distance) return CreateAbility(builder, t.Id, t.Distance)
} }
......
...@@ -45,23 +45,23 @@ type AnyT struct { ...@@ -45,23 +45,23 @@ type AnyT struct {
Value interface{} Value interface{}
} }
func AnyPack(builder *flatbuffers.Builder, t *AnyT) flatbuffers.UOffsetT { func (t *AnyT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { if t == nil {
return 0 return 0
} }
switch t.Type { switch t.Type {
case AnyMonster: case AnyMonster:
return MonsterPack(builder, t.Value.(*MonsterT)) return t.Value.(*MonsterT).Pack(builder)
case AnyTestSimpleTableWithEnum: case AnyTestSimpleTableWithEnum:
return TestSimpleTableWithEnumPack(builder, t.Value.(*TestSimpleTableWithEnumT)) return t.Value.(*TestSimpleTableWithEnumT).Pack(builder)
case AnyMyGame_Example2_Monster: case AnyMyGame_Example2_Monster:
return MyGame__Example2.MonsterPack(builder, t.Value.(*MyGame__Example2.MonsterT)) return t.Value.(*MyGame__Example2.MonsterT).Pack(builder)
} }
return 0 return 0
} }
func AnyUnPack(t Any, table flatbuffers.Table) *AnyT { func (rcv Any) UnPack(table flatbuffers.Table) *AnyT {
switch t { switch rcv {
case AnyMonster: case AnyMonster:
x := Monster{_tab: table} x := Monster{_tab: table}
return &AnyT{ Type: AnyMonster, Value: x.UnPack() } return &AnyT{ Type: AnyMonster, Value: x.UnPack() }
......
...@@ -43,23 +43,23 @@ type AnyAmbiguousAliasesT struct { ...@@ -43,23 +43,23 @@ type AnyAmbiguousAliasesT struct {
Value interface{} Value interface{}
} }
func AnyAmbiguousAliasesPack(builder *flatbuffers.Builder, t *AnyAmbiguousAliasesT) flatbuffers.UOffsetT { func (t *AnyAmbiguousAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { if t == nil {
return 0 return 0
} }
switch t.Type { switch t.Type {
case AnyAmbiguousAliasesM1: case AnyAmbiguousAliasesM1:
return MonsterPack(builder, t.Value.(*MonsterT)) return t.Value.(*MonsterT).Pack(builder)
case AnyAmbiguousAliasesM2: case AnyAmbiguousAliasesM2:
return MonsterPack(builder, t.Value.(*MonsterT)) return t.Value.(*MonsterT).Pack(builder)
case AnyAmbiguousAliasesM3: case AnyAmbiguousAliasesM3:
return MonsterPack(builder, t.Value.(*MonsterT)) return t.Value.(*MonsterT).Pack(builder)
} }
return 0 return 0
} }
func AnyAmbiguousAliasesUnPack(t AnyAmbiguousAliases, table flatbuffers.Table) *AnyAmbiguousAliasesT { func (rcv AnyAmbiguousAliases) UnPack(table flatbuffers.Table) *AnyAmbiguousAliasesT {
switch t { switch rcv {
case AnyAmbiguousAliasesM1: case AnyAmbiguousAliasesM1:
x := Monster{_tab: table} x := Monster{_tab: table}
return &AnyAmbiguousAliasesT{ Type: AnyAmbiguousAliasesM1, Value: x.UnPack() } return &AnyAmbiguousAliasesT{ Type: AnyAmbiguousAliasesM1, Value: x.UnPack() }
......
...@@ -45,23 +45,23 @@ type AnyUniqueAliasesT struct { ...@@ -45,23 +45,23 @@ type AnyUniqueAliasesT struct {
Value interface{} Value interface{}
} }
func AnyUniqueAliasesPack(builder *flatbuffers.Builder, t *AnyUniqueAliasesT) flatbuffers.UOffsetT { func (t *AnyUniqueAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { if t == nil {
return 0 return 0
} }
switch t.Type { switch t.Type {
case AnyUniqueAliasesM: case AnyUniqueAliasesM:
return MonsterPack(builder, t.Value.(*MonsterT)) return t.Value.(*MonsterT).Pack(builder)
case AnyUniqueAliasesTS: case AnyUniqueAliasesTS:
return TestSimpleTableWithEnumPack(builder, t.Value.(*TestSimpleTableWithEnumT)) return t.Value.(*TestSimpleTableWithEnumT).Pack(builder)
case AnyUniqueAliasesM2: case AnyUniqueAliasesM2:
return MyGame__Example2.MonsterPack(builder, t.Value.(*MyGame__Example2.MonsterT)) return t.Value.(*MyGame__Example2.MonsterT).Pack(builder)
} }
return 0 return 0
} }
func AnyUniqueAliasesUnPack(t AnyUniqueAliases, table flatbuffers.Table) *AnyUniqueAliasesT { func (rcv AnyUniqueAliases) UnPack(table flatbuffers.Table) *AnyUniqueAliasesT {
switch t { switch rcv {
case AnyUniqueAliasesM: case AnyUniqueAliasesM:
x := Monster{_tab: table} x := Monster{_tab: table}
return &AnyUniqueAliasesT{ Type: AnyUniqueAliasesM, Value: x.UnPack() } return &AnyUniqueAliasesT{ Type: AnyUniqueAliasesM, Value: x.UnPack() }
......
...@@ -57,21 +57,21 @@ type MonsterT struct { ...@@ -57,21 +57,21 @@ type MonsterT struct {
SignedEnum Race SignedEnum Race
} }
func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT { func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
nameOffset := builder.CreateString(t.Name) nameOffset := builder.CreateString(t.Name)
inventoryOffset := flatbuffers.UOffsetT(0) inventoryOffset := flatbuffers.UOffsetT(0)
if t.Inventory != nil { if t.Inventory != nil {
inventoryOffset = builder.CreateByteString(t.Inventory) inventoryOffset = builder.CreateByteString(t.Inventory)
} }
testOffset := AnyPack(builder, t.Test) testOffset := t.Test.Pack(builder)
test4Offset := flatbuffers.UOffsetT(0) test4Offset := flatbuffers.UOffsetT(0)
if t.Test4 != nil { if t.Test4 != nil {
test4Length := len(t.Test4) test4Length := len(t.Test4)
MonsterStartTest4Vector(builder, test4Length) MonsterStartTest4Vector(builder, test4Length)
for j := test4Length - 1; j >= 0; j-- { for j := test4Length - 1; j >= 0; j-- {
TestPack(builder, t.Test4[j]) t.Test4[j].Pack(builder)
} }
test4Offset = builder.EndVector(test4Length) test4Offset = builder.EndVector(test4Length)
} }
...@@ -93,7 +93,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -93,7 +93,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
testarrayoftablesLength := len(t.Testarrayoftables) testarrayoftablesLength := len(t.Testarrayoftables)
testarrayoftablesOffsets := make([]flatbuffers.UOffsetT, testarrayoftablesLength) testarrayoftablesOffsets := make([]flatbuffers.UOffsetT, testarrayoftablesLength)
for j := 0; j < testarrayoftablesLength; j++ { for j := 0; j < testarrayoftablesLength; j++ {
testarrayoftablesOffsets[j] = MonsterPack(builder, t.Testarrayoftables[j]) testarrayoftablesOffsets[j] = t.Testarrayoftables[j].Pack(builder)
} }
MonsterStartTestarrayoftablesVector(builder, testarrayoftablesLength) MonsterStartTestarrayoftablesVector(builder, testarrayoftablesLength)
for j := testarrayoftablesLength - 1; j >= 0; j-- { for j := testarrayoftablesLength - 1; j >= 0; j-- {
...@@ -101,12 +101,12 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -101,12 +101,12 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
} }
testarrayoftablesOffset = builder.EndVector(testarrayoftablesLength) testarrayoftablesOffset = builder.EndVector(testarrayoftablesLength)
} }
enemyOffset := MonsterPack(builder, t.Enemy) enemyOffset := t.Enemy.Pack(builder)
testnestedflatbufferOffset := flatbuffers.UOffsetT(0) testnestedflatbufferOffset := flatbuffers.UOffsetT(0)
if t.Testnestedflatbuffer != nil { if t.Testnestedflatbuffer != nil {
testnestedflatbufferOffset = builder.CreateByteString(t.Testnestedflatbuffer) testnestedflatbufferOffset = builder.CreateByteString(t.Testnestedflatbuffer)
} }
testemptyOffset := StatPack(builder, t.Testempty) testemptyOffset := t.Testempty.Pack(builder)
testarrayofboolsOffset := flatbuffers.UOffsetT(0) testarrayofboolsOffset := flatbuffers.UOffsetT(0)
if t.Testarrayofbools != nil { if t.Testarrayofbools != nil {
testarrayofboolsLength := len(t.Testarrayofbools) testarrayofboolsLength := len(t.Testarrayofbools)
...@@ -134,7 +134,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -134,7 +134,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
testarrayofsortedstructLength := len(t.Testarrayofsortedstruct) testarrayofsortedstructLength := len(t.Testarrayofsortedstruct)
MonsterStartTestarrayofsortedstructVector(builder, testarrayofsortedstructLength) MonsterStartTestarrayofsortedstructVector(builder, testarrayofsortedstructLength)
for j := testarrayofsortedstructLength - 1; j >= 0; j-- { for j := testarrayofsortedstructLength - 1; j >= 0; j-- {
AbilityPack(builder, t.Testarrayofsortedstruct[j]) t.Testarrayofsortedstruct[j].Pack(builder)
} }
testarrayofsortedstructOffset = builder.EndVector(testarrayofsortedstructLength) testarrayofsortedstructOffset = builder.EndVector(testarrayofsortedstructLength)
} }
...@@ -147,7 +147,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -147,7 +147,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
test5Length := len(t.Test5) test5Length := len(t.Test5)
MonsterStartTest5Vector(builder, test5Length) MonsterStartTest5Vector(builder, test5Length)
for j := test5Length - 1; j >= 0; j-- { for j := test5Length - 1; j >= 0; j-- {
TestPack(builder, t.Test5[j]) t.Test5[j].Pack(builder)
} }
test5Offset = builder.EndVector(test5Length) test5Offset = builder.EndVector(test5Length)
} }
...@@ -169,13 +169,13 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -169,13 +169,13 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
} }
vectorOfDoublesOffset = builder.EndVector(vectorOfDoublesLength) vectorOfDoublesOffset = builder.EndVector(vectorOfDoublesLength)
} }
parentNamespaceTestOffset := MyGame.InParentNamespacePack(builder, t.ParentNamespaceTest) parentNamespaceTestOffset := t.ParentNamespaceTest.Pack(builder)
vectorOfReferrablesOffset := flatbuffers.UOffsetT(0) vectorOfReferrablesOffset := flatbuffers.UOffsetT(0)
if t.VectorOfReferrables != nil { if t.VectorOfReferrables != nil {
vectorOfReferrablesLength := len(t.VectorOfReferrables) vectorOfReferrablesLength := len(t.VectorOfReferrables)
vectorOfReferrablesOffsets := make([]flatbuffers.UOffsetT, vectorOfReferrablesLength) vectorOfReferrablesOffsets := make([]flatbuffers.UOffsetT, vectorOfReferrablesLength)
for j := 0; j < vectorOfReferrablesLength; j++ { for j := 0; j < vectorOfReferrablesLength; j++ {
vectorOfReferrablesOffsets[j] = ReferrablePack(builder, t.VectorOfReferrables[j]) vectorOfReferrablesOffsets[j] = t.VectorOfReferrables[j].Pack(builder)
} }
MonsterStartVectorOfReferrablesVector(builder, vectorOfReferrablesLength) MonsterStartVectorOfReferrablesVector(builder, vectorOfReferrablesLength)
for j := vectorOfReferrablesLength - 1; j >= 0; j-- { for j := vectorOfReferrablesLength - 1; j >= 0; j-- {
...@@ -197,7 +197,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -197,7 +197,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
vectorOfStrongReferrablesLength := len(t.VectorOfStrongReferrables) vectorOfStrongReferrablesLength := len(t.VectorOfStrongReferrables)
vectorOfStrongReferrablesOffsets := make([]flatbuffers.UOffsetT, vectorOfStrongReferrablesLength) vectorOfStrongReferrablesOffsets := make([]flatbuffers.UOffsetT, vectorOfStrongReferrablesLength)
for j := 0; j < vectorOfStrongReferrablesLength; j++ { for j := 0; j < vectorOfStrongReferrablesLength; j++ {
vectorOfStrongReferrablesOffsets[j] = ReferrablePack(builder, t.VectorOfStrongReferrables[j]) vectorOfStrongReferrablesOffsets[j] = t.VectorOfStrongReferrables[j].Pack(builder)
} }
MonsterStartVectorOfStrongReferrablesVector(builder, vectorOfStrongReferrablesLength) MonsterStartVectorOfStrongReferrablesVector(builder, vectorOfStrongReferrablesLength)
for j := vectorOfStrongReferrablesLength - 1; j >= 0; j-- { for j := vectorOfStrongReferrablesLength - 1; j >= 0; j-- {
...@@ -223,9 +223,9 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -223,9 +223,9 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
} }
vectorOfNonOwningReferencesOffset = builder.EndVector(vectorOfNonOwningReferencesLength) vectorOfNonOwningReferencesOffset = builder.EndVector(vectorOfNonOwningReferencesLength)
} }
anyUniqueOffset := AnyUniqueAliasesPack(builder, t.AnyUnique) anyUniqueOffset := t.AnyUnique.Pack(builder)
anyAmbiguousOffset := AnyAmbiguousAliasesPack(builder, t.AnyAmbiguous) anyAmbiguousOffset := t.AnyAmbiguous.Pack(builder)
vectorOfEnumsOffset := flatbuffers.UOffsetT(0) vectorOfEnumsOffset := flatbuffers.UOffsetT(0)
if t.VectorOfEnums != nil { if t.VectorOfEnums != nil {
...@@ -237,7 +237,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT ...@@ -237,7 +237,7 @@ func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT
vectorOfEnumsOffset = builder.EndVector(vectorOfEnumsLength) vectorOfEnumsOffset = builder.EndVector(vectorOfEnumsLength)
} }
MonsterStart(builder) MonsterStart(builder)
posOffset := Vec3Pack(builder, t.Pos) posOffset := t.Pos.Pack(builder)
MonsterAddPos(builder, posOffset) MonsterAddPos(builder, posOffset)
MonsterAddMana(builder, t.Mana) MonsterAddMana(builder, t.Mana)
MonsterAddHp(builder, t.Hp) MonsterAddHp(builder, t.Hp)
...@@ -304,7 +304,7 @@ func (rcv *Monster) UnPackTo(t *MonsterT) { ...@@ -304,7 +304,7 @@ func (rcv *Monster) UnPackTo(t *MonsterT) {
t.Color = rcv.Color() t.Color = rcv.Color()
testTable := flatbuffers.Table{} testTable := flatbuffers.Table{}
if rcv.Test(&testTable) { if rcv.Test(&testTable) {
t.Test = AnyUnPack(rcv.TestType(), testTable) t.Test = rcv.TestType().UnPack(testTable)
} }
test4Length := rcv.Test4Length() test4Length := rcv.Test4Length()
t.Test4 = make([]*TestT, test4Length) t.Test4 = make([]*TestT, test4Length)
...@@ -410,11 +410,11 @@ func (rcv *Monster) UnPackTo(t *MonsterT) { ...@@ -410,11 +410,11 @@ func (rcv *Monster) UnPackTo(t *MonsterT) {
} }
anyUniqueTable := flatbuffers.Table{} anyUniqueTable := flatbuffers.Table{}
if rcv.AnyUnique(&anyUniqueTable) { if rcv.AnyUnique(&anyUniqueTable) {
t.AnyUnique = AnyUniqueAliasesUnPack(rcv.AnyUniqueType(), anyUniqueTable) t.AnyUnique = rcv.AnyUniqueType().UnPack(anyUniqueTable)
} }
anyAmbiguousTable := flatbuffers.Table{} anyAmbiguousTable := flatbuffers.Table{}
if rcv.AnyAmbiguous(&anyAmbiguousTable) { if rcv.AnyAmbiguous(&anyAmbiguousTable) {
t.AnyAmbiguous = AnyAmbiguousAliasesUnPack(rcv.AnyAmbiguousType(), anyAmbiguousTable) t.AnyAmbiguous = rcv.AnyAmbiguousType().UnPack(anyAmbiguousTable)
} }
vectorOfEnumsLength := rcv.VectorOfEnumsLength() vectorOfEnumsLength := rcv.VectorOfEnumsLength()
t.VectorOfEnums = make([]Color, vectorOfEnumsLength) t.VectorOfEnums = make([]Color, vectorOfEnumsLength)
......
...@@ -10,7 +10,7 @@ type ReferrableT struct { ...@@ -10,7 +10,7 @@ type ReferrableT struct {
Id uint64 Id uint64
} }
func ReferrablePack(builder *flatbuffers.Builder, t *ReferrableT) flatbuffers.UOffsetT { func (t *ReferrableT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
ReferrableStart(builder) ReferrableStart(builder)
ReferrableAddId(builder, t.Id) ReferrableAddId(builder, t.Id)
......
...@@ -12,7 +12,7 @@ type StatT struct { ...@@ -12,7 +12,7 @@ type StatT struct {
Count uint16 Count uint16
} }
func StatPack(builder *flatbuffers.Builder, t *StatT) flatbuffers.UOffsetT { func (t *StatT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
idOffset := builder.CreateString(t.Id) idOffset := builder.CreateString(t.Id)
StatStart(builder) StatStart(builder)
......
...@@ -11,7 +11,7 @@ type TestT struct { ...@@ -11,7 +11,7 @@ type TestT struct {
B int8 B int8
} }
func TestPack(builder *flatbuffers.Builder, t *TestT) flatbuffers.UOffsetT { func (t *TestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
return CreateTest(builder, t.A, t.B) return CreateTest(builder, t.A, t.B)
} }
......
...@@ -10,7 +10,7 @@ type TestSimpleTableWithEnumT struct { ...@@ -10,7 +10,7 @@ type TestSimpleTableWithEnumT struct {
Color Color Color Color
} }
func TestSimpleTableWithEnumPack(builder *flatbuffers.Builder, t *TestSimpleTableWithEnumT) flatbuffers.UOffsetT { func (t *TestSimpleTableWithEnumT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
TestSimpleTableWithEnumStart(builder) TestSimpleTableWithEnumStart(builder)
TestSimpleTableWithEnumAddColor(builder, t.Color) TestSimpleTableWithEnumAddColor(builder, t.Color)
......
...@@ -21,7 +21,7 @@ type TypeAliasesT struct { ...@@ -21,7 +21,7 @@ type TypeAliasesT struct {
Vf64 []float64 Vf64 []float64
} }
func TypeAliasesPack(builder *flatbuffers.Builder, t *TypeAliasesT) flatbuffers.UOffsetT { func (t *TypeAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
v8Offset := flatbuffers.UOffsetT(0) v8Offset := flatbuffers.UOffsetT(0)
if t.V8 != nil { if t.V8 != nil {
......
...@@ -15,7 +15,7 @@ type Vec3T struct { ...@@ -15,7 +15,7 @@ type Vec3T struct {
Test3 *TestT Test3 *TestT
} }
func Vec3Pack(builder *flatbuffers.Builder, t *Vec3T) flatbuffers.UOffsetT { func (t *Vec3T) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
return CreateVec3(builder, t.X, t.Y, t.Z, t.Test1, t.Test2, t.Test3.A, t.Test3.B) return CreateVec3(builder, t.X, t.Y, t.Z, t.Test1, t.Test2, t.Test3.A, t.Test3.B)
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
type MonsterT struct { type MonsterT struct {
} }
func MonsterPack(builder *flatbuffers.Builder, t *MonsterT) flatbuffers.UOffsetT { func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
MonsterStart(builder) MonsterStart(builder)
return MonsterEnd(builder) return MonsterEnd(builder)
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
type InParentNamespaceT struct { type InParentNamespaceT struct {
} }
func InParentNamespacePack(builder *flatbuffers.Builder, t *InParentNamespaceT) flatbuffers.UOffsetT { func (t *InParentNamespaceT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
InParentNamespaceStart(builder) InParentNamespaceStart(builder)
return InParentNamespaceEnd(builder) return InParentNamespaceEnd(builder)
......
...@@ -463,7 +463,7 @@ func CheckObjectAPI(buf []byte, offset flatbuffers.UOffsetT, fail func(string, . ...@@ -463,7 +463,7 @@ func CheckObjectAPI(buf []byte, offset flatbuffers.UOffsetT, fail func(string, .
} }
builder := flatbuffers.NewBuilder(0) builder := flatbuffers.NewBuilder(0)
builder.Finish(example.MonsterPack(builder, monster)) builder.Finish(monster.Pack(builder))
monster2 := example.GetRootAsMonster(builder.FinishedBytes(), 0).UnPack() monster2 := example.GetRootAsMonster(builder.FinishedBytes(), 0).UnPack()
if !reflect.DeepEqual(monster, monster2) { if !reflect.DeepEqual(monster, monster2) {
fail(FailString("Pack/Unpack()", monster, monster2)) fail(FailString("Pack/Unpack()", monster, monster2))
......
...@@ -11,7 +11,7 @@ type StructInNestedNST struct { ...@@ -11,7 +11,7 @@ type StructInNestedNST struct {
B int32 B int32
} }
func StructInNestedNSPack(builder *flatbuffers.Builder, t *StructInNestedNST) flatbuffers.UOffsetT { func (t *StructInNestedNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
return CreateStructInNestedNS(builder, t.A, t.B) return CreateStructInNestedNS(builder, t.A, t.B)
} }
......
...@@ -10,7 +10,7 @@ type TableInNestedNST struct { ...@@ -10,7 +10,7 @@ type TableInNestedNST struct {
Foo int32 Foo int32
} }
func TableInNestedNSPack(builder *flatbuffers.Builder, t *TableInNestedNST) flatbuffers.UOffsetT { func (t *TableInNestedNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
TableInNestedNSStart(builder) TableInNestedNSStart(builder)
TableInNestedNSAddFoo(builder, t.Foo) TableInNestedNSAddFoo(builder, t.Foo)
......
...@@ -12,9 +12,9 @@ type SecondTableInAT struct { ...@@ -12,9 +12,9 @@ type SecondTableInAT struct {
ReferToC *NamespaceC.TableInCT ReferToC *NamespaceC.TableInCT
} }
func SecondTableInAPack(builder *flatbuffers.Builder, t *SecondTableInAT) flatbuffers.UOffsetT { func (t *SecondTableInAT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
referToCOffset := NamespaceC.TableInCPack(builder, t.ReferToC) referToCOffset := t.ReferToC.Pack(builder)
SecondTableInAStart(builder) SecondTableInAStart(builder)
SecondTableInAAddReferToC(builder, referToCOffset) SecondTableInAAddReferToC(builder, referToCOffset)
return SecondTableInAEnd(builder) return SecondTableInAEnd(builder)
......
...@@ -14,13 +14,13 @@ type TableInFirstNST struct { ...@@ -14,13 +14,13 @@ type TableInFirstNST struct {
FooStruct *NamespaceA__NamespaceB.StructInNestedNST FooStruct *NamespaceA__NamespaceB.StructInNestedNST
} }
func TableInFirstNSPack(builder *flatbuffers.Builder, t *TableInFirstNST) flatbuffers.UOffsetT { func (t *TableInFirstNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
fooTableOffset := NamespaceA__NamespaceB.TableInNestedNSPack(builder, t.FooTable) fooTableOffset := t.FooTable.Pack(builder)
TableInFirstNSStart(builder) TableInFirstNSStart(builder)
TableInFirstNSAddFooTable(builder, fooTableOffset) TableInFirstNSAddFooTable(builder, fooTableOffset)
TableInFirstNSAddFooEnum(builder, t.FooEnum) TableInFirstNSAddFooEnum(builder, t.FooEnum)
fooStructOffset := NamespaceA__NamespaceB.StructInNestedNSPack(builder, t.FooStruct) fooStructOffset := t.FooStruct.Pack(builder)
TableInFirstNSAddFooStruct(builder, fooStructOffset) TableInFirstNSAddFooStruct(builder, fooStructOffset)
return TableInFirstNSEnd(builder) return TableInFirstNSEnd(builder)
} }
......
...@@ -13,10 +13,10 @@ type TableInCT struct { ...@@ -13,10 +13,10 @@ type TableInCT struct {
ReferToA2 *NamespaceA.SecondTableInAT ReferToA2 *NamespaceA.SecondTableInAT
} }
func TableInCPack(builder *flatbuffers.Builder, t *TableInCT) flatbuffers.UOffsetT { func (t *TableInCT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
if t == nil { return 0 } if t == nil { return 0 }
referToA1Offset := NamespaceA.TableInFirstNSPack(builder, t.ReferToA1) referToA1Offset := t.ReferToA1.Pack(builder)
referToA2Offset := NamespaceA.SecondTableInAPack(builder, t.ReferToA2) referToA2Offset := t.ReferToA2.Pack(builder)
TableInCStart(builder) TableInCStart(builder)
TableInCAddReferToA1(builder, referToA1Offset) TableInCAddReferToA1(builder, referToA1Offset)
TableInCAddReferToA2(builder, referToA2Offset) TableInCAddReferToA2(builder, referToA2Offset)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment