From 3ff6cdf49181061bd545bcd3a2a292bca3e8ef6b Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Sat, 6 Apr 2019 06:34:53 +1100 Subject: [PATCH] [C++]Sync the sample monster.fbs file with the tutorial (#5277) * Fix the header file path in the tutorial doc * Add the path field in sample/monster.fbs to match the tutorial * Update the lobster sample file * Update the binary sample file --- docs/source/Tutorial.md | 2 +- samples/monster.bfbs | Bin 1768 -> 1840 bytes samples/monster.fbs | 1 + samples/monster_generated.h | 42 +++++++++++++++++++++++------- samples/monster_generated.lobster | 10 ++++++- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md index 482fe1be9..72b49a0ec 100644 --- a/docs/source/Tutorial.md +++ b/docs/source/Tutorial.md @@ -1922,7 +1922,7 @@ before:
~~~{.cpp} - #include "monster_generate.h" // This was generated by `flatc`. + #include "monster_generated.h" // This was generated by `flatc`. using namespace MyGame::Sample; // Specified in the schema. ~~~ diff --git a/samples/monster.bfbs b/samples/monster.bfbs index 95a977a36bdbfdfbb18abe4a8ae3904a571610cc..061a17b6e067a33c8afb7c95d2b82fd57f0f58bc 100644 GIT binary patch delta 341 zcmaFCyMb?l4&#=Iy4su_ObiSUSQ!{@Oia{gY@0aIn=xkMU1`a8zyAMcU|`?}$}+G4 zad>KCL4Fb?uogndcldg z1v#mD&iOg{MGTX7Fe*%b!OWvH<^TWxEI>t0Ii;x#415eS3@i)+Kt2Zp50J;epujNk zp48+gj17k8fYvYqT_FJ!AbANzNn%u}H%(!UsN+xwi zm&q5Igmt-rDijzQ7)pTj5+I%fWP1R;<^rTA0O=n>nnE@gnQO5uP delta 305 zcmdnM_kwqV4&#D}y4sv2ObiS&SQ!|OOia{gJU4NoH>1bIyV8KCL4FAoAdUcH86Xx0V&6*l#N1T9;Kba5 zoK!vM{G9wEhHL--{|Cv705J~`gDil789+G}Ajc`EGMg>O3$!{6EC7J&G|IY|? zg#=Ivqy?k|1XfL+$RsSu^cUn(77W>IllL;I+d2T%2>>x85X1Cw0oiYW*a3(OfH(sv dDFSqd0FaIW(no;w0wCQpS(RCSa|!bvW&l@1KF$CD diff --git a/samples/monster.fbs b/samples/monster.fbs index 247b81771..af224512e 100644 --- a/samples/monster.fbs +++ b/samples/monster.fbs @@ -22,6 +22,7 @@ table Monster { color:Color = Blue; weapons:[Weapon]; equipped:Equipment; + path:[Vec3]; } table Weapon { diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 84e816024..e89ec3a51 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -224,6 +224,7 @@ struct MonsterT : public flatbuffers::NativeTable { Color color; std::vector> weapons; EquipmentUnion equipped; + std::vector path; MonsterT() : mana(150), hp(100), @@ -240,7 +241,8 @@ inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) { (lhs.inventory == rhs.inventory) && (lhs.color == rhs.color) && (lhs.weapons == rhs.weapons) && - (lhs.equipped == rhs.equipped); + (lhs.equipped == rhs.equipped) && + (lhs.path == rhs.path); } inline bool operator!=(const MonsterT &lhs, const MonsterT &rhs) { @@ -262,7 +264,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_COLOR = 16, VT_WEAPONS = 18, VT_EQUIPPED_TYPE = 20, - VT_EQUIPPED = 22 + VT_EQUIPPED = 22, + VT_PATH = 24 }; const Vec3 *pos() const { return GetStruct(VT_POS); @@ -322,6 +325,12 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { void *mutable_equipped() { return GetPointer(VT_EQUIPPED); } + const flatbuffers::Vector *path() const { + return GetPointer *>(VT_PATH); + } + flatbuffers::Vector *mutable_path() { + return GetPointer *>(VT_PATH); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_POS) && @@ -338,6 +347,8 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VerifyField(verifier, VT_EQUIPPED_TYPE) && VerifyOffset(verifier, VT_EQUIPPED) && VerifyEquipment(verifier, equipped(), equipped_type()) && + VerifyOffset(verifier, VT_PATH) && + verifier.VerifyVector(path()) && verifier.EndTable(); } MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; @@ -379,6 +390,9 @@ struct MonsterBuilder { void add_equipped(flatbuffers::Offset equipped) { fbb_.AddOffset(Monster::VT_EQUIPPED, equipped); } + void add_path(flatbuffers::Offset> path) { + fbb_.AddOffset(Monster::VT_PATH, path); + } explicit MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -401,8 +415,10 @@ inline flatbuffers::Offset CreateMonster( Color color = Color_Blue, flatbuffers::Offset>> weapons = 0, Equipment equipped_type = Equipment_NONE, - flatbuffers::Offset equipped = 0) { + flatbuffers::Offset equipped = 0, + flatbuffers::Offset> path = 0) { MonsterBuilder builder_(_fbb); + builder_.add_path(path); builder_.add_equipped(equipped); builder_.add_weapons(weapons); builder_.add_inventory(inventory); @@ -425,10 +441,12 @@ inline flatbuffers::Offset CreateMonsterDirect( Color color = Color_Blue, const std::vector> *weapons = nullptr, Equipment equipped_type = Equipment_NONE, - flatbuffers::Offset equipped = 0) { + flatbuffers::Offset equipped = 0, + const std::vector *path = nullptr) { auto name__ = name ? _fbb.CreateString(name) : 0; auto inventory__ = inventory ? _fbb.CreateVector(*inventory) : 0; auto weapons__ = weapons ? _fbb.CreateVector>(*weapons) : 0; + auto path__ = path ? _fbb.CreateVectorOfStructs(*path) : 0; return MyGame::Sample::CreateMonster( _fbb, pos, @@ -439,7 +457,8 @@ inline flatbuffers::Offset CreateMonsterDirect( color, weapons__, equipped_type, - equipped); + equipped, + path__); } flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); @@ -559,6 +578,7 @@ inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function { auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons[_i] = flatbuffers::unique_ptr(_e->Get(_i)->UnPack(_resolver)); } } }; { auto _e = equipped_type(); _o->equipped.type = _e; }; { auto _e = equipped(); if (_e) _o->equipped.value = EquipmentUnion::UnPack(_e, equipped_type(), _resolver); }; + { auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } }; } inline flatbuffers::Offset Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) { @@ -578,6 +598,7 @@ inline flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder auto _weapons = _o->weapons.size() ? _fbb.CreateVector> (_o->weapons.size(), [](size_t i, _VectorArgs *__va) { return CreateWeapon(*__va->__fbb, __va->__o->weapons[i].get(), __va->__rehasher); }, &_va ) : 0; auto _equipped_type = _o->equipped.type; auto _equipped = _o->equipped.Pack(_fbb); + auto _path = _o->path.size() ? _fbb.CreateVectorOfStructs(_o->path) : 0; return MyGame::Sample::CreateMonster( _fbb, _pos, @@ -588,7 +609,8 @@ inline flatbuffers::Offset CreateMonster(flatbuffers::FlatBufferBuilder _color, _weapons, _equipped_type, - _equipped); + _equipped, + _path); } inline WeaponT *Weapon::UnPack(const flatbuffers::resolver_function_t *_resolver) const { @@ -756,7 +778,8 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() { { flatbuffers::ET_CHAR, 0, 1 }, { flatbuffers::ET_SEQUENCE, 1, 2 }, { flatbuffers::ET_UTYPE, 0, 3 }, - { flatbuffers::ET_SEQUENCE, 0, 3 } + { flatbuffers::ET_SEQUENCE, 0, 3 }, + { flatbuffers::ET_SEQUENCE, 1, 0 } }; static const flatbuffers::TypeFunction type_refs[] = { Vec3TypeTable, @@ -774,10 +797,11 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() { "color", "weapons", "equipped_type", - "equipped" + "equipped", + "path" }; static const flatbuffers::TypeTable tt = { - flatbuffers::ST_TABLE, 10, type_codes, type_refs, nullptr, names + flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, names }; return &tt; } diff --git a/samples/monster_generated.lobster b/samples/monster_generated.lobster index c1a319966..409e77d74 100644 --- a/samples/monster_generated.lobster +++ b/samples/monster_generated.lobster @@ -58,11 +58,15 @@ struct Monster : flatbuffers_handle buf_.flatbuffers_field_int8(pos_, 20, 0) def equipped_as_Weapon(): MyGame_Sample_Weapon { buf_, buf_.flatbuffers_field_table(pos_, 22) } + def path(i:int): + MyGame_Sample_Vec3 { buf_, buf_.flatbuffers_field_vector(pos_, 24) + i * 12 } + def path_length(): + buf_.flatbuffers_field_vector_len(pos_, 24) def GetRootAsMonster(buf:string): Monster { buf, buf.flatbuffers_indirect(0) } def MonsterStart(b_:flatbuffers_builder): - b_.StartObject(10) + b_.StartObject(11) def MonsterAddPos(b_:flatbuffers_builder, pos:int): b_.PrependStructSlot(0, pos, 0) def MonsterAddMana(b_:flatbuffers_builder, mana:int): @@ -93,6 +97,10 @@ def MonsterAddEquippedType(b_:flatbuffers_builder, equipped_type:int): b_.PrependUint8Slot(8, equipped_type, 0) def MonsterAddEquipped(b_:flatbuffers_builder, equipped:int): b_.PrependUOffsetTRelativeSlot(9, equipped, 0) +def MonsterAddPath(b_:flatbuffers_builder, path:int): + b_.PrependUOffsetTRelativeSlot(10, path, 0) +def MonsterStartPathVector(b_:flatbuffers_builder, n_:int): + b_.StartVector(12, n_, 4) def MonsterEnd(b_:flatbuffers_builder): b_.EndObject()