• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Using the schema compiler    {#flatbuffers_guide_using_schema_compiler}
2=========================
3
4Usage:
5
6    flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] FILES...
7          [ -- FILES...]
8
9The files are read and parsed in order, and can contain either schemas
10or data (see below). Data files are processed according to the definitions of
11the most recent schema specified.
12
13`--` indicates that the following files are binary files in
14FlatBuffer format conforming to the schema indicated before it.
15
16Depending on the flags passed, additional files may
17be generated for each file processed:
18
19For any schema input files, one or more generators can be specified:
20
21-   `--cpp`, `-c` : Generate a C++ header for all definitions in this file (as
22    `filename_generated.h`).
23
24-   `--java`, `-j` : Generate Java code.
25
26-   `--kotlin`, `-k` : Generate Kotlin code.
27
28-   `--csharp`, `-n` : Generate C# code.
29
30-   `--go`, `-g` : Generate Go code.
31
32-   `--python`, `-p`: Generate Python code.
33
34-   `--js`, `-s`: Generate JavaScript code.
35
36-   `--ts`: Generate TypeScript code.
37
38-   `--php`: Generate PHP code.
39
40-   `--grpc`: Generate RPC stub code for GRPC.
41
42-   `--dart`: Generate Dart code.
43
44-   `--lua`: Generate Lua code.
45
46-   `--lobster`: Generate Lobster code.
47
48-   `--rust`, `-r` : Generate Rust code.
49
50-   `--swift`: Generate Swift code.
51
52For any data input files:
53
54-   `--binary`, `-b` : If data is contained in this file, generate a
55    `filename.bin` containing the binary flatbuffer (or a different extension
56    if one is specified in the schema).
57
58-   `--json`, `-t` : If data is contained in this file, generate a
59    `filename.json` representing the data in the flatbuffer.
60
61Additional options:
62
63-   `-o PATH` : Output all generated files to PATH (either absolute, or
64    relative to the current directory). If omitted, PATH will be the
65    current directory. PATH should end in your systems path separator,
66    e.g. `/` or `\`.
67
68-   `-I PATH` : when encountering `include` statements, attempt to load the
69    files from this path. Paths will be tried in the order given, and if all
70    fail (or none are specified) it will try to load relative to the path of
71    the schema file being parsed.
72
73-   `-M` : Print make rules for generated files.
74
75-   `--strict-json` : Require & generate strict JSON (field names are enclosed
76    in quotes, no trailing commas in tables/vectors). By default, no quotes are
77    required/generated, and trailing commas are allowed.
78
79-   `--allow-non-utf8` : Pass non-UTF-8 input through parser and emit nonstandard
80    \x escapes in JSON. (Default is to raise parse error on non-UTF-8 input.)
81
82-  `--natural-utf8` : Output strings with UTF-8 as human-readable strings.
83     By default, UTF-8 characters are printed as \uXXXX escapes."
84
85-   `--defaults-json` : Output fields whose value is equal to the default value
86    when writing JSON text.
87
88-   `--no-prefix` : Don't prefix enum values in generated C++ by their enum
89    type.
90
91-   `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
92    generated C++. This also implies `--no-prefix`.
93
94-   `--gen-includes` : (deprecated), this is the default behavior.
95                       If the original behavior is required (no include
96	                   statements) use `--no-includes.`
97
98-   `--no-includes` : Don't generate include statements for included schemas the
99    generated file depends on (C++ / Python).
100
101-   `--gen-mutable` : Generate additional non-const accessors for mutating
102    FlatBuffers in-place.
103
104-   `--gen-onefile` : Generate single output file for C# and Go.
105
106-   `--gen-name-strings` : Generate type name functions for C++.
107
108-   `--gen-object-api` : Generate an additional object-based API. This API is
109    more convenient for object construction and mutation than the base API,
110    at the cost of efficiency (object allocation). Recommended only to be used
111    if other options are insufficient.
112
113-   `--gen-compare`  :  Generate operator== for object-based API types.
114
115-   `--gen-nullable` : Add Clang _Nullable for C++ pointer. or @Nullable for Java.
116
117-   `--gen-generated` : Add @Generated annotation for Java.
118
119-   `--gen-all` : Generate not just code for the current schema files, but
120    for all files it includes as well. If the language uses a single file for
121    output (by default the case for C++ and JS), all code will end up in
122    this one file.
123
124-   `--cpp-include` : Adds an #include in generated file
125
126-   `--cpp-ptr-type T` : Set object API pointer type (default std::unique_ptr)
127
128-   `--cpp-str-type T` : Set object API string type (default std::string)
129    T::c_str(), T::length() and T::empty() must be supported.
130    The custom type also needs to be constructible from std::string (see the
131	--cpp-str-flex-ctor option to change this behavior).
132
133-   `--cpp-str-flex-ctor` : Don't construct custom string types by passing
134    std::string from Flatbuffers, but (char* + length). This allows efficient
135	construction of custom string types, including zero-copy construction.
136
137-   `--cpp-std CPP_STD` : Generate a C++ code using features of selected C++ standard.
138     Supported `CPP_STD` values:
139    * `c++0x` - generate code compatible with old compilers (VS2010).
140    * `c++11` - use C++11 code generator (default);
141
142-   `--object-prefix` : Customise class prefix for C++ object-based API.
143
144-   `--object-suffix` : Customise class suffix for C++ object-based API.
145
146-   `--no-js-exports` : Removes Node.js style export lines (useful for JS)
147
148-   `--goog-js-export` :  Uses goog.exportsSymbol and goog.exportsProperty
149    instead of Node.js style exporting.  Needed for compatibility with the
150    Google closure compiler (useful for JS).
151
152-   `--es6-js-export` : Generates ECMAScript v6 style export definitions
153    instead of Node.js style exporting. Useful when integrating flatbuffers
154    with modern Javascript projects.
155
156-   `--go-namespace` : Generate the overrided namespace in Golang.
157
158-   `--go-import` : Generate the overrided import for flatbuffers in Golang.
159     (default is "github.com/google/flatbuffers/go").
160
161-   `--raw-binary` : Allow binaries without a file_indentifier to be read.
162    This may crash flatc given a mismatched schema.
163
164-   `--size-prefixed` : Input binaries are size prefixed buffers.
165
166-   `--proto`: Expect input files to be .proto files (protocol buffers).
167    Output the corresponding .fbs file.
168    Currently supports: `package`, `message`, `enum`, nested declarations,
169    `import` (use `-I` for paths), `extend`, `oneof`, `group`.
170    Does not support, but will skip without error: `option`, `service`,
171    `extensions`, and most everything else.
172
173-   `--oneof-union` : Translate .proto oneofs to flatbuffer unions.
174
175-   `--grpc` : Generate GRPC interfaces for the specified languages.
176
177-   `--schema`: Serialize schemas instead of JSON (use with -b). This will
178    output a binary version of the specified schema that itself corresponds
179    to the reflection/reflection.fbs schema. Loading this binary file is the
180    basis for reflection functionality.
181
182-   `--bfbs-comments`: Add doc comments to the binary schema files.
183
184-   `--conform FILE` : Specify a schema the following schemas should be
185    an evolution of. Gives errors if not. Useful to check if schema
186    modifications don't break schema evolution rules.
187
188-   `--conform-includes PATH` : Include path for the schema given with
189    `--conform PATH`.
190
191-   `--filename-suffix SUFFIX` : The suffix appended to the generated
192    file names. Default is '_generated'.
193
194-   `--filename-ext EXTENSION` : The extension appended to the generated
195    file names. Default is language-specific (e.g. "h" for C++). This
196    should not be used when multiple languages are specified.
197
198-   `--include-prefix PATH` : Prefix this path to any generated include
199    statements.
200
201-   `--keep-prefix` : Keep original prefix of schema include statement.
202
203-   `--no-fb-impor` : Don't include flatbuffers import statement for TypeScript.
204
205-   `--no-ts-reexpor` : Don't re-export imported dependencies for TypeScript.
206
207-   `--short-name` : Use short function names for JS and TypeScript.
208
209-   `--reflect-types` : Add minimal type reflection to code generation.
210
211-   `--reflect-names` : Add minimal type/name reflection.
212
213-   `--root-type T` : Select or override the default root_type.
214
215-   `--force-defaults` : Emit default values in binary output from JSON.
216
217-   `--force-empty` : When serializing from object API representation, force
218     strings and vectors to empty rather than null.
219
220-   `--force-empty-vectors` : When serializing from object API representation, force
221     vectors to empty rather than null.
222
223NOTE: short-form options for generators are deprecated, use the long form
224whenever possible.
225