Commit 53e9606e authored by Muhammed Thanish's avatar Muhammed Thanish

Implement mutators for Go

parent ffc0d620
...@@ -67,6 +67,29 @@ Now you can access values like this: ...@@ -67,6 +67,29 @@ Now you can access values like this:
pos := monster.Pos(nil) pos := monster.Pos(nil)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.go}
monster := example.GetRootAsMonster(buf, 0)
// Set table field.
if ok := monster.MutateHp(10); !ok {
panic("failed to mutate Hp")
}
// Set struct field.
monster.Pos().MutateZ(4)
// This mutation will fail because the mana field is not available in
// the buffer. It should be set when creating the buffer.
if ok := monster.MutateMana(20); !ok {
panic("failed to mutate Hp")
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The term `mutate` is used instead of `set` to indicate that this is a special use case. All mutate functions return a boolean value which is false if the field we're trying to mutate is not available in the buffer.
## Text Parsing ## Text Parsing
There currently is no support for parsing text (Schema's and JSON) directly There currently is no support for parsing text (Schema's and JSON) directly
......
...@@ -293,3 +293,213 @@ func (t *Table) GetVOffsetTSlot(slot VOffsetT, d VOffsetT) VOffsetT { ...@@ -293,3 +293,213 @@ func (t *Table) GetVOffsetTSlot(slot VOffsetT, d VOffsetT) VOffsetT {
} }
return VOffsetT(off) return VOffsetT(off)
} }
// MutateBool updates a bool at the given offset.
func (t *Table) MutateBool(off UOffsetT, n bool) bool {
WriteBool(t.Bytes[off:], n)
return true
}
// MutateByte updates a Byte at the given offset.
func (t *Table) MutateByte(off UOffsetT, n byte) bool {
WriteByte(t.Bytes[off:], n)
return true
}
// MutateUint8 updates a Uint8 at the given offset.
func (t *Table) MutateUint8(off UOffsetT, n uint8) bool {
WriteUint8(t.Bytes[off:], n)
return true
}
// MutateUint16 updates a Uint16 at the given offset.
func (t *Table) MutateUint16(off UOffsetT, n uint16) bool {
WriteUint16(t.Bytes[off:], n)
return true
}
// MutateUint32 updates a Uint32 at the given offset.
func (t *Table) MutateUint32(off UOffsetT, n uint32) bool {
WriteUint32(t.Bytes[off:], n)
return true
}
// MutateUint64 updates a Uint64 at the given offset.
func (t *Table) MutateUint64(off UOffsetT, n uint64) bool {
WriteUint64(t.Bytes[off:], n)
return true
}
// MutateInt8 updates a Int8 at the given offset.
func (t *Table) MutateInt8(off UOffsetT, n int8) bool {
WriteInt8(t.Bytes[off:], n)
return true
}
// MutateInt16 updates a Int16 at the given offset.
func (t *Table) MutateInt16(off UOffsetT, n int16) bool {
WriteInt16(t.Bytes[off:], n)
return true
}
// MutateInt32 updates a Int32 at the given offset.
func (t *Table) MutateInt32(off UOffsetT, n int32) bool {
WriteInt32(t.Bytes[off:], n)
return true
}
// MutateInt64 updates a Int64 at the given offset.
func (t *Table) MutateInt64(off UOffsetT, n int64) bool {
WriteInt64(t.Bytes[off:], n)
return true
}
// MutateFloat32 updates a Float32 at the given offset.
func (t *Table) MutateFloat32(off UOffsetT, n float32) bool {
WriteFloat32(t.Bytes[off:], n)
return true
}
// MutateFloat64 updates a Float64 at the given offset.
func (t *Table) MutateFloat64(off UOffsetT, n float64) bool {
WriteFloat64(t.Bytes[off:], n)
return true
}
// MutateUOffsetT updates a UOffsetT at the given offset.
func (t *Table) MutateUOffsetT(off UOffsetT, n UOffsetT) bool {
WriteUOffsetT(t.Bytes[off:], n)
return true
}
// MutateVOffsetT updates a VOffsetT at the given offset.
func (t *Table) MutateVOffsetT(off UOffsetT, n VOffsetT) bool {
WriteVOffsetT(t.Bytes[off:], n)
return true
}
// MutateSOffsetT updates a SOffsetT at the given offset.
func (t *Table) MutateSOffsetT(off UOffsetT, n SOffsetT) bool {
WriteSOffsetT(t.Bytes[off:], n)
return true
}
// MutateBoolSlot updates the bool at given vtable location
func (t *Table) MutateBoolSlot(slot VOffsetT, n bool) bool {
if off := t.Offset(slot); off != 0 {
t.MutateBool(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateByteSlot updates the byte at given vtable location
func (t *Table) MutateByteSlot(slot VOffsetT, n byte) bool {
if off := t.Offset(slot); off != 0 {
t.MutateByte(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateInt8Slot updates the int8 at given vtable location
func (t *Table) MutateInt8Slot(slot VOffsetT, n int8) bool {
if off := t.Offset(slot); off != 0 {
t.MutateInt8(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateUint8Slot updates the uint8 at given vtable location
func (t *Table) MutateUint8Slot(slot VOffsetT, n uint8) bool {
if off := t.Offset(slot); off != 0 {
t.MutateUint8(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateInt16Slot updates the int16 at given vtable location
func (t *Table) MutateInt16Slot(slot VOffsetT, n int16) bool {
if off := t.Offset(slot); off != 0 {
t.MutateInt16(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateUint16Slot updates the uint16 at given vtable location
func (t *Table) MutateUint16Slot(slot VOffsetT, n uint16) bool {
if off := t.Offset(slot); off != 0 {
t.MutateUint16(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateInt32Slot updates the int32 at given vtable location
func (t *Table) MutateInt32Slot(slot VOffsetT, n int32) bool {
if off := t.Offset(slot); off != 0 {
t.MutateInt32(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateUint32Slot updates the uint32 at given vtable location
func (t *Table) MutateUint32Slot(slot VOffsetT, n uint32) bool {
if off := t.Offset(slot); off != 0 {
t.MutateUint32(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateInt64Slot updates the int64 at given vtable location
func (t *Table) MutateInt64Slot(slot VOffsetT, n int64) bool {
if off := t.Offset(slot); off != 0 {
t.MutateInt64(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateUint64Slot updates the uint64 at given vtable location
func (t *Table) MutateUint64Slot(slot VOffsetT, n uint64) bool {
if off := t.Offset(slot); off != 0 {
t.MutateUint64(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateFloat32Slot updates the float32 at given vtable location
func (t *Table) MutateFloat32Slot(slot VOffsetT, n float32) bool {
if off := t.Offset(slot); off != 0 {
t.MutateFloat32(t.Pos+UOffsetT(off), n)
return true
}
return false
}
// MutateFloat64Slot updates the float64 at given vtable location
func (t *Table) MutateFloat64Slot(slot VOffsetT, n float64) bool {
if off := t.Offset(slot); off != 0 {
t.MutateFloat64(t.Pos+UOffsetT(off), n)
return true
}
return false
}
...@@ -439,7 +439,7 @@ static void GenReceiver(const StructDef &struct_def, std::string *code_ptr) { ...@@ -439,7 +439,7 @@ static void GenReceiver(const StructDef &struct_def, std::string *code_ptr) {
code += "func (rcv *" + struct_def.name + ")"; code += "func (rcv *" + struct_def.name + ")";
} }
// Generate a struct field, conditioned on its child type(s). // Generate a struct field getter, conditioned on its child type(s).
static void GenStructAccessor(const StructDef &struct_def, static void GenStructAccessor(const StructDef &struct_def,
const FieldDef &field, const FieldDef &field,
std::string *code_ptr) { std::string *code_ptr) {
...@@ -486,6 +486,48 @@ static void GenStructAccessor(const StructDef &struct_def, ...@@ -486,6 +486,48 @@ static void GenStructAccessor(const StructDef &struct_def,
} }
} }
// Mutate the value of a struct's scalar.
static void MutateScalarFieldOfStruct(const StructDef &struct_def,
const FieldDef &field,
std::string *code_ptr) {
std::string &code = *code_ptr;
std::string type = MakeCamel(GenTypeBasic(field.value.type));
std::string setter = "rcv._tab.Mutate" + type;
GenReceiver(struct_def, code_ptr);
code += " Mutate" + MakeCamel(field.name);
code += "(n " + TypeName(field) + ") bool { return " + setter;
code += "(rcv._tab.Pos + flatbuffers.UOffsetT(";
code += NumToString(field.value.offset) + "), n) }\n\n";
}
// Mutate the value of a table's scalar.
static void MutateScalarFieldOfTable(const StructDef &struct_def,
const FieldDef &field,
std::string *code_ptr) {
std::string &code = *code_ptr;
std::string type = MakeCamel(GenTypeBasic(field.value.type));
std::string setter = "rcv._tab.Mutate" + type + "Slot";
GenReceiver(struct_def, code_ptr);
code += " Mutate" + MakeCamel(field.name);
code += "(n " + TypeName(field) + ") bool {\n\treturn ";
code += setter + "(" + NumToString(field.value.offset) + ", n)\n";
code += "}\n\n";
}
// Generate a struct field setter, conditioned on its child type(s).
static void GenStructMutator(const StructDef &struct_def,
const FieldDef &field,
std::string *code_ptr) {
GenComment(field.doc_comment, code_ptr, nullptr, "");
if (IsScalar(field.value.type.base_type)) {
if (struct_def.fixed) {
MutateScalarFieldOfStruct(struct_def, field, code_ptr);
} else {
MutateScalarFieldOfTable(struct_def, field, code_ptr);
}
}
}
// Generate table constructors, conditioned on its members' types. // Generate table constructors, conditioned on its members' types.
static void GenTableBuilders(const StructDef &struct_def, static void GenTableBuilders(const StructDef &struct_def,
std::string *code_ptr) { std::string *code_ptr) {
...@@ -530,6 +572,7 @@ static void GenStruct(const StructDef &struct_def, ...@@ -530,6 +572,7 @@ static void GenStruct(const StructDef &struct_def,
if (field.deprecated) continue; if (field.deprecated) continue;
GenStructAccessor(struct_def, field, code_ptr); GenStructAccessor(struct_def, field, code_ptr);
GenStructMutator(struct_def, field, code_ptr);
} }
if (struct_def.fixed) { if (struct_def.fixed) {
...@@ -681,4 +724,3 @@ bool GenerateGo(const Parser &parser, const std::string &path, ...@@ -681,4 +724,3 @@ bool GenerateGo(const Parser &parser, const std::string &path,
} }
} // namespace flatbuffers } // namespace flatbuffers
...@@ -43,6 +43,10 @@ func (rcv *Monster) Mana() int16 { ...@@ -43,6 +43,10 @@ func (rcv *Monster) Mana() int16 {
return 150 return 150
} }
func (rcv *Monster) MutateMana(n int16) bool {
return rcv._tab.MutateInt16Slot(6, n)
}
func (rcv *Monster) Hp() int16 { func (rcv *Monster) Hp() int16 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 { if o != 0 {
...@@ -51,6 +55,10 @@ func (rcv *Monster) Hp() int16 { ...@@ -51,6 +55,10 @@ func (rcv *Monster) Hp() int16 {
return 100 return 100
} }
func (rcv *Monster) MutateHp(n int16) bool {
return rcv._tab.MutateInt16Slot(8, n)
}
func (rcv *Monster) Name() []byte { func (rcv *Monster) Name() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(10)) o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
if o != 0 { if o != 0 {
...@@ -92,6 +100,10 @@ func (rcv *Monster) Color() int8 { ...@@ -92,6 +100,10 @@ func (rcv *Monster) Color() int8 {
return 8 return 8
} }
func (rcv *Monster) MutateColor(n int8) bool {
return rcv._tab.MutateInt8Slot(16, n)
}
func (rcv *Monster) TestType() byte { func (rcv *Monster) TestType() byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(18)) o := flatbuffers.UOffsetT(rcv._tab.Offset(18))
if o != 0 { if o != 0 {
...@@ -100,6 +112,10 @@ func (rcv *Monster) TestType() byte { ...@@ -100,6 +112,10 @@ func (rcv *Monster) TestType() byte {
return 0 return 0
} }
func (rcv *Monster) MutateTestType(n byte) bool {
return rcv._tab.MutateByteSlot(18, n)
}
func (rcv *Monster) Test(obj *flatbuffers.Table) bool { func (rcv *Monster) Test(obj *flatbuffers.Table) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(20)) o := flatbuffers.UOffsetT(rcv._tab.Offset(20))
if o != 0 { if o != 0 {
...@@ -173,6 +189,8 @@ func (rcv *Monster) TestarrayoftablesLength() int { ...@@ -173,6 +189,8 @@ func (rcv *Monster) TestarrayoftablesLength() int {
return 0 return 0
} }
/// an example documentation comment: this will end up in the generated code
/// multiline too
func (rcv *Monster) Enemy(obj *Monster) *Monster { func (rcv *Monster) Enemy(obj *Monster) *Monster {
o := flatbuffers.UOffsetT(rcv._tab.Offset(28)) o := flatbuffers.UOffsetT(rcv._tab.Offset(28))
if o != 0 { if o != 0 {
...@@ -232,6 +250,10 @@ func (rcv *Monster) Testbool() byte { ...@@ -232,6 +250,10 @@ func (rcv *Monster) Testbool() byte {
return 0 return 0
} }
func (rcv *Monster) MutateTestbool(n byte) bool {
return rcv._tab.MutateByteSlot(34, n)
}
func (rcv *Monster) Testhashs32Fnv1() int32 { func (rcv *Monster) Testhashs32Fnv1() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(36)) o := flatbuffers.UOffsetT(rcv._tab.Offset(36))
if o != 0 { if o != 0 {
...@@ -240,6 +262,10 @@ func (rcv *Monster) Testhashs32Fnv1() int32 { ...@@ -240,6 +262,10 @@ func (rcv *Monster) Testhashs32Fnv1() int32 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashs32Fnv1(n int32) bool {
return rcv._tab.MutateInt32Slot(36, n)
}
func (rcv *Monster) Testhashu32Fnv1() uint32 { func (rcv *Monster) Testhashu32Fnv1() uint32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(38)) o := flatbuffers.UOffsetT(rcv._tab.Offset(38))
if o != 0 { if o != 0 {
...@@ -248,6 +274,10 @@ func (rcv *Monster) Testhashu32Fnv1() uint32 { ...@@ -248,6 +274,10 @@ func (rcv *Monster) Testhashu32Fnv1() uint32 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashu32Fnv1(n uint32) bool {
return rcv._tab.MutateUint32Slot(38, n)
}
func (rcv *Monster) Testhashs64Fnv1() int64 { func (rcv *Monster) Testhashs64Fnv1() int64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(40)) o := flatbuffers.UOffsetT(rcv._tab.Offset(40))
if o != 0 { if o != 0 {
...@@ -256,6 +286,10 @@ func (rcv *Monster) Testhashs64Fnv1() int64 { ...@@ -256,6 +286,10 @@ func (rcv *Monster) Testhashs64Fnv1() int64 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashs64Fnv1(n int64) bool {
return rcv._tab.MutateInt64Slot(40, n)
}
func (rcv *Monster) Testhashu64Fnv1() uint64 { func (rcv *Monster) Testhashu64Fnv1() uint64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(42)) o := flatbuffers.UOffsetT(rcv._tab.Offset(42))
if o != 0 { if o != 0 {
...@@ -264,6 +298,10 @@ func (rcv *Monster) Testhashu64Fnv1() uint64 { ...@@ -264,6 +298,10 @@ func (rcv *Monster) Testhashu64Fnv1() uint64 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashu64Fnv1(n uint64) bool {
return rcv._tab.MutateUint64Slot(42, n)
}
func (rcv *Monster) Testhashs32Fnv1a() int32 { func (rcv *Monster) Testhashs32Fnv1a() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(44)) o := flatbuffers.UOffsetT(rcv._tab.Offset(44))
if o != 0 { if o != 0 {
...@@ -272,6 +310,10 @@ func (rcv *Monster) Testhashs32Fnv1a() int32 { ...@@ -272,6 +310,10 @@ func (rcv *Monster) Testhashs32Fnv1a() int32 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashs32Fnv1a(n int32) bool {
return rcv._tab.MutateInt32Slot(44, n)
}
func (rcv *Monster) Testhashu32Fnv1a() uint32 { func (rcv *Monster) Testhashu32Fnv1a() uint32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(46)) o := flatbuffers.UOffsetT(rcv._tab.Offset(46))
if o != 0 { if o != 0 {
...@@ -280,6 +322,10 @@ func (rcv *Monster) Testhashu32Fnv1a() uint32 { ...@@ -280,6 +322,10 @@ func (rcv *Monster) Testhashu32Fnv1a() uint32 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashu32Fnv1a(n uint32) bool {
return rcv._tab.MutateUint32Slot(46, n)
}
func (rcv *Monster) Testhashs64Fnv1a() int64 { func (rcv *Monster) Testhashs64Fnv1a() int64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(48)) o := flatbuffers.UOffsetT(rcv._tab.Offset(48))
if o != 0 { if o != 0 {
...@@ -288,6 +334,10 @@ func (rcv *Monster) Testhashs64Fnv1a() int64 { ...@@ -288,6 +334,10 @@ func (rcv *Monster) Testhashs64Fnv1a() int64 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashs64Fnv1a(n int64) bool {
return rcv._tab.MutateInt64Slot(48, n)
}
func (rcv *Monster) Testhashu64Fnv1a() uint64 { func (rcv *Monster) Testhashu64Fnv1a() uint64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(50)) o := flatbuffers.UOffsetT(rcv._tab.Offset(50))
if o != 0 { if o != 0 {
...@@ -296,6 +346,10 @@ func (rcv *Monster) Testhashu64Fnv1a() uint64 { ...@@ -296,6 +346,10 @@ func (rcv *Monster) Testhashu64Fnv1a() uint64 {
return 0 return 0
} }
func (rcv *Monster) MutateTesthashu64Fnv1a(n uint64) bool {
return rcv._tab.MutateUint64Slot(50, n)
}
func (rcv *Monster) Testarrayofbools(j int) byte { func (rcv *Monster) Testarrayofbools(j int) byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(52)) o := flatbuffers.UOffsetT(rcv._tab.Offset(52))
if o != 0 { if o != 0 {
...@@ -321,6 +375,10 @@ func (rcv *Monster) Testf() float32 { ...@@ -321,6 +375,10 @@ func (rcv *Monster) Testf() float32 {
return 3.14159 return 3.14159
} }
func (rcv *Monster) MutateTestf(n float32) bool {
return rcv._tab.MutateFloat32Slot(54, n)
}
func (rcv *Monster) Testf2() float32 { func (rcv *Monster) Testf2() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(56)) o := flatbuffers.UOffsetT(rcv._tab.Offset(56))
if o != 0 { if o != 0 {
...@@ -329,6 +387,10 @@ func (rcv *Monster) Testf2() float32 { ...@@ -329,6 +387,10 @@ func (rcv *Monster) Testf2() float32 {
return 3.0 return 3.0
} }
func (rcv *Monster) MutateTestf2(n float32) bool {
return rcv._tab.MutateFloat32Slot(56, n)
}
func (rcv *Monster) Testf3() float32 { func (rcv *Monster) Testf3() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(58)) o := flatbuffers.UOffsetT(rcv._tab.Offset(58))
if o != 0 { if o != 0 {
...@@ -337,6 +399,10 @@ func (rcv *Monster) Testf3() float32 { ...@@ -337,6 +399,10 @@ func (rcv *Monster) Testf3() float32 {
return 0.0 return 0.0
} }
func (rcv *Monster) MutateTestf3(n float32) bool {
return rcv._tab.MutateFloat32Slot(58, n)
}
func (rcv *Monster) Testarrayofstring2(j int) []byte { func (rcv *Monster) Testarrayofstring2(j int) []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(60)) o := flatbuffers.UOffsetT(rcv._tab.Offset(60))
if o != 0 { if o != 0 {
......
...@@ -30,6 +30,10 @@ func (rcv *Stat) Val() int64 { ...@@ -30,6 +30,10 @@ func (rcv *Stat) Val() int64 {
return 0 return 0
} }
func (rcv *Stat) MutateVal(n int64) bool {
return rcv._tab.MutateInt64Slot(6, n)
}
func (rcv *Stat) Count() uint16 { func (rcv *Stat) Count() uint16 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8)) o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 { if o != 0 {
...@@ -38,6 +42,10 @@ func (rcv *Stat) Count() uint16 { ...@@ -38,6 +42,10 @@ func (rcv *Stat) Count() uint16 {
return 0 return 0
} }
func (rcv *Stat) MutateCount(n uint16) bool {
return rcv._tab.MutateUint16Slot(8, n)
}
func StatStart(builder *flatbuffers.Builder) { builder.StartObject(3) } func StatStart(builder *flatbuffers.Builder) { builder.StartObject(3) }
func StatAddId(builder *flatbuffers.Builder, id flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(id), 0) } func StatAddId(builder *flatbuffers.Builder, id flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(id), 0) }
func StatAddVal(builder *flatbuffers.Builder, val int64) { builder.PrependInt64Slot(1, val, 0) } func StatAddVal(builder *flatbuffers.Builder, val int64) { builder.PrependInt64Slot(1, val, 0) }
......
...@@ -15,7 +15,11 @@ func (rcv *Test) Init(buf []byte, i flatbuffers.UOffsetT) { ...@@ -15,7 +15,11 @@ func (rcv *Test) Init(buf []byte, i flatbuffers.UOffsetT) {
} }
func (rcv *Test) A() int16 { return rcv._tab.GetInt16(rcv._tab.Pos + flatbuffers.UOffsetT(0)) } func (rcv *Test) A() int16 { return rcv._tab.GetInt16(rcv._tab.Pos + flatbuffers.UOffsetT(0)) }
func (rcv *Test) MutateA(n int16) bool { return rcv._tab.MutateInt16(rcv._tab.Pos + flatbuffers.UOffsetT(0), n) }
func (rcv *Test) B() int8 { return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(2)) } func (rcv *Test) B() int8 { return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(2)) }
func (rcv *Test) MutateB(n int8) bool { return rcv._tab.MutateInt8(rcv._tab.Pos + flatbuffers.UOffsetT(2), n) }
func CreateTest(builder *flatbuffers.Builder, a int16, b int8) flatbuffers.UOffsetT { func CreateTest(builder *flatbuffers.Builder, a int16, b int8) flatbuffers.UOffsetT {
builder.Prep(2, 4) builder.Prep(2, 4)
......
...@@ -22,6 +22,10 @@ func (rcv *TestSimpleTableWithEnum) Color() int8 { ...@@ -22,6 +22,10 @@ func (rcv *TestSimpleTableWithEnum) Color() int8 {
return 2 return 2
} }
func (rcv *TestSimpleTableWithEnum) MutateColor(n int8) bool {
return rcv._tab.MutateInt8Slot(4, n)
}
func TestSimpleTableWithEnumStart(builder *flatbuffers.Builder) { builder.StartObject(1) } func TestSimpleTableWithEnumStart(builder *flatbuffers.Builder) { builder.StartObject(1) }
func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color int8) { builder.PrependInt8Slot(0, color, 2) } func TestSimpleTableWithEnumAddColor(builder *flatbuffers.Builder, color int8) { builder.PrependInt8Slot(0, color, 2) }
func TestSimpleTableWithEnumEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } func TestSimpleTableWithEnumEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() }
...@@ -15,10 +15,20 @@ func (rcv *Vec3) Init(buf []byte, i flatbuffers.UOffsetT) { ...@@ -15,10 +15,20 @@ func (rcv *Vec3) Init(buf []byte, i flatbuffers.UOffsetT) {
} }
func (rcv *Vec3) X() float32 { return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(0)) } func (rcv *Vec3) X() float32 { return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(0)) }
func (rcv *Vec3) MutateX(n float32) bool { return rcv._tab.MutateFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(0), n) }
func (rcv *Vec3) Y() float32 { return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(4)) } func (rcv *Vec3) Y() float32 { return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(4)) }
func (rcv *Vec3) MutateY(n float32) bool { return rcv._tab.MutateFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(4), n) }
func (rcv *Vec3) Z() float32 { return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(8)) } func (rcv *Vec3) Z() float32 { return rcv._tab.GetFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(8)) }
func (rcv *Vec3) MutateZ(n float32) bool { return rcv._tab.MutateFloat32(rcv._tab.Pos + flatbuffers.UOffsetT(8), n) }
func (rcv *Vec3) Test1() float64 { return rcv._tab.GetFloat64(rcv._tab.Pos + flatbuffers.UOffsetT(16)) } func (rcv *Vec3) Test1() float64 { return rcv._tab.GetFloat64(rcv._tab.Pos + flatbuffers.UOffsetT(16)) }
func (rcv *Vec3) MutateTest1(n float64) bool { return rcv._tab.MutateFloat64(rcv._tab.Pos + flatbuffers.UOffsetT(16), n) }
func (rcv *Vec3) Test2() int8 { return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(24)) } func (rcv *Vec3) Test2() int8 { return rcv._tab.GetInt8(rcv._tab.Pos + flatbuffers.UOffsetT(24)) }
func (rcv *Vec3) MutateTest2(n int8) bool { return rcv._tab.MutateInt8(rcv._tab.Pos + flatbuffers.UOffsetT(24), n) }
func (rcv *Vec3) Test3(obj *Test) *Test { func (rcv *Vec3) Test3(obj *Test) *Test {
if obj == nil { if obj == nil {
obj = new(Test) obj = new(Test)
......
This diff is collapsed.
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