Go: make generated code more compliant to "go fmt" (#7907)
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
parent
63495b935a
commit
6c8a8d054d
|
@ -12,8 +12,13 @@ type WarriorT struct {
|
|||
}
|
||||
|
||||
func (t *WarriorT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
nameOffset := builder.CreateString(t.Name)
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
nameOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Name != "" {
|
||||
nameOffset = builder.CreateString(t.Name)
|
||||
}
|
||||
WarriorStart(builder)
|
||||
WarriorAddName(builder, nameOffset)
|
||||
WarriorAddHp(builder, t.Hp)
|
||||
|
@ -26,7 +31,9 @@ func (rcv *Warrior) UnPackTo(t *WarriorT) {
|
|||
}
|
||||
|
||||
func (rcv *Warrior) UnPack() *WarriorT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &WarriorT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -13,7 +13,9 @@ type RequestT struct {
|
|||
}
|
||||
|
||||
func (t *RequestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
playerOffset := t.Player.Pack(builder)
|
||||
RequestStart(builder)
|
||||
RequestAddPlayer(builder, playerOffset)
|
||||
|
@ -25,7 +27,9 @@ func (rcv *Request) UnPackTo(t *RequestT) {
|
|||
}
|
||||
|
||||
func (rcv *Request) UnPack() *RequestT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &RequestT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -13,7 +13,9 @@ type ResponseT struct {
|
|||
}
|
||||
|
||||
func (t *ResponseT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
playerOffset := t.Player.Pack(builder)
|
||||
ResponseStart(builder)
|
||||
ResponseAddPlayer(builder, playerOffset)
|
||||
|
@ -25,7 +27,9 @@ func (rcv *Response) UnPackTo(t *ResponseT) {
|
|||
}
|
||||
|
||||
func (rcv *Response) UnPack() *ResponseT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &ResponseT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -541,7 +541,7 @@ class GoGenerator : public BaseGenerator {
|
|||
GenReceiver(struct_def, code_ptr);
|
||||
code += " " + namer_.Field(field) + "ByKey";
|
||||
code += "(obj *" + TypeName(field);
|
||||
code += ", key " + NativeType(key_field.value.type) + ") bool" +
|
||||
code += ", key " + NativeType(key_field.value.type) + ") bool " +
|
||||
OffsetPrefix(field);
|
||||
code += "\t\tx := rcv._tab.Vector(o)\n";
|
||||
code += "\t\treturn ";
|
||||
|
@ -920,8 +920,8 @@ class GoGenerator : public BaseGenerator {
|
|||
code += "o1, o2 flatbuffers.UOffsetT, buf []byte) bool {\n";
|
||||
code += "\tobj1 := &" + namer_.Type(struct_def) + "{}\n";
|
||||
code += "\tobj2 := &" + namer_.Type(struct_def) + "{}\n";
|
||||
code += "\tobj1.Init(buf, flatbuffers.UOffsetT(len(buf)) - o1)\n";
|
||||
code += "\tobj2.Init(buf, flatbuffers.UOffsetT(len(buf)) - o2)\n";
|
||||
code += "\tobj1.Init(buf, flatbuffers.UOffsetT(len(buf))-o1)\n";
|
||||
code += "\tobj2.Init(buf, flatbuffers.UOffsetT(len(buf))-o2)\n";
|
||||
if (IsString(field.value.type)) {
|
||||
code += "\treturn string(obj1." + namer_.Function(field.name) + "()) < ";
|
||||
code += "string(obj2." + namer_.Function(field.name) + "())\n";
|
||||
|
@ -943,13 +943,13 @@ class GoGenerator : public BaseGenerator {
|
|||
code += "key " + NativeType(field.value.type) + ", ";
|
||||
code += "vectorLocation flatbuffers.UOffsetT, ";
|
||||
code += "buf []byte) bool {\n";
|
||||
code += "\tspan := flatbuffers.GetUOffsetT(buf[vectorLocation - 4:])\n";
|
||||
code += "\tspan := flatbuffers.GetUOffsetT(buf[vectorLocation-4:])\n";
|
||||
code += "\tstart := flatbuffers.UOffsetT(0)\n";
|
||||
if (IsString(field.value.type)) { code += "\tbKey := []byte(key)\n"; }
|
||||
code += "\tfor span != 0 {\n";
|
||||
code += "\t\tmiddle := span / 2\n";
|
||||
code += "\t\ttableOffset := flatbuffers.GetIndirectOffset(buf, ";
|
||||
code += "vectorLocation+ 4 * (start + middle))\n";
|
||||
code += "vectorLocation+4*(start+middle))\n";
|
||||
|
||||
code += "\t\tobj := &" + namer_.Type(struct_def) + "{}\n";
|
||||
code += "\t\tobj.Init(buf, tableOffset)\n";
|
||||
|
@ -1060,8 +1060,8 @@ class GoGenerator : public BaseGenerator {
|
|||
|
||||
code += "\t\treturn &" +
|
||||
WrapInNameSpaceAndTrack(&enum_def, NativeName(enum_def)) +
|
||||
"{ Type: " + namer_.EnumVariant(enum_def, ev) +
|
||||
", Value: x.UnPack() }\n";
|
||||
"{Type: " + namer_.EnumVariant(enum_def, ev) +
|
||||
", Value: x.UnPack()}\n";
|
||||
}
|
||||
code += "\t}\n";
|
||||
code += "\treturn nil\n";
|
||||
|
@ -1074,7 +1074,7 @@ class GoGenerator : public BaseGenerator {
|
|||
|
||||
code += "func (t *" + NativeName(struct_def) +
|
||||
") Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {\n";
|
||||
code += "\tif t == nil { return 0 }\n";
|
||||
code += "\tif t == nil {\n\t\treturn 0\n\t}\n";
|
||||
for (auto it = struct_def.fields.vec.begin();
|
||||
it != struct_def.fields.vec.end(); ++it) {
|
||||
const FieldDef &field = **it;
|
||||
|
@ -1144,8 +1144,7 @@ class GoGenerator : public BaseGenerator {
|
|||
if (field.value.type.struct_def->fixed) continue;
|
||||
code += "\t" + offset + " := t." + field_field + ".Pack(builder)\n";
|
||||
} else if (field.value.type.base_type == BASE_TYPE_UNION) {
|
||||
code += "\t" + offset + " := t." + field_field + ".Pack(builder)\n";
|
||||
code += "\t\n";
|
||||
code += "\t" + offset + " := t." + field_field + ".Pack(builder)\n\n";
|
||||
} else {
|
||||
FLATBUFFERS_ASSERT(0);
|
||||
}
|
||||
|
@ -1261,7 +1260,7 @@ class GoGenerator : public BaseGenerator {
|
|||
|
||||
code += "func (rcv *" + struct_type + ") UnPack() *" +
|
||||
NativeName(struct_def) + " {\n";
|
||||
code += "\tif rcv == nil { return nil }\n";
|
||||
code += "\tif rcv == nil {\n\t\treturn nil\n\t}\n";
|
||||
code += "\tt := &" + NativeName(struct_def) + "{}\n";
|
||||
code += "\trcv.UnPackTo(t)\n";
|
||||
code += "\treturn t\n";
|
||||
|
@ -1273,7 +1272,7 @@ class GoGenerator : public BaseGenerator {
|
|||
|
||||
code += "func (t *" + NativeName(struct_def) +
|
||||
") Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {\n";
|
||||
code += "\tif t == nil { return 0 }\n";
|
||||
code += "\tif t == nil {\n\t\treturn 0\n\t}\n";
|
||||
code += "\treturn Create" + namer_.Type(struct_def) + "(builder";
|
||||
StructPackArgs(struct_def, "", code_ptr);
|
||||
code += ")\n";
|
||||
|
@ -1317,7 +1316,7 @@ class GoGenerator : public BaseGenerator {
|
|||
|
||||
code += "func (rcv *" + namer_.Type(struct_def) + ") UnPack() *" +
|
||||
NativeName(struct_def) + " {\n";
|
||||
code += "\tif rcv == nil { return nil }\n";
|
||||
code += "\tif rcv == nil {\n\t\treturn nil\n\t}\n";
|
||||
code += "\tt := &" + NativeName(struct_def) + "{}\n";
|
||||
code += "\trcv.UnPackTo(t)\n";
|
||||
code += "\treturn t\n";
|
||||
|
@ -1505,15 +1504,17 @@ class GoGenerator : public BaseGenerator {
|
|||
code += "package " + name_space_name + "\n\n";
|
||||
if (needs_imports) {
|
||||
code += "import (\n";
|
||||
// standard imports, in alphabetical order for go fmt
|
||||
if (needs_bytes_import_) code += "\t\"bytes\"\n";
|
||||
// math is needed to support non-finite scalar default values.
|
||||
if (needs_math_import_) { code += "\t\"math\"\n"; }
|
||||
if (is_enum) { code += "\t\"strconv\"\n"; }
|
||||
if (!parser_.opts.go_import.empty()) {
|
||||
code += "\tflatbuffers \"" + parser_.opts.go_import + "\"\n";
|
||||
} else {
|
||||
code += "\tflatbuffers \"github.com/google/flatbuffers/go\"\n";
|
||||
}
|
||||
// math is needed to support non-finite scalar default values.
|
||||
if (needs_math_import_) { code += "\t\"math\"\n"; }
|
||||
if (is_enum) { code += "\t\"strconv\"\n"; }
|
||||
|
||||
if (tracked_imported_namespaces_.size() > 0) {
|
||||
code += "\n";
|
||||
for (auto it = tracked_imported_namespaces_.begin();
|
||||
|
|
|
@ -12,7 +12,9 @@ type AbilityT struct {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
func (rcv *Ability) UnPackTo(t *AbilityT) {
|
||||
|
@ -21,7 +23,9 @@ func (rcv *Ability) UnPackTo(t *AbilityT) {
|
|||
}
|
||||
|
||||
func (rcv *Ability) UnPack() *AbilityT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &AbilityT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
package Example
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
|
||||
MyGame__Example2 "MyGame/Example2"
|
||||
)
|
||||
|
@ -64,15 +64,15 @@ func (rcv Any) UnPack(table flatbuffers.Table) *AnyT {
|
|||
case AnyMonster:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyT{ Type: AnyMonster, Value: x.UnPack() }
|
||||
return &AnyT{Type: AnyMonster, Value: x.UnPack()}
|
||||
case AnyTestSimpleTableWithEnum:
|
||||
var x TestSimpleTableWithEnum
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyT{ Type: AnyTestSimpleTableWithEnum, Value: x.UnPack() }
|
||||
return &AnyT{Type: AnyTestSimpleTableWithEnum, Value: x.UnPack()}
|
||||
case AnyMyGame_Example2_Monster:
|
||||
var x MyGame__Example2.Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyT{ Type: AnyMyGame_Example2_Monster, Value: x.UnPack() }
|
||||
return &AnyT{Type: AnyMyGame_Example2_Monster, Value: x.UnPack()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
package Example
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type AnyAmbiguousAliases byte
|
||||
|
@ -62,15 +62,15 @@ func (rcv AnyAmbiguousAliases) UnPack(table flatbuffers.Table) *AnyAmbiguousAlia
|
|||
case AnyAmbiguousAliasesM1:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyAmbiguousAliasesT{ Type: AnyAmbiguousAliasesM1, Value: x.UnPack() }
|
||||
return &AnyAmbiguousAliasesT{Type: AnyAmbiguousAliasesM1, Value: x.UnPack()}
|
||||
case AnyAmbiguousAliasesM2:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyAmbiguousAliasesT{ Type: AnyAmbiguousAliasesM2, Value: x.UnPack() }
|
||||
return &AnyAmbiguousAliasesT{Type: AnyAmbiguousAliasesM2, Value: x.UnPack()}
|
||||
case AnyAmbiguousAliasesM3:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyAmbiguousAliasesT{ Type: AnyAmbiguousAliasesM3, Value: x.UnPack() }
|
||||
return &AnyAmbiguousAliasesT{Type: AnyAmbiguousAliasesM3, Value: x.UnPack()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
package Example
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
|
||||
MyGame__Example2 "MyGame/Example2"
|
||||
)
|
||||
|
@ -64,15 +64,15 @@ func (rcv AnyUniqueAliases) UnPack(table flatbuffers.Table) *AnyUniqueAliasesT {
|
|||
case AnyUniqueAliasesM:
|
||||
var x Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyUniqueAliasesT{ Type: AnyUniqueAliasesM, Value: x.UnPack() }
|
||||
return &AnyUniqueAliasesT{Type: AnyUniqueAliasesM, Value: x.UnPack()}
|
||||
case AnyUniqueAliasesTS:
|
||||
var x TestSimpleTableWithEnum
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyUniqueAliasesT{ Type: AnyUniqueAliasesTS, Value: x.UnPack() }
|
||||
return &AnyUniqueAliasesT{Type: AnyUniqueAliasesTS, Value: x.UnPack()}
|
||||
case AnyUniqueAliasesM2:
|
||||
var x MyGame__Example2.Monster
|
||||
x.Init(table.Bytes, table.Pos)
|
||||
return &AnyUniqueAliasesT{ Type: AnyUniqueAliasesM2, Value: x.UnPack() }
|
||||
return &AnyUniqueAliasesT{Type: AnyUniqueAliasesM2, Value: x.UnPack()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ package Example
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"math"
|
||||
|
||||
MyGame "MyGame"
|
||||
)
|
||||
|
@ -73,7 +73,9 @@ type MonsterT struct {
|
|||
}
|
||||
|
||||
func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
nameOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Name != "" {
|
||||
nameOffset = builder.CreateString(t.Name)
|
||||
|
@ -83,7 +85,7 @@ func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
|||
inventoryOffset = builder.CreateByteString(t.Inventory)
|
||||
}
|
||||
testOffset := t.Test.Pack(builder)
|
||||
|
||||
|
||||
test4Offset := flatbuffers.UOffsetT(0)
|
||||
if t.Test4 != nil {
|
||||
test4Length := len(t.Test4)
|
||||
|
@ -242,9 +244,9 @@ func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
|||
vectorOfNonOwningReferencesOffset = builder.EndVector(vectorOfNonOwningReferencesLength)
|
||||
}
|
||||
anyUniqueOffset := t.AnyUnique.Pack(builder)
|
||||
|
||||
|
||||
anyAmbiguousOffset := t.AnyAmbiguous.Pack(builder)
|
||||
|
||||
|
||||
vectorOfEnumsOffset := flatbuffers.UOffsetT(0)
|
||||
if t.VectorOfEnums != nil {
|
||||
vectorOfEnumsLength := len(t.VectorOfEnums)
|
||||
|
@ -493,7 +495,9 @@ func (rcv *Monster) UnPackTo(t *MonsterT) {
|
|||
}
|
||||
|
||||
func (rcv *Monster) UnPack() *MonsterT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &MonsterT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
@ -594,18 +598,18 @@ func (rcv *Monster) Name() []byte {
|
|||
func MonsterKeyCompare(o1, o2 flatbuffers.UOffsetT, buf []byte) bool {
|
||||
obj1 := &Monster{}
|
||||
obj2 := &Monster{}
|
||||
obj1.Init(buf, flatbuffers.UOffsetT(len(buf)) - o1)
|
||||
obj2.Init(buf, flatbuffers.UOffsetT(len(buf)) - o2)
|
||||
obj1.Init(buf, flatbuffers.UOffsetT(len(buf))-o1)
|
||||
obj2.Init(buf, flatbuffers.UOffsetT(len(buf))-o2)
|
||||
return string(obj1.Name()) < string(obj2.Name())
|
||||
}
|
||||
|
||||
func (rcv *Monster) LookupByKey(key string, vectorLocation flatbuffers.UOffsetT, buf []byte) bool {
|
||||
span := flatbuffers.GetUOffsetT(buf[vectorLocation - 4:])
|
||||
span := flatbuffers.GetUOffsetT(buf[vectorLocation-4:])
|
||||
start := flatbuffers.UOffsetT(0)
|
||||
bKey := []byte(key)
|
||||
for span != 0 {
|
||||
middle := span / 2
|
||||
tableOffset := flatbuffers.GetIndirectOffset(buf, vectorLocation+ 4 * (start + middle))
|
||||
tableOffset := flatbuffers.GetIndirectOffset(buf, vectorLocation+4*(start+middle))
|
||||
obj := &Monster{}
|
||||
obj.Init(buf, tableOffset)
|
||||
comp := bytes.Compare(obj.Name(), bKey)
|
||||
|
@ -740,7 +744,7 @@ func (rcv *Monster) Testarrayoftables(obj *Monster, j int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (rcv *Monster) TestarrayoftablesByKey(obj *Monster, key string) bool{
|
||||
func (rcv *Monster) TestarrayoftablesByKey(obj *Monster, key string) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(26))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Vector(o)
|
||||
|
@ -1155,7 +1159,7 @@ func (rcv *Monster) VectorOfReferrables(obj *Referrable, j int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (rcv *Monster) VectorOfReferrablesByKey(obj *Referrable, key uint64) bool{
|
||||
func (rcv *Monster) VectorOfReferrablesByKey(obj *Referrable, key uint64) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(74))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Vector(o)
|
||||
|
@ -1222,7 +1226,7 @@ func (rcv *Monster) VectorOfStrongReferrables(obj *Referrable, j int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (rcv *Monster) VectorOfStrongReferrablesByKey(obj *Referrable, key uint64) bool{
|
||||
func (rcv *Monster) VectorOfStrongReferrablesByKey(obj *Referrable, key uint64) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(80))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Vector(o)
|
||||
|
@ -1449,7 +1453,7 @@ func (rcv *Monster) ScalarKeySortedTables(obj *Stat, j int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (rcv *Monster) ScalarKeySortedTablesByKey(obj *Stat, key uint16) bool{
|
||||
func (rcv *Monster) ScalarKeySortedTablesByKey(obj *Stat, key uint16) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(104))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Vector(o)
|
||||
|
|
|
@ -11,7 +11,9 @@ type ReferrableT struct {
|
|||
}
|
||||
|
||||
func (t *ReferrableT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
ReferrableStart(builder)
|
||||
ReferrableAddId(builder, t.Id)
|
||||
return ReferrableEnd(builder)
|
||||
|
@ -22,7 +24,9 @@ func (rcv *Referrable) UnPackTo(t *ReferrableT) {
|
|||
}
|
||||
|
||||
func (rcv *Referrable) UnPack() *ReferrableT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &ReferrableT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
@ -78,17 +82,17 @@ func (rcv *Referrable) MutateId(n uint64) bool {
|
|||
func ReferrableKeyCompare(o1, o2 flatbuffers.UOffsetT, buf []byte) bool {
|
||||
obj1 := &Referrable{}
|
||||
obj2 := &Referrable{}
|
||||
obj1.Init(buf, flatbuffers.UOffsetT(len(buf)) - o1)
|
||||
obj2.Init(buf, flatbuffers.UOffsetT(len(buf)) - o2)
|
||||
obj1.Init(buf, flatbuffers.UOffsetT(len(buf))-o1)
|
||||
obj2.Init(buf, flatbuffers.UOffsetT(len(buf))-o2)
|
||||
return obj1.Id() < obj2.Id()
|
||||
}
|
||||
|
||||
func (rcv *Referrable) LookupByKey(key uint64, vectorLocation flatbuffers.UOffsetT, buf []byte) bool {
|
||||
span := flatbuffers.GetUOffsetT(buf[vectorLocation - 4:])
|
||||
span := flatbuffers.GetUOffsetT(buf[vectorLocation-4:])
|
||||
start := flatbuffers.UOffsetT(0)
|
||||
for span != 0 {
|
||||
middle := span / 2
|
||||
tableOffset := flatbuffers.GetIndirectOffset(buf, vectorLocation+ 4 * (start + middle))
|
||||
tableOffset := flatbuffers.GetIndirectOffset(buf, vectorLocation+4*(start+middle))
|
||||
obj := &Referrable{}
|
||||
obj.Init(buf, tableOffset)
|
||||
val := obj.Id()
|
||||
|
|
|
@ -13,7 +13,9 @@ type StatT struct {
|
|||
}
|
||||
|
||||
func (t *StatT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
idOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Id != "" {
|
||||
idOffset = builder.CreateString(t.Id)
|
||||
|
@ -32,7 +34,9 @@ func (rcv *Stat) UnPackTo(t *StatT) {
|
|||
}
|
||||
|
||||
func (rcv *Stat) UnPack() *StatT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &StatT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
@ -108,17 +112,17 @@ func (rcv *Stat) MutateCount(n uint16) bool {
|
|||
func StatKeyCompare(o1, o2 flatbuffers.UOffsetT, buf []byte) bool {
|
||||
obj1 := &Stat{}
|
||||
obj2 := &Stat{}
|
||||
obj1.Init(buf, flatbuffers.UOffsetT(len(buf)) - o1)
|
||||
obj2.Init(buf, flatbuffers.UOffsetT(len(buf)) - o2)
|
||||
obj1.Init(buf, flatbuffers.UOffsetT(len(buf))-o1)
|
||||
obj2.Init(buf, flatbuffers.UOffsetT(len(buf))-o2)
|
||||
return obj1.Count() < obj2.Count()
|
||||
}
|
||||
|
||||
func (rcv *Stat) LookupByKey(key uint16, vectorLocation flatbuffers.UOffsetT, buf []byte) bool {
|
||||
span := flatbuffers.GetUOffsetT(buf[vectorLocation - 4:])
|
||||
span := flatbuffers.GetUOffsetT(buf[vectorLocation-4:])
|
||||
start := flatbuffers.UOffsetT(0)
|
||||
for span != 0 {
|
||||
middle := span / 2
|
||||
tableOffset := flatbuffers.GetIndirectOffset(buf, vectorLocation+ 4 * (start + middle))
|
||||
tableOffset := flatbuffers.GetIndirectOffset(buf, vectorLocation+4*(start+middle))
|
||||
obj := &Stat{}
|
||||
obj.Init(buf, tableOffset)
|
||||
val := obj.Count()
|
||||
|
|
|
@ -13,7 +13,9 @@ type StructOfStructsT struct {
|
|||
}
|
||||
|
||||
func (t *StructOfStructsT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
return CreateStructOfStructs(builder, t.A.Id, t.A.Distance, t.B.A, t.B.B, t.C.Id, t.C.Distance)
|
||||
}
|
||||
func (rcv *StructOfStructs) UnPackTo(t *StructOfStructsT) {
|
||||
|
@ -23,7 +25,9 @@ func (rcv *StructOfStructs) UnPackTo(t *StructOfStructsT) {
|
|||
}
|
||||
|
||||
func (rcv *StructOfStructs) UnPack() *StructOfStructsT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &StructOfStructsT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -11,7 +11,9 @@ type StructOfStructsOfStructsT struct {
|
|||
}
|
||||
|
||||
func (t *StructOfStructsOfStructsT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
return CreateStructOfStructsOfStructs(builder, t.A.A.Id, t.A.A.Distance, t.A.B.A, t.A.B.B, t.A.C.Id, t.A.C.Distance)
|
||||
}
|
||||
func (rcv *StructOfStructsOfStructs) UnPackTo(t *StructOfStructsOfStructsT) {
|
||||
|
@ -19,7 +21,9 @@ func (rcv *StructOfStructsOfStructs) UnPackTo(t *StructOfStructsOfStructsT) {
|
|||
}
|
||||
|
||||
func (rcv *StructOfStructsOfStructs) UnPack() *StructOfStructsOfStructsT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &StructOfStructsOfStructsT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -12,7 +12,9 @@ type TestT struct {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
func (rcv *Test) UnPackTo(t *TestT) {
|
||||
|
@ -21,7 +23,9 @@ func (rcv *Test) UnPackTo(t *TestT) {
|
|||
}
|
||||
|
||||
func (rcv *Test) UnPack() *TestT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &TestT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -11,7 +11,9 @@ type TestSimpleTableWithEnumT struct {
|
|||
}
|
||||
|
||||
func (t *TestSimpleTableWithEnumT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
TestSimpleTableWithEnumStart(builder)
|
||||
TestSimpleTableWithEnumAddColor(builder, t.Color)
|
||||
return TestSimpleTableWithEnumEnd(builder)
|
||||
|
@ -22,7 +24,9 @@ func (rcv *TestSimpleTableWithEnum) UnPackTo(t *TestSimpleTableWithEnumT) {
|
|||
}
|
||||
|
||||
func (rcv *TestSimpleTableWithEnum) UnPack() *TestSimpleTableWithEnumT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &TestSimpleTableWithEnumT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -22,7 +22,9 @@ type TypeAliasesT struct {
|
|||
}
|
||||
|
||||
func (t *TypeAliasesT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
v8Offset := flatbuffers.UOffsetT(0)
|
||||
if t.V8 != nil {
|
||||
v8Length := len(t.V8)
|
||||
|
@ -81,7 +83,9 @@ func (rcv *TypeAliases) UnPackTo(t *TypeAliasesT) {
|
|||
}
|
||||
|
||||
func (rcv *TypeAliases) UnPack() *TypeAliasesT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &TypeAliasesT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -16,7 +16,9 @@ type Vec3T struct {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
func (rcv *Vec3) UnPackTo(t *Vec3T) {
|
||||
|
@ -29,7 +31,9 @@ func (rcv *Vec3) UnPackTo(t *Vec3T) {
|
|||
}
|
||||
|
||||
func (rcv *Vec3) UnPack() *Vec3T {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &Vec3T{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -10,7 +10,9 @@ type MonsterT struct {
|
|||
}
|
||||
|
||||
func (t *MonsterT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
MonsterStart(builder)
|
||||
return MonsterEnd(builder)
|
||||
}
|
||||
|
@ -19,7 +21,9 @@ func (rcv *Monster) UnPackTo(t *MonsterT) {
|
|||
}
|
||||
|
||||
func (rcv *Monster) UnPack() *MonsterT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &MonsterT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
|
@ -10,7 +10,9 @@ type InParentNamespaceT struct {
|
|||
}
|
||||
|
||||
func (t *InParentNamespaceT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
InParentNamespaceStart(builder)
|
||||
return InParentNamespaceEnd(builder)
|
||||
}
|
||||
|
@ -19,7 +21,9 @@ func (rcv *InParentNamespace) UnPackTo(t *InParentNamespaceT) {
|
|||
}
|
||||
|
||||
func (rcv *InParentNamespace) UnPack() *InParentNamespaceT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &InParentNamespaceT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
|
Loading…
Reference in New Issue