mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-19 14:35:42 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user