File: IntermediateRepresentation.md

package info (click to toggle)
flatbuffers 2.0.8%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,308 kB
  • sloc: cpp: 44,808; python: 6,544; cs: 4,852; java: 4,389; ansic: 1,615; php: 1,455; xml: 973; javascript: 938; sh: 806; makefile: 35
file content (35 lines) | stat: -rw-r--r-- 1,548 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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.
- Filenames are relative to a "project root" denoted by "//" in the path. This
  may be specified in flatc with `--bfbs-filenames=$PROJECT_ROOT`, or it will be
  inferred to be the directory containing the first provided schema file.


## 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.