Hello,

In Flatbuffers, all fields are optional by default.  It means that the
reader can get NULL (in C++) for a missing field.  In turn, this means
that message validation (at least in C++) should check all child table
fields for non-NULL.  Not only is this burdensome, but it's easy to miss
some checks.  Currently, we don't seem to do any of them.

Instead, it seems we could mark most child fields *required*.  This
would allow the generated verifier to check that those fields are indeed
non-NULL when reading.  It would also potentially break compatibility,
though I'm not sure why (do people rely on the fields being missing
sometimes?).  What do you think?


To quote the Flatbuffers documentation:
"""
By default, all fields are optional, i.e. may be left out. This is
desirable, as it helps with forwards/backwards compatibility, and
flexibility of data structures. It is also a burden on the reading code,
since for non-scalar fields it requires you to check against NULL and
take appropriate action. By specifying this field, you force code that
constructs FlatBuffers to ensure this field is initialized, so the
reading code may access it directly, without checking for NULL. If the
constructing code does not initialize this field, they will get an
assert, and also the verifier will fail on buffers that have missing
required fields.
"""
https://google.github.io/flatbuffers/md__schemas.html

Regards

Antoine.

Reply via email to