mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 01:08:04 +00:00
Intermediate Representation docs (#6685)
* Intermediate Representation docs * minor rewording * addressing comments * move IR to bottom Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
32
docs/source/IntermediateRepresentation.md
Normal file
32
docs/source/IntermediateRepresentation.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Flatbuffers Intermediate Representation {#intermediate_representation}
|
||||||
|
|
||||||
|
We use [reflection.fbs](https://github.com/google/flatbuffers/blob/master/reflection/reflection.fbs)
|
||||||
|
as our intermediate representation. `flatc` parses `.fbs` files, checks them for
|
||||||
|
errors and stores the resulting data in this IR, outputting `.bfbs` files.
|
||||||
|
Since this IR is a Flatbuffer, you can load and use it at runtime for runtime
|
||||||
|
reflection purposes.
|
||||||
|
|
||||||
|
There are some quirks:
|
||||||
|
- Tables and Structs are serialized as `Object`s.
|
||||||
|
- Unions and Enums are serialized as `Enum`s.
|
||||||
|
- It is the responsibility of the code generator to check the `advanced_features`
|
||||||
|
field of `Schema`. These mark the presence of new, backwards incompatible,
|
||||||
|
schema features. Code generators must error if generating a schema with
|
||||||
|
unrecognized advanced features.
|
||||||
|
|
||||||
|
|
||||||
|
## Invocation
|
||||||
|
You can invoke it like so
|
||||||
|
```{.sh}
|
||||||
|
flatc -b --schema ${your_fbs_files}
|
||||||
|
```
|
||||||
|
This generates `.bfbs` (binary flatbuffer schema) files.
|
||||||
|
|
||||||
|
Some information is not included by default. See the `--bfbs-filenames` and
|
||||||
|
`--bfbs-comments` flags. These may be necessary for code-generators, so they can
|
||||||
|
add documentation and maybe name generated files (depending on the generator).
|
||||||
|
|
||||||
|
|
||||||
|
TODO(cneo): Flags to output bfbs as flexbuffers or json.
|
||||||
|
|
||||||
|
TODO(cneo): Tutorial for building a flatc plugin.
|
||||||
@@ -637,10 +637,14 @@ optional type.
|
|||||||
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
|
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
|
||||||
that circumvents this "not writing defaults" behavior you can then use
|
that circumvents this "not writing defaults" behavior you can then use
|
||||||
`IsFieldPresent` to query presence.
|
`IsFieldPresent` to query presence.
|
||||||
|
/
|
||||||
Another option that works in all languages is to wrap a scalar field in a
|
Another option that works in all languages is to wrap a scalar field in a
|
||||||
struct. This way it will return null if it is not present. This will be slightly
|
struct. This way it will return null if it is not present. This will be slightly
|
||||||
less ergonomic but structs don't take up any more space than the scalar they
|
less ergonomic but structs don't take up any more space than the scalar they
|
||||||
represent.
|
represent.
|
||||||
|
|
||||||
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
||||||
|
|
||||||
|
## Writing your own code generator.
|
||||||
|
|
||||||
|
See [our intermediate representation](@ref intermediate_representation).
|
||||||
|
|||||||
@@ -768,6 +768,7 @@ INPUT = "FlatBuffers.md" \
|
|||||||
"WhitePaper.md" \
|
"WhitePaper.md" \
|
||||||
"FlexBuffers.md" \
|
"FlexBuffers.md" \
|
||||||
"Internals.md" \
|
"Internals.md" \
|
||||||
|
"IntermediateRepresentation.md" \
|
||||||
"Grammar.md" \
|
"Grammar.md" \
|
||||||
"../../CONTRIBUTING.md" \
|
"../../CONTRIBUTING.md" \
|
||||||
"Tutorial.md" \
|
"Tutorial.md" \
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
title="FlatBuffers white paper"/>
|
title="FlatBuffers white paper"/>
|
||||||
<tab type="user" url="@ref flatbuffers_internals"
|
<tab type="user" url="@ref flatbuffers_internals"
|
||||||
title="FlatBuffers internals"/>
|
title="FlatBuffers internals"/>
|
||||||
|
<tab type="user" url="@ref intermediate_representation"
|
||||||
|
title="Intermediate Representation"/>
|
||||||
<tab type="user" url="@ref flatbuffers_grammar"
|
<tab type="user" url="@ref flatbuffers_grammar"
|
||||||
title="Grammar of the schema language"/>
|
title="Grammar of the schema language"/>
|
||||||
<tab type="usergroup" url="" title="API Reference">
|
<tab type="usergroup" url="" title="API Reference">
|
||||||
|
|||||||
Reference in New Issue
Block a user