Make string/vector field serialization order not depend on optimizer.

Multiple calls of e.g. CreateString inside a call to a CreateTable
could cause those strings to end up in different locations in the
wire format, since order or argument evaluation is undefined.

This is allowed by the FlatBuffer format, but it is not helpful,
especially when debugging the contents of binaries, or comparing
against a "golden" binary for tests etc.

Now making sure that all the CreateTableDirect calls first serialize
sub strings/vectors before calling CreateTable.

Also made similar changes to the serialization of "binary schemas".

Change-Id: I5747c4038b37a0d400aca2bc592bec751cf5c172
This commit is contained in:
Wouter van Oortmerssen
2018-11-16 16:22:18 -08:00
parent 5f32f94810
commit f575b02fda
7 changed files with 192 additions and 133 deletions

View File

@@ -408,15 +408,18 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
const std::vector<flatbuffers::Offset<Weapon>> *weapons = nullptr,
Equipment equipped_type = Equipment_NONE,
flatbuffers::Offset<void> equipped = 0) {
auto name__ = name ? _fbb.CreateString(name) : 0;
auto inventory__ = inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 0;
auto weapons__ = weapons ? _fbb.CreateVector<flatbuffers::Offset<Weapon>>(*weapons) : 0;
return MyGame::Sample::CreateMonster(
_fbb,
pos,
mana,
hp,
name ? _fbb.CreateString(name) : 0,
inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 0,
name__,
inventory__,
color,
weapons ? _fbb.CreateVector<flatbuffers::Offset<Weapon>>(*weapons) : 0,
weapons__,
equipped_type,
equipped);
}
@@ -506,9 +509,10 @@ inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
int16_t damage = 0) {
auto name__ = name ? _fbb.CreateString(name) : 0;
return MyGame::Sample::CreateWeapon(
_fbb,
name ? _fbb.CreateString(name) : 0,
name__,
damage);
}