mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 17:22:21 +00:00
Add byte slice accessor to Go code
This commit is contained in:
@@ -75,6 +75,14 @@ func (rcv *Monster) InventoryLength() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv *Monster) InventoryBytes() []byte {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(14))
|
||||
if o != 0 {
|
||||
return rcv._tab.ByteVector(o + rcv._tab.Pos)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcv *Monster) Color() int8 {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(16))
|
||||
if o != 0 {
|
||||
@@ -140,7 +148,9 @@ func (rcv *Monster) TestarrayofstringLength() int {
|
||||
}
|
||||
|
||||
/// an example documentation comment: this will end up in the generated code
|
||||
|
||||
/// multiline too
|
||||
|
||||
func (rcv *Monster) Testarrayoftables(obj *Monster, j int) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(26))
|
||||
if o != 0 {
|
||||
@@ -194,6 +204,14 @@ func (rcv *Monster) TestnestedflatbufferLength() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv *Monster) TestnestedflatbufferBytes() []byte {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(30))
|
||||
if o != 0 {
|
||||
return rcv._tab.ByteVector(o + rcv._tab.Pos)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcv *Monster) Testempty(obj *Stat) *Stat {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(32))
|
||||
if o != 0 {
|
||||
|
||||
@@ -213,6 +213,11 @@ func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string,
|
||||
fail(FailString("monster2.Name()", "Fred", got))
|
||||
}
|
||||
|
||||
inventorySlice := monster.InventoryBytes()
|
||||
if len(inventorySlice) != monster.InventoryLength() {
|
||||
fail(FailString("len(monster.InventoryBytes) != monster.InventoryLength", len(inventorySlice), monster.InventoryLength()))
|
||||
}
|
||||
|
||||
if got := monster.InventoryLength(); 5 != got {
|
||||
fail(FailString("monster.InventoryLength", 5, got))
|
||||
}
|
||||
@@ -221,6 +226,9 @@ func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string,
|
||||
l := monster.InventoryLength()
|
||||
for i := 0; i < l; i++ {
|
||||
v := monster.Inventory(i)
|
||||
if v != inventorySlice[i] {
|
||||
fail(FailString("monster inventory slice[i] != Inventory(i)", v, inventorySlice[i]))
|
||||
}
|
||||
invsum += int(v)
|
||||
}
|
||||
if invsum != 10 {
|
||||
|
||||
Reference in New Issue
Block a user