aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2014-09-19 16:51:36 -0700
committerWouter van Oortmerssen <wvo@google.com>2014-09-22 15:53:19 -0700
commit517c964fe2099ecc0810db33cfd45b406b3f3132 (patch)
tree4b646dbde5cd5b70d4ef92c07d4cbbb27a594c50 /docs
parent3f8700b29669855ae440ad67180742ede82b3fb2 (diff)
downloadflatbuffers-517c964fe2099ecc0810db33cfd45b406b3f3132.tar.gz
Support for required fields.
Change-Id: I560c7ca11b3d665eecafb528f3737b7e139ca9b0 Tested: on Linux and Windows.
Diffstat (limited to 'docs')
-rw-r--r--docs/html/md__schemas.html1
-rwxr-xr-xdocs/source/Schemas.md12
2 files changed, 12 insertions, 1 deletions
diff --git a/docs/html/md__schemas.html b/docs/html/md__schemas.html
index 6662ed3a..28d69108 100644
--- a/docs/html/md__schemas.html
+++ b/docs/html/md__schemas.html
@@ -133,6 +133,7 @@ root_type Monster;
<ul>
<li><code>id: n</code> (on a table field): manually set the field identifier to <code>n</code>. If you use this attribute, you must use it on ALL fields of this table, and the numbers must be a contiguous range from 0 onwards. Additionally, since a union type effectively adds two fields, its id must be that of the second field (the first field is the type field and not explicitly declared in the schema). For example, if the last field before the union field had id 6, the union field should have id 8, and the unions type field will implicitly be 7. IDs allow the fields to be placed in any order in the schema. When a new field is added to the schema is must use the next available ID.</li>
<li><code>deprecated</code> (on a field): do not generate accessors for this field anymore, code should stop using this data.</li>
+<li><code>required</code> (on a non-scalar table field): this field must always be set. 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.</li>
<li><code>original_order</code> (on a table): since elements in a table do not need to be stored in any particular order, they are often optimized for space by sorting them to size. This attribute stops that from happening.</li>
<li><code>force_align: size</code> (on a struct): force the alignment of this struct to be something higher than what it is naturally aligned to. Causes these structs to be aligned to that amount inside a buffer, IF that buffer is allocated with that alignment (which is not necessarily the case for buffers accessed directly inside a <code>FlatBufferBuilder</code>).</li>
<li><code>bit_flags</code> (on an enum): the values of this field indicate bits, meaning that any value N specified in the schema will end up representing 1&lt;&lt;N, or if you don't specify values at all, you'll get the sequence 1, 2, 4, 8, ...</li>
diff --git a/docs/source/Schemas.md b/docs/source/Schemas.md
index f3afdfa6..d7b905f8 100755
--- a/docs/source/Schemas.md
+++ b/docs/source/Schemas.md
@@ -146,7 +146,7 @@ packages.
You can include other schemas files in your current one, e.g.:
include "mydefinitions.fbs"
-
+
This makes it easier to refer to types defined elsewhere. `include`
automatically ensures each file is parsed just once, even when referred to
more than once.
@@ -232,6 +232,16 @@ Current understood attributes:
When a new field is added to the schema is must use the next available ID.
- `deprecated` (on a field): do not generate accessors for this field
anymore, code should stop using this data.
+- `required` (on a non-scalar table field): this field must always be set.
+ 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.
- `original_order` (on a table): since elements in a table do not need
to be stored in any particular order, they are often optimized for
space by sorting them to size. This attribute stops that from happening.