Optional-ness in reflection (#6097)

* Optional scalars in reflection

* fixed name collision

* Remove code duplicated by merge

Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
Casper
2020-09-11 14:20:32 -07:00
committed by GitHub
parent 338944d3d9
commit c75ae24293
11 changed files with 523 additions and 487 deletions

View File

@@ -900,6 +900,7 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
TEST_EQ_STR(hp_field.name()->c_str(), "hp");
TEST_EQ(hp_field.id(), 2);
TEST_EQ(hp_field.type()->base_type(), reflection::Short);
auto friendly_field_ptr = fields->LookupByKey("friendly");
TEST_NOTNULL(friendly_field_ptr);
TEST_NOTNULL(friendly_field_ptr->attributes());
@@ -913,6 +914,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
TEST_NOTNULL(pos_table_ptr);
TEST_EQ_STR(pos_table_ptr->name()->c_str(), "MyGame.Example.Vec3");
// Test nullability of fields: hp is a 0-default scalar, pos is a struct =>
// optional, and name is a required string => not optional.
TEST_EQ(hp_field.optional(), false);
TEST_EQ(pos_field_ptr->optional(), true);
TEST_EQ(fields->LookupByKey("name")->optional(), false);
// Now use it to dynamically access a buffer.
auto &root = *flatbuffers::GetAnyRoot(flatbuf);