1FLATC(1) User Commands FLATC(1)
2
3
4
6 flatc – FlatBuffers compiler
7
9 flatc [OPTION]... FILE... [-- FILE...]
10
12 FILEs may be schemas (must end in .fbs), binary schemas (must end in
13 .bfbs), or JSON files (conforming to preceding schema). FILEs after
14 the -- must be binary flatbuffer format files.
15
16 Output files are named using the base file name of the input, and writ‐
17 ten to the current directory or the path given by -o.
18
19 --binary, -b
20 Generate wire format binaries for any data definitions.
21
22 --json, -t
23 Generate text output for any data definitions.
24
25 --cpp, -c
26 Generate C++ headers for tables/structs.
27
28 --go, -g
29 Generate Go files for tables/structs.
30
31 --java, -j
32 Generate Java classes for tables/structs.
33
34 --dart, -d
35 Generate Dart classes for tables/structs.
36
37 --ts, -T
38 Generate TypeScript code for tables/structs.
39
40 --csharp, -n
41 Generate C# classes for tables/structs.
42
43 --python, -p
44 Generate Python files for tables/structs.
45
46 --lobster
47 Generate Lobster files for tables/structs.
48
49 --lua, -l
50 Generate Lua files for tables/structs.
51
52 --rust, -r
53 Generate Rust files for tables/structs.
54
55 --php Generate PHP files for tables/structs.
56
57 --kotlin
58 Generate Kotlin classes for tables/structs.
59
60 --jsonschema
61 Generate Json schema.
62
63 --swift
64 Generate Swift files for tables/structs.
65
66 -o PATH
67 Prefix PATH to all generated files.
68
69 -I PATH
70 Search for includes in the specified path.
71
72 -M Print make(1) rules for generated files.
73
74 --version
75 Print the version number of flatc and exit.
76
77 --strict-json
78 Strict JSON: field names must be / will be quoted, no trailing
79 commas in tables/vectors.
80
81 --allow-non-utf8
82 Pass non-UTF-8 input through parser and emit nonstandard \x es‐
83 capes in JSON. (Default is to raise parse error on non-UTF-8
84 input.)
85
86 --natural-utf8
87 Output strings with UTF-8 as human-readable strings. By de‐
88 fault, UTF-8 characters are printed as \uXXXX escapes.
89
90 --defaults-json
91 Output fields whose value is the default when writing JSON
92
93 --unknown-json
94 Allow fields in JSON that are not defined in the schema. These
95 fields will be discared when generating binaries.
96
97 --no-prefix
98 Don’t prefix enum values with the enum type in C++.
99
100 --scoped-enums
101 Use C++11 style scoped and strongly typed enums. Also implies
102 --no-prefix.
103
104 --gen-includes
105 (deprecated), this is the default behavior. If the original be‐
106 havior is required (no include statements) use --no-includes.
107
108 --no-includes
109 Don’t generate include statements for included schemas the gen‐
110 erated file depends on (C++ / Python).
111
112 --gen-mutable
113 Generate accessors that can mutate buffers in-place.
114
115 --gen-onefile
116 Generate single output file for C# and Go.
117
118 --gen-name-strings
119 Generate type name functions for C++ and Rust.
120
121 --gen-object-api
122 Generate an additional object-based API.
123
124 --gen-compare
125 Generate operator== for object-based API types.
126
127 --gen-nullable
128 Add Clang _Nullable for C++ pointer. or @Nullable for Java
129
130 --java-checkerframework
131 Add @Pure for Java.
132
133 --gen-generated
134 Add @Generated annotation for Java
135
136 --gen-jvmstatic
137 Add @JvmStatic annotation for Kotlin methods in companion object
138 for interop from Java to Kotlin.
139
140 --gen-all
141 Generate not just code for the current schema files, but for all
142 files it includes as well. If the language uses a single file
143 for output (by default the case for C++ and JS), all code will
144 end up in this one file.
145
146 --cpp-include
147 Adds an #include in generated file.
148
149 --cpp-ptr-type T
150 Set object API pointer type (default std::unique_ptr).
151
152 --cpp-str-type T
153 Set object API string type (default std::string). T::c_str(),
154 T::length(), and T::empty() must be supported. The custom type
155 also needs to be constructible from std::string (see the
156 --cpp-str-flex-ctor option to change this behavior).
157
158 --cpp-str-flex-ctor
159 Don’t construct custom string types by passing std::string from
160 Flatbuffers, but (char* + length).
161
162 --cpp-std CPP_STD
163 Generate a C++ code using features of selected C++ standard.
164
165 Supported CPP_STD values:
166
167 • c++0x – generate code compatible with old compilers;
168
169 • c++11 – use C++11 code generator (default);
170
171 • c++17 – use C++17 features in generated code (experimental).
172
173 --cpp-static-reflection
174 When using C++17, generate extra code to provide compile-time
175 (static) reflection of Flatbuffers types. Requires --cpp-std to
176 be “c++17” or higher.
177
178 --object-prefix
179 Customise class prefix for C++ object-based API.
180
181 --object-suffix
182 Customise class suffix for C++ object-based API. Default value
183 is “T”.
184
185 --go-namespace
186 Generate the overriding namespace in Golang.
187
188 --go-import
189 Generate the overriding import for flatbuffers in Golang (de‐
190 fault is “github.com/google/flatbuffers/go”).
191
192 --raw-binary
193 Allow binaries without file_identifier to be read. This may
194 crash flatc given a mismatched schema.
195
196 --size-prefixed
197 Input binaries are size prefixed buffers.
198
199 --proto
200 Input is a .proto, translate to .fbs.
201
202 --proto-namespace-suffix SUFFIX
203 Add this namespace to any flatbuffers generated from protobufs.
204
205 --oneof-union
206 Translate .proto oneofs to flatbuffer unions.
207
208 --grpc Generate GRPC interfaces for the specified languages.
209
210 --schema
211 Serialize schemas instead of JSON (use with -b).
212
213 --bfbs-comments
214 Add doc comments to the binary schema files.
215
216 --bfbs-builtins
217 Add builtin attributes to the binary schema files.
218
219 --bfbs-gen-embed
220 Generate code to embed the bfbs schema to the source.
221
222 --conform FILE
223 Specify a schema the following schemas should be an evolution
224 of. Gives errors if not.
225
226 --conform-includes
227 Include path for the schema given with --conform PATH
228
229 --filename-suffix
230 The suffix appended to the generated file names. Default is
231 ‘_generated’.
232
233 --filename-ext
234 The extension appended to the generated file names. Default is
235 language-specific (e.g., ‘.h’ for C++)
236
237 --include-prefix PATH
238 Prefix this path to any generated include statements.
239
240 --keep-prefix
241 Keep original prefix of schema include statement.
242
243 --reflect-types
244 Add minimal type reflection to code generation.
245
246 --reflect-names
247 Add minimal type/name reflection.
248
249 --root-type T
250 Select or override the default root_type
251
252 --require-explicit-ids
253 When parsing schemas, require explicit ids (id: x).
254
255 --force-defaults
256 Emit default values in binary output from JSON
257
258 --force-empty
259 When serializing from object API representation, force strings
260 and vectors to empty rather than null.
261
262 --force-empty-vectors
263 When serializing from object API representation, force vectors
264 to empty rather than null.
265
266 --flexbuffers
267 Used with “binary” and “json” options, it generates data using
268 schema-less FlexBuffers.
269
270 --no-warnings
271 Inhibit all warning messages.
272
274 flatc -c -b schema1.fbs schema2.fbs data.json
275
277 Official documentation ⟨https://google.github.io/flatbuffers⟩
278
279
280
281 June 2022 FLATC(1)