diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2014-07-15 17:50:22 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2014-07-21 16:40:39 -0700 |
commit | 3e201a99b2f23c8c8475e43803d122b105db9a68 (patch) | |
tree | 57c95caa3e9b688e701e5d1841380c8dfe95dbf8 /tests | |
parent | 9143a93312b65955511838fafddf56301716be41 (diff) | |
download | flatbuffers-3e201a99b2f23c8c8475e43803d122b105db9a68.tar.gz flatbuffers-3e201a99b2f23c8c8475e43803d122b105db9a68.tar.bz2 flatbuffers-3e201a99b2f23c8c8475e43803d122b105db9a68.zip |
A feature that officially supports nested FlatBuffers.
Generates convenient accessors for the nested root.
Change-Id: Ic0b1531de7ace475ff2a7b1f430d27f41c838430
Tested: on Windows.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/MyGame/Example/Monster.go | 21 | ||||
-rwxr-xr-x | tests/MyGame/Example/Monster.java | 6 | ||||
-rwxr-xr-x | tests/monster_test.fbs | 1 | ||||
-rwxr-xr-x | tests/monster_test_generated.h | 13 | ||||
-rw-r--r-- | tests/monsterdata_test.bin | bin | 176 -> 176 bytes |
5 files changed, 36 insertions, 5 deletions
diff --git a/tests/MyGame/Example/Monster.go b/tests/MyGame/Example/Monster.go index 2bceae58..16894f16 100644 --- a/tests/MyGame/Example/Monster.go +++ b/tests/MyGame/Example/Monster.go @@ -176,7 +176,24 @@ func (rcv *Monster) Enemy(obj *Monster) *Monster { return nil } -func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(13) } +func (rcv *Monster) Testnestedflatbuffer(j int) byte { + o := flatbuffers.UOffsetT(rcv._tab.Offset(30)) + if o != 0 { + a := rcv._tab.Vector(o) + return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j * 1)) + } + return 0 +} + +func (rcv *Monster) TestnestedflatbufferLength() int { + o := flatbuffers.UOffsetT(rcv._tab.Offset(30)) + if o != 0 { + return rcv._tab.VectorLen(o) + } + return 0 +} + +func MonsterStart(builder *flatbuffers.Builder) { builder.StartObject(14) } func MonsterAddPos(builder *flatbuffers.Builder, pos flatbuffers.UOffsetT) { builder.PrependStructSlot(0, flatbuffers.UOffsetT(pos), 0) } func MonsterAddMana(builder *flatbuffers.Builder, mana int16) { builder.PrependInt16Slot(1, mana, 150) } func MonsterAddHp(builder *flatbuffers.Builder, hp int16) { builder.PrependInt16Slot(2, hp, 100) } @@ -193,4 +210,6 @@ func MonsterStartTestarrayofstringVector(builder *flatbuffers.Builder, numElems func MonsterAddTestarrayoftables(builder *flatbuffers.Builder, testarrayoftables flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(11, flatbuffers.UOffsetT(testarrayoftables), 0) } func MonsterStartTestarrayoftablesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(4, numElems) } func MonsterAddEnemy(builder *flatbuffers.Builder, enemy flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(12, flatbuffers.UOffsetT(enemy), 0) } +func MonsterAddTestnestedflatbuffer(builder *flatbuffers.Builder, testnestedflatbuffer flatbuffers.UOffsetT) { builder.PrependUOffsetTSlot(13, flatbuffers.UOffsetT(testnestedflatbuffer), 0) } +func MonsterStartTestnestedflatbufferVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT { return builder.StartVector(1, numElems) } func MonsterEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT { return builder.EndObject() } diff --git a/tests/MyGame/Example/Monster.java b/tests/MyGame/Example/Monster.java index 439dd7a4..dcb7699c 100755 --- a/tests/MyGame/Example/Monster.java +++ b/tests/MyGame/Example/Monster.java @@ -31,8 +31,10 @@ public class Monster extends Table { public int testarrayoftablesLength() { int o = __offset(26); return o != 0 ? __vector_len(o) : 0; } public Monster enemy() { return enemy(new Monster()); } public Monster enemy(Monster obj) { int o = __offset(28); return o != 0 ? obj.__init(__indirect(o + bb_pos), bb) : null; } + public byte testnestedflatbuffer(int j) { int o = __offset(30); return o != 0 ? bb.get(__vector(o) + j * 1) : 0; } + public int testnestedflatbufferLength() { int o = __offset(30); return o != 0 ? __vector_len(o) : 0; } - public static void startMonster(FlatBufferBuilder builder) { builder.startObject(13); } + public static void startMonster(FlatBufferBuilder builder) { builder.startObject(14); } public static void addPos(FlatBufferBuilder builder, int posOffset) { builder.addStruct(0, posOffset, 0); } public static void addMana(FlatBufferBuilder builder, short mana) { builder.addShort(1, mana, 150); } public static void addHp(FlatBufferBuilder builder, short hp) { builder.addShort(2, hp, 100); } @@ -49,6 +51,8 @@ public class Monster extends Table { public static void addTestarrayoftables(FlatBufferBuilder builder, int testarrayoftablesOffset) { builder.addOffset(11, testarrayoftablesOffset, 0); } public static void startTestarrayoftablesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems); } public static void addEnemy(FlatBufferBuilder builder, int enemyOffset) { builder.addOffset(12, enemyOffset, 0); } + public static void addTestnestedflatbuffer(FlatBufferBuilder builder, int testnestedflatbufferOffset) { builder.addOffset(13, testnestedflatbufferOffset, 0); } + public static void startTestnestedflatbufferVector(FlatBufferBuilder builder, int numElems) { builder.startVector(1, numElems); } public static int endMonster(FlatBufferBuilder builder) { return builder.endObject(); } }; diff --git a/tests/monster_test.fbs b/tests/monster_test.fbs index cf191c41..9e6d4446 100755 --- a/tests/monster_test.fbs +++ b/tests/monster_test.fbs @@ -32,6 +32,7 @@ table Monster { enemy:Monster (id:12); test:Any (id: 8); test4:[Test] (id: 9); + testnestedflatbuffer:[ubyte] (id:13, nested_flatbuffer: "Monster"); } root_type Monster; diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index b8ad91c4..e6beb77b 100755 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -93,6 +93,8 @@ struct Monster : private flatbuffers::Table { /// an example documentation comment: this will end up in the generated code multiline too const flatbuffers::Vector<flatbuffers::Offset<Monster>> *testarrayoftables() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Monster>> *>(26); } const Monster *enemy() const { return GetPointer<const Monster *>(28); } + const flatbuffers::Vector<uint8_t> *testnestedflatbuffer() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(30); } + const Monster *testnestedflatbuffer_nested_root() { return flatbuffers::GetRoot<Monster>(testnestedflatbuffer()->Data()); } bool Verify(const flatbuffers::Verifier &verifier) const { return VerifyTable(verifier) && VerifyField<Vec3>(verifier, 4 /* pos */) && @@ -115,7 +117,9 @@ struct Monster : private flatbuffers::Table { verifier.Verify(testarrayoftables()) && verifier.VerifyVectorOfTables(testarrayoftables()) && VerifyField<flatbuffers::uoffset_t>(verifier, 28 /* enemy */) && - verifier.VerifyTable(enemy()); + verifier.VerifyTable(enemy()) && + VerifyField<flatbuffers::uoffset_t>(verifier, 30 /* testnestedflatbuffer */) && + verifier.Verify(testnestedflatbuffer()); } }; @@ -134,9 +138,10 @@ struct MonsterBuilder { void add_testarrayofstring(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> testarrayofstring) { fbb_.AddOffset(24, testarrayofstring); } void add_testarrayoftables(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Monster>>> testarrayoftables) { fbb_.AddOffset(26, testarrayoftables); } void add_enemy(flatbuffers::Offset<Monster> enemy) { fbb_.AddOffset(28, enemy); } + void add_testnestedflatbuffer(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> testnestedflatbuffer) { fbb_.AddOffset(30, testnestedflatbuffer); } MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } MonsterBuilder &operator=(const MonsterBuilder &); - flatbuffers::Offset<Monster> Finish() { return flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 13)); } + flatbuffers::Offset<Monster> Finish() { return flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 14)); } }; inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, @@ -151,8 +156,10 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder flatbuffers::Offset<flatbuffers::Vector<const Test *>> test4 = 0, flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> testarrayofstring = 0, flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Monster>>> testarrayoftables = 0, - flatbuffers::Offset<Monster> enemy = 0) { + flatbuffers::Offset<Monster> enemy = 0, + flatbuffers::Offset<flatbuffers::Vector<uint8_t>> testnestedflatbuffer = 0) { MonsterBuilder builder_(_fbb); + builder_.add_testnestedflatbuffer(testnestedflatbuffer); builder_.add_enemy(enemy); builder_.add_testarrayoftables(testarrayoftables); builder_.add_testarrayofstring(testarrayofstring); diff --git a/tests/monsterdata_test.bin b/tests/monsterdata_test.bin Binary files differindex f09bf508..63137456 100644 --- a/tests/monsterdata_test.bin +++ b/tests/monsterdata_test.bin |