1FLATC(1)                         User Commands                        FLATC(1)
2
3
4

NAME

6       flatc – FlatBuffers compiler
7

SYNOPSIS

9       flatc [OPTION]... FILE... [-- BINARY_FILE...]
10

OPTIONS

12       FILEs  may  be  schemas (must end in .fbs), binary schemas (must end in
13       .bfbs), or JSON files (conforming to preceding  schema).   BINARY_FILEs
14       after 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       --nim  Generate Nim files for tables/structs.
67
68       -o PATH
69              Prefix PATH to all generated files.
70
71       -I PATH
72              Search for includes in the specified path.
73
74       -M     Print make(1) rules for generated files.
75
76       --version
77              Print the version number of flatc and exit.
78
79       --strict-json
80              Strict JSON: field names must be / will be quoted,  no  trailing
81              commas in tables/vectors.
82
83       --allow-non-utf8
84              Pass  non-UTF-8 input through parser and emit nonstandard \x es‐
85              capes in JSON.  (Default is to raise parse  error  on  non-UTF-8
86              input.)
87
88       --natural-utf8
89              Output  strings  with  UTF-8  as human-readable strings.  By de‐
90              fault, UTF-8 characters are printed as \uXXXX escapes.
91
92       --defaults-json
93              Output fields whose value is the default when writing JSON.
94
95       --unknown-json
96              Allow fields in JSON that are not defined in the schema.   These
97              fields will be discared when generating binaries.
98
99       --no-prefix
100              Don’t prefix enum values with the enum type in C++.
101
102       --scoped-enums
103              Use  C++11  style scoped and strongly typed enums.  Also implies
104              --no-prefix.
105
106       --no-emit-min-max-enum-values
107              Disable generation of MIN and MAX enumerated values  for  scoped
108              enums and prefixed enums.
109
110       --gen-includes
111              (deprecated), this is the default behavior.  If the original be‐
112              havior is required (no include statements) use --no-includes.
113
114       --no-includes
115              Don’t generate include statements for included schemas the  gen‐
116              erated file depends on (C++ / Python).
117
118       --gen-mutable
119              Generate accessors that can mutate buffers in-place.
120
121       --gen-onefile
122              Generate single output file for C# and Go.
123
124       --gen-name-strings
125              Generate type name functions for C++ and Rust.
126
127       --gen-object-api
128              Generate an additional object-based API.
129
130       --gen-compare
131              Generate operator== for object-based API types.
132
133       --gen-nullable
134              Add Clang _Nullable for C++ pointer.  or @Nullable for Java
135
136       --java-package-prefix
137              Add a prefix to the generated package name for Java.
138
139       --java-checkerframework
140              Add @Pure for Java.
141
142       --gen-generated
143              Add @Generated annotation for Java
144
145       --gen-jvmstatic
146              Add @JvmStatic annotation for Kotlin methods in companion object
147              for interop from Java to Kotlin.
148
149       --gen-all
150              Generate not just code for the current schema files, but for all
151              files  it  includes as well.  If the language uses a single file
152              for output (by default the case for C++ and JS), all  code  will
153              end up in this one file.
154
155       --gen-json-emit
156              Generates encoding code which emits Flatbuffers into JSON.
157
158       --cpp-include
159              Adds an #include in generated file.
160
161       --cpp-ptr-type T
162              Set object API pointer type (default std::unique_ptr).
163
164       --cpp-str-type T
165              Set  object  API string type (default std::string).  T::c_str(),
166              T::length(), and T::empty() must be supported.  The custom  type
167              also  needs  to  be  constructible  from  std::string  (see  the
168              --cpp-str-flex-ctor option to change this behavior).
169
170       --cpp-str-flex-ctor
171              Don’t construct custom string types by passing std::string  from
172              Flatbuffers, but (char* + length).
173
174       --cpp-std CPP_STD
175              Generate a C++ code using features of selected C++ standard.
176
177              Supported CPP_STD values:
178
179c++0x – generate code compatible with old compilers;
180
181c++11 – use C++11 code generator (default);
182
183c++17 – use C++17 features in generated code (experimental).
184
185       --cpp-static-reflection
186              When  using  C++17,  generate extra code to provide compile-time
187              (static) reflection of Flatbuffers types.  Requires --cpp-std to
188              be “c++17” or higher.
189
190       --object-prefix
191              Customise class prefix for C++ object-based API.
192
193       --object-suffix
194              Customise  class suffix for C++ object-based API.  Default value
195              is “T”.
196
197       --go-namespace
198              Generate the overriding namespace in Golang.
199
200       --go-import
201              Generate the overriding import for flatbuffers  in  Golang  (de‐
202              fault is “github.com/google/flatbuffers/go”).
203
204       --go-module-name
205              Prefix  local  import paths of generated go code with the module
206              name.
207
208       --raw-binary
209              Allow binaries without file_identifier to  be  read.   This  may
210              crash flatc given a mismatched schema.
211
212       --size-prefixed
213              Input binaries are size prefixed buffers.
214
215       --proto-namespace-suffix SUFFIX
216              Add this namespace to any flatbuffers generated from protobufs.
217
218       --oneof-union
219              Translate .proto oneofs to flatbuffer unions.
220
221       --keep-proto-id
222              Keep protobuf field ids in generated fbs file.
223
224       --proto-id-gap
225              Action  that  should  be  taken  when a gap between protobuf ids
226              found.
227
228              Supported values:
229
230nop – do not care about gap
231
232warn – A warning message will be shown about the gap in proto‐
233                buf ids (default)
234
235error  – An error message will be shown and the fbs generation
236                will be interrupted.
237
238       --grpc Generate GRPC interfaces for the specified languages.
239
240       --schema
241              Serialize schemas instead of JSON (use with -b).
242
243       --bfbs-comments
244              Add doc comments to the binary schema files.
245
246       --bfbs-builtins
247              Add builtin attributes to the binary schema files.
248
249       --bfbs-gen-embed
250              Generate code to embed the bfbs schema to the source.
251
252       --conform FILE
253              Specify a schema the following schemas should  be  an  evolution
254              of.  Gives errors if not.
255
256       --conform-includes
257              Include path for the schema given with --conform PATH.
258
259       --filename-suffix
260              The  suffix  appended  to  the generated file names.  Default is
261              _generated’.
262
263       --filename-ext
264              The extension appended to the generated file names.  Default  is
265              language-specific (e.g., ‘.h’ for C++)
266
267       --include-prefix PATH
268              Prefix this path to any generated include statements.
269
270       --keep-prefix
271              Keep original prefix of schema include statement.
272
273       --reflect-types
274              Add minimal type reflection to code generation.
275
276       --reflect-names
277              Add minimal type/name reflection.
278
279       --rust-serialize
280              Implement serde::Serialize on generated Rust types.
281
282       --rust-module-root-file
283              Generate rust code in individual files with a module root file.
284
285       --root-type T
286              Select or override the default root_type.
287
288       --require-explicit-ids
289              When parsing schemas, require explicit ids (id: x).
290
291       --force-defaults
292              Emit default values in binary output from JSON.
293
294       --force-empty
295              When  serializing  from object API representation, force strings
296              and vectors to empty rather than null.
297
298       --force-empty-vectors
299              When serializing from object API representation,  force  vectors
300              to empty rather than null.
301
302       --flexbuffers
303              Used  with  “binary” and “json” options, it generates data using
304              schema-less FlexBuffers.
305
306       --no-warnings
307              Inhibit all warning messages.
308
309       --warnings-as-errors
310              Treat all warnings as errors.
311
312       --cs-global-alias
313              Prepend “global::” to all  user  generated  csharp  classes  and
314              structs.
315
316       --cs-gen-json-serializer
317              Allows  (de)serialization  of JSON text in the Object API.  (re‐
318              quires --gen-object-api).
319
320       --json-nested-bytes
321              Allow a nested_flatbuffer field to be  parsed  as  a  vector  of
322              bytes  in JSON, which is unsafe unless checked by a verifier af‐
323              terwards.
324
325       --ts-flat-files
326              Generate a  single  typescript  file  per  .fbs  file.   Implies
327              --ts-entry-points.
328
329       --ts-entry-points
330              Generate   entry   point   typescript  per  namespace.   Implies
331              --gen-all.
332
333       --annotate-sparse-vectors SCHEMA
334              Don’t annotate every vector element.
335
336       --annotate SCHEMA
337              Annotate the provided  BINARY_FILE  with  the  specified  SCHEMA
338              file.
339
340       --no-leak-private-annotation
341              Prevents  multiple type of annotations within a Fbs SCHEMA file.
342              Currently this is required to generate private types in Rust.
343
344       --python-no-type-prefix-suffix
345              Skip emission of Python functions that are prefixed  with  type‐
346              names
347
348       --python-typing
349              Generate Python type annotations
350
351       --file-names-only
352              Print out generated file names without writing to the files
353

EXAMPLES

355       flatc -c -b schema1.fbs schema2.fbs data.json
356

SEE ALSO

358       Official documentation ⟨https://google.github.io/flatbuffers
359
360
361
362                                 October 2022                         FLATC(1)
Impressum