450b421
.TH FLATC "1" "October 2022" "" "User Commands"
8251aff
.SH NAME
e7399ea
.B flatc
e7399ea
\(en FlatBuffers compiler
8251aff
.SH SYNOPSIS
e7399ea
.B flatc
e7399ea
.RI [ OPTION ]...\:
e7399ea
.IR FILE ...\:
450b421
.RI [\-\-\  BINARY_FILE ...]
8251aff
.SH OPTIONS
e7399ea
.IR FILE s
e7399ea
may be schemas (must end in
e7399ea
.BR .fbs ),
e7399ea
binary schemas (must end in
e7399ea
.BR .bfbs ),
e7399ea
or JSON files (conforming to preceding schema).
450b421
.IR BINARY_FILE s
e7399ea
after the
e7399ea
.B \-\-
e7399ea
must be binary flatbuffer format files.
e7399ea
.P
e7399ea
Output files are named using the base file name of the input,
e7399ea
and written to the current directory or the path given by
e7399ea
.BR \-o .
e7399ea
.TP
e7399ea
.B \-\-binary\fR, \fB\-b
e7399ea
Generate wire format binaries for any data definitions.
e7399ea
.TP
e7399ea
.B \-\-json\fR, \fB\-t
e7399ea
Generate text output for any data definitions.
e7399ea
.TP
e7399ea
.B \-\-cpp\fR, \fB\-c
e7399ea
Generate C++ headers for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-go\fR, \fB\-g
e7399ea
Generate Go files for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-java\fR, \fB\-j
e7399ea
Generate Java classes for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-dart\fR, \fB\-d
e7399ea
Generate Dart classes for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-ts\fR, \fB\-T
e7399ea
Generate TypeScript code for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-csharp\fR, \fB\-n
e7399ea
Generate C# classes for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-python\fR, \fB\-p
e7399ea
Generate Python files for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-lobster
e7399ea
Generate Lobster files for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-lua\fR, \fB\-l
e7399ea
Generate Lua files for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-rust\fR, \fB\-r
e7399ea
Generate Rust files for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-php
e7399ea
Generate PHP files for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-kotlin
e7399ea
Generate Kotlin classes for tables/structs.
e7399ea
.TP
e7399ea
.B \-\-jsonschema
e7399ea
Generate Json schema.
e7399ea
.TP
e7399ea
.B \-\-swift
e7399ea
Generate Swift files for tables/structs.
e7399ea
.TP
450b421
.B \-\-nim
450b421
Generate Nim files for tables/structs.
450b421
.TP
e7399ea
.B \-o\ \fIPATH
e7399ea
Prefix
e7399ea
.I PATH
e7399ea
to all generated files.
e7399ea
.TP
e7399ea
.B \-I\ \fIPATH
e7399ea
Search for includes in the specified path.
e7399ea
.TP
e7399ea
.B \-M
e7399ea
Print
e7399ea
.BR make (1)
e7399ea
rules for generated files.
e7399ea
.TP
e7399ea
.B \-\-version
e7399ea
Print the version number of
e7399ea
.B flatc
e7399ea
and exit.
e7399ea
.TP
e7399ea
.B \-\-strict\-json
e7399ea
Strict JSON: field names must be\ / will be quoted,
e7399ea
no trailing commas in tables/vectors.
e7399ea
.TP
e7399ea
.B \-\-allow-non-utf8
e7399ea
Pass non-UTF-8 input through parser and emit nonstandard
e7399ea
.BI \\\\\\\\ x
e7399ea
escapes in JSON.
e7399ea
(Default is to raise parse error on non-UTF-8 input.)
e7399ea
.TP
e7399ea
.B \-\-natural\-utf8
e7399ea
Output strings with UTF-8 as human-readable strings.
e7399ea
By default, UTF-8 characters are printed as
e7399ea
.BI \\\\\\\\u XXXX
e7399ea
escapes.
e7399ea
.TP
e7399ea
.B \-\-defaults\-json
450b421
Output fields whose value is the default when writing JSON.
e7399ea
.TP
e7399ea
.B \-\-unknown\-json
e7399ea
Allow fields in JSON that are not defined in the schema.
e7399ea
These fields will be discared when generating binaries.
e7399ea
.TP
e7399ea
.B \-\-no\-prefix
e7399ea
Don\(cqt prefix enum values with the enum type in C++.
e7399ea
.TP
e7399ea
.B \-\-scoped\-enums
e7399ea
Use C++11 style scoped and strongly typed enums.
e7399ea
Also implies
e7399ea
.BR \-\-no\-prefix .
e7399ea
.TP
ed9000d
.B \-\-no\-emit\-min\-max\-enum\-values
ed9000d
Disable generation of
ed9000d
.B MIN
ed9000d
and
ed9000d
.B MAX
ed9000d
enumerated values for scoped enums and prefixed enums.
ed9000d
.TP
e7399ea
.B \-\-gen\-includes
e7399ea
.RI ( deprecated ),
e7399ea
this is the default behavior.
e7399ea
If the original behavior is required (no include statements) use
e7399ea
.BR \-\-no\-includes .
e7399ea
.TP
e7399ea
.B \-\-no\-includes
e7399ea
Don\(cqt generate include statements for included
e7399ea
schemas the generated file depends on (C++\ / Python).
e7399ea
.TP
e7399ea
.B \-\-gen\-mutable
e7399ea
Generate accessors that can mutate buffers in-place.
e7399ea
.TP
e7399ea
.B \-\-gen\-onefile
e7399ea
Generate single output file for C# and Go.
e7399ea
.TP
e7399ea
.B \-\-gen\-name\-strings
e7399ea
Generate type name functions for C++ and Rust.
e7399ea
.TP
e7399ea
.B \-\-gen\-object\-api
e7399ea
Generate an additional object-based API.
e7399ea
.TP
e7399ea
.B \-\-gen\-compare
e7399ea
Generate
e7399ea
.B operator==
e7399ea
for object-based API types.
e7399ea
.TP
e7399ea
.B \-\-gen\-nullable
e7399ea
Add Clang
e7399ea
.B _Nullable
450b421
for C++ pointer.
450b421
or
e7399ea
.B @Nullable
e7399ea
for Java
e7399ea
.TP
b1bfc9b
.B \-\-java\-package\-prefix
b1bfc9b
Add a prefix to the generated package name for Java.
b1bfc9b
.TP
e7399ea
.B \-\-java\-checkerframework
e7399ea
Add
e7399ea
.B @Pure
e7399ea
for Java.
e7399ea
.TP
e7399ea
.B \-\-gen\-generated
e7399ea
Add
e7399ea
.B @Generated
e7399ea
annotation for Java
e7399ea
.TP
e7399ea
.B \-\-gen\-jvmstatic
e7399ea
Add
e7399ea
.B @JvmStatic
e7399ea
annotation for Kotlin methods
e7399ea
in companion object for interop from Java to Kotlin.
e7399ea
.TP
e7399ea
.B \-\-gen\-all
e7399ea
Generate not just code for the current schema files,
e7399ea
but for all files it includes as well.
e7399ea
If the language uses a single file for output (by default
e7399ea
the case for C++ and JS), all code will end up in this one file.
e7399ea
.TP
450b421
.B \-\-gen\-json\-emit
450b421
Generates encoding code which emits Flatbuffers into JSON.
450b421
.TP
e7399ea
.B \-\-cpp\-include
e7399ea
Adds an
e7399ea
.B #include
e7399ea
in generated file.
e7399ea
.TP
e7399ea
.B \-\-cpp\-ptr\-type\ \fIT
e7399ea
Set object API pointer type
e7399ea
(default
e7399ea
.BR std::unique_ptr ).
e7399ea
.TP
e7399ea
.B \-\-cpp\-str\-type\ \fIT
e7399ea
Set object API string type
e7399ea
(default
e7399ea
.BR std::string ).
e7399ea
.BR \fIT\fB::c_str() ,
e7399ea
.BR \fIT\fB::length() ,
e7399ea
and
e7399ea
.BR \fIT\fB::empty()
e7399ea
must be supported.
e7399ea
The custom type also needs to be constructible from
e7399ea
.B std::string
e7399ea
(see the
e7399ea
.B \-\-cpp\-str\-flex\-ctor
e7399ea
option to change this behavior).
e7399ea
.TP
e7399ea
.B \-\-cpp-str-flex-ctor
e7399ea
Don\(cqt construct custom string types by passing
e7399ea
.B std::string
e7399ea
from Flatbuffers, but (\fBchar*\fR\ + \fIlength\fR).
e7399ea
.TP
e7399ea
.B \-\-cpp-std\ \fICPP_STD
e7399ea
Generate a C++ code using features of selected C++ standard.
e7399ea
.IP
e7399ea
.B Supported
e7399ea
.I CPP_STD
e7399ea
.B values:
e7399ea
.RS +7n
e7399ea
.IP \(bu 2n
e7399ea
.B c++0x
e7399ea
\(en generate code compatible with old compilers;
e7399ea
.IP \(bu 2n
e7399ea
.B c++11
e7399ea
\(en use C++11 code generator
e7399ea
.RI ( default );
e7399ea
.IP \(bu 2n
e7399ea
.B c++17
e7399ea
\(en use C++17 features in generated code
e7399ea
.RI ( experimental ).
e7399ea
.RE
e7399ea
.TP
e7399ea
.B \-\-cpp\-static\-reflection
e7399ea
When using C++17, generate extra code to provide compile-time
e7399ea
(static) reflection of Flatbuffers types.
e7399ea
Requires
e7399ea
.B \-\-cpp\-std
e7399ea
to be
e7399ea
.RB \(lq c++17 \(rq
e7399ea
or higher.
e7399ea
.TP
e7399ea
.B \-\-object\-prefix
e7399ea
Customise class prefix for C++ object-based API.
e7399ea
.TP
e7399ea
.B \-\-object\-suffix
e7399ea
Customise class suffix for C++ object-based API.
e7399ea
Default value is
e7399ea
.RB \(lq T \(rq.
e7399ea
.TP
e7399ea
.B \-\-go\-namespace
e7399ea
Generate the overriding namespace in Golang.
e7399ea
.TP
e7399ea
.B \-\-go\-import
e7399ea
Generate the overriding import for flatbuffers in Golang
e7399ea
(default is
e7399ea
.RB \(lq github.com/google/flatbuffers/go \(rq).
e7399ea
.TP
8f534ba
.B \-\-go\-module\-name
8f534ba
Prefix local import paths of generated go code with the module name.
8f534ba
.TP
e7399ea
.B \-\-raw\-binary
e7399ea
Allow binaries without
e7399ea
.B file_identifier
e7399ea
to be read.
e7399ea
This may crash
e7399ea
.B flatc
e7399ea
given a mismatched schema.
e7399ea
.TP
e7399ea
.B \-\-size\-prefixed
e7399ea
Input binaries are size prefixed buffers.
e7399ea
.TP
e7399ea
.B \-\-proto\-namespace\-suffix\ \fISUFFIX
e7399ea
Add this namespace to any flatbuffers generated from protobufs.
e7399ea
.TP
e7399ea
.B \-\-oneof\-union
e7399ea
Translate
e7399ea
.B .proto
e7399ea
oneofs to flatbuffer unions.
e7399ea
.TP
b1bfc9b
.B \-\-keep\-proto\-id
b1bfc9b
Keep protobuf field ids in generated fbs file.
b1bfc9b
.TP
b1bfc9b
.B \-\-proto\-id\-gap
b1bfc9b
Action that should be taken when a gap between protobuf ids found.
b1bfc9b
.IP
b1bfc9b
.B Supported values:
b1bfc9b
.RS +7n
b1bfc9b
.IP \(bu 2n
b1bfc9b
.B nop
b1bfc9b
\(en do not care about gap
b1bfc9b
.IP \(bu 2n
b1bfc9b
.B warn
b1bfc9b
\(en A warning message will be shown about the gap in protobuf ids
b1bfc9b
.RI ( default )
b1bfc9b
.IP \(bu 2n
b1bfc9b
.B error
b1bfc9b
\(en An error message will be shown and the fbs generation will be interrupted.
b1bfc9b
.RE
b1bfc9b
.TP
e7399ea
.B \-\-grpc
e7399ea
Generate GRPC interfaces for the specified languages.
e7399ea
.TP
e7399ea
.B \-\-schema
e7399ea
Serialize schemas instead of JSON (use with
e7399ea
.BR \-b ).
e7399ea
.TP
e7399ea
.B \-\-bfbs\-comments
e7399ea
Add doc comments to the binary schema files.
e7399ea
.TP
e7399ea
.B \-\-bfbs\-builtins
e7399ea
Add builtin attributes to the binary schema files.
e7399ea
.TP
e7399ea
.B \-\-bfbs\-gen\-embed
e7399ea
Generate code to embed the
e7399ea
.B bfbs
e7399ea
schema to the source.
e7399ea
.TP
e7399ea
.B \-\-conform\ \fIFILE
e7399ea
Specify a schema the following schemas should be an evolution of.
e7399ea
Gives errors if not.
e7399ea
.TP
e7399ea
.B \-\-conform\-includes
e7399ea
Include path for the schema given with
450b421
.BR \-\-conform\ \fIPATH .
e7399ea
.TP
e7399ea
.B \-\-filename\-suffix
e7399ea
The suffix appended to the generated file names.
e7399ea
Default is
e7399ea
.BR \(oq _generated \(cq.
e7399ea
.TP
e7399ea
.B \-\-filename\-ext
e7399ea
The extension appended to the generated file names.
e7399ea
Default is language-specific (e.g.,
e7399ea
.RB \(oq .h \(cq
e7399ea
for C++)
e7399ea
.TP
e7399ea
.B \-\-include\-prefix\ \fIPATH
e7399ea
Prefix this path to any generated include statements.
e7399ea
.TP
e7399ea
.B \-\-keep\-prefix
e7399ea
Keep original prefix of schema include statement.
e7399ea
.TP
e7399ea
.B \-\-reflect\-types
e7399ea
Add minimal type reflection to code generation.
e7399ea
.TP
e7399ea
.B \-\-reflect\-names
e7399ea
Add minimal type/name reflection.
e7399ea
.TP
450b421
.B \-\-rust\-serialize
450b421
Implement
450b421
.B serde::Serialize
450b421
on generated Rust types.
450b421
.TP
450b421
.B \-\-rust\-module\-root\-file
450b421
Generate rust code in individual files with a module root file.
450b421
.TP
e7399ea
.B \-\-root\-type\ \fIT
450b421
Select or override the default root_type.
e7399ea
.TP
e7399ea
.B \-\-require\-explicit\-ids
e7399ea
When parsing schemas, require explicit ids
e7399ea
.RB ( id:\ \fIx ).
e7399ea
.TP
e7399ea
.B \-\-force\-defaults
450b421
Emit default values in binary output from JSON.
e7399ea
.TP
e7399ea
.B \-\-force\-empty
e7399ea
When serializing from object API representation,
e7399ea
force strings and vectors to empty rather than null.
e7399ea
.TP
e7399ea
.B \-\-force\-empty\-vectors
e7399ea
When serializing from object API representation,
e7399ea
force vectors to empty rather than null.
e7399ea
.TP
e7399ea
.B \-\-flexbuffers
e7399ea
Used with
e7399ea
.RB \(lq binary \(rq
e7399ea
and
e7399ea
.RB \(lq json \(rq
e7399ea
options, it generates
e7399ea
data using schema-less FlexBuffers.
e7399ea
.TP
e7399ea
.B \-\-no\-warnings
e7399ea
Inhibit all warning messages.
450b421
.TP
450b421
.B \-\-warnings\-as-errors
450b421
Treat all warnings as errors.
450b421
.TP
450b421
.B \-\-cs\-global\-alias
450b421
Prepend
450b421
.RB \(lq global:: \(rq
450b421
to all user generated csharp classes and structs.
450b421
.TP
450b421
.B \-\-cs\-gen\-json\-serializer
450b421
Allows (de)serialization of JSON text in the Object API.
450b421
(requires
450b421
.BR \-\-gen\-object\-api ).
450b421
.TP
450b421
.B \-\-json\-nested\-bytes
450b421
Allow a
450b421
.B nested_flatbuffer
450b421
field to be parsed as a vector of bytes in JSON,
450b421
which is unsafe unless checked by a verifier afterwards.
450b421
.TP
450b421
.B \-\-ts\-flat\-files
ed9000d
Generate a single typescript file per
450b421
.B .fbs
450b421
file.
ed9000d
Implies
ed9000d
.BR \-\-ts\-entry\-points .
ed9000d
.TP
ed9000d
.B \-\-ts\-entry\-points
ed9000d
Generate entry point typescript per namespace.
ed9000d
Implies
ed9000d
.BR \-\-gen\-all .
450b421
.TP
b1bfc9b
.B \-\-annotate\-sparse\-vectors\ \fISCHEMA
b1bfc9b
Don\(cqt annotate every vector element.
b1bfc9b
.TP
450b421
.B \-\-annotate\ \fISCHEMA
450b421
Annotate the provided
450b421
.I BINARY_FILE
450b421
with the specified
450b421
.I SCHEMA
450b421
file.
450b421
.TP
450b421
.B \-\-no\-leak\-private\-annotation
450b421
Prevents multiple type of annotations within a Fbs
450b421
.I SCHEMA
450b421
file.
450b421
Currently this is required to generate private types in Rust.
f3f252b
.TP
f3f252b
.B \-\-python\-no\-type\-prefix\-suffix
f3f252b
Skip emission of Python functions that are prefixed with typenames
f3f252b
.TP
f3f252b
.B \-\-python\-typing
f3f252b
Generate Python type annotations
f3f252b
.TP
f3f252b
.B \-\-file\-names\-only
f3f252b
Print out generated file names without writing to the files
e7399ea
.SH EXAMPLES
e7399ea
.EX
e7399ea
.B flatc\ \-c\ \-b\ schema1.fbs\ schema2.fbs\ data.json
e7399ea
.EE
e7399ea
.SH "SEE ALSO"
e7399ea
.UR https://google.github.io/flatbuffers
e7399ea
Official documentation
e7399ea
.UE