FLATC(1)
πΈ FLATC β bestie edition π
okay so this is FLATC(1), the User Commands one, and literally it's the main character of the FlatBuffers world. sit down, grab a strawberry drink π, we're doing this.
β¨ NAME β¨
flatc β FlatBuffers compiler. that's it, that's the name, slay.
π¦ SYNOPSIS π¦
flatc [ GENERATOR_OPTIONS ] [ -o PATH ] FILES... [ -- BINARY_FILES... ]
π DESCRIPTION π
The main compiler for FlatBuffers is called flatc(1) and it's the one that takes your schema definitions and turns them into generated code files for a whole bunch of languages. one schema, many languages, no cap. π
π OPTIONS π
- The
GENERATOR_OPTIONSare the vibe-setters: they say which language(s) you're compiling code for, plus all the little features you wanna enable or disable. - The
-o PATHsays where the generated files get dropped. if you don't say anything, it defaults to the current path, ngl. - The
-I PATHsays where your included schema files are hiding. also defaults to the current path if you don't specify.
π INPUT FILES π
FILES... is one or more schema or data files to process. and bestie, they get processed in the order provided β order matters, fr fr.
π§ SCHEMA FILES π§
For schema files, the language specifiers are how you tell flatc which languages to generate code for:
--cpp: C++--java: Java--kotlin: Kotlin--csharp: C#--go: Golang--python: Python--js: JavaScript--ts: TypeScript--php: PHP--dart: Dart--lua: Lua--lobster: Lobster--rust: Rust--swift: Swift--nim: Nim
Also, if you toss in --grpc it will generate RPC stub code for gRPC β but heads up, that's not available in all languages. π
ποΈ DATA FILES ποΈ
If your FILES... are data files, you can export them to either a binary or a JSON representation. two paths, both iconic:
--binary,-bβ generates a binary file holding a serialized flatbuffer.--json,-jβ generates a JSON file from a serialized flatbuffer.
β οΈ Both options require the corresponding schema file to be included first in the list of FILES.... don't skip this, it's giving chaos otherwise.
π§ To Binary
To serialize the JSON data in mydata.json using the schema myschema.fbs:
flatc --binary myschema.fbs mydata.json
This will generate a mydata_wire.bin file containing the serialized flatbuffer data. so clean, so tidy. β¨
π To JSON
To convert the serialized binary flatbuffer mydata.bin using the schema myschema.fbs to JSON:
flatc --json myschema.fbs mydata.bin
This will generate a mydata.json file. round trip, periodt. π
π₯ ADDITIONAL OPTIONS π₯
-o PATHβ output all generated files toPATH(either absolute, or relative to the current directory). if you omit it,PATHwill be the current directory. and bestie,PATHshould end in your system's path separator, e.g./or\. yes, really.-I PATHβ when it hits include statements, it attempts to load those files from this path. paths get tried in the order given, and if they all fail (or you specified none at all) it tries to load relative to the path of the schema file being parsed.-Mβ print make rules for generated files.--strict-jsonβ require and generate strict JSON (field names are enclosed in quotes, no trailing commas in tables/vectors). by default, no quotes are required/generated, and trailing commas are allowed. choose your fighter.--allow-non-utf8β pass non-UTF-8 input through the parser and emit nonstandard\xescapes in JSON. (default is to raise a parse error on non-UTF-8 input.) then,--natural-utf8β output strings with UTF-8 as human-readable strings. by default, UTF-8 characters are printed as\uXXXXescapes.--defaults-jsonβ output fields whose value is equal to the default value when writing JSON text.--no-prefixβ don't prefix enum values in generated C++ by their enum type.--scoped-enumsβ use C++11 style scoped and strongly typed enums in generated C++. this also implies--no-prefix.--no-emit-min-max-enum-valuesβ disable generation ofMINandMAXenumerated values for scoped enums and prefixed enums.--gen-includesβ (deprecated) this is the default behavior. if you need the original behavior (no include statements) use--no-includes.--no-includesβ don't generate include statements for included schemas the generated file depends on (C++ / Python).--gen-mutableβ generate additional non-const accessors for mutating FlatBuffers in-place.--gen-onefileβ generate a single output file for C#, Go, and Python.--gen-name-stringsβ generate type name functions for C++.--gen-object-apiβ generate an additional object-based API. this API is more convenient for object construction and mutation than the base API, at the cost of efficiency (object allocation). it's recommended only if other options are insufficient, ngl.--gen-compareβ generateoperator==for object-based API types.--gen-nullableβ add Clang_Nullablefor C++ pointer or@Nullablefor Java.--gen-generatedβ add@Generatedannotation for Java.--gen-jvmstaticβ add@JvmStaticannotation for Kotlin methods in companion object, for interop from Java to Kotlin.--gen-allβ generate not just code for the current schema files, but for all files it includes as well. if the language uses a single file for output (by default the case for C++ and JS), all code will end up in this one file.--cpp-includeβ adds an#includein the generated file.--cpp-ptr-type Tβ set object API pointer type (defaultstd::unique_ptr).--cpp-str-type Tβ set object API string type (defaultstd::string).T::c_str(),T::length()andT::empty()must be supported. the custom type also needs to be constructible fromstd::string(see the--cpp-str-flex-ctoroption to change this behavior).--cpp-str-flex-ctorβ don't construct custom string types by passingstd::stringfrom Flatbuffers, but (char*+ length). this allows efficient construction of custom string types, including zero-copy construction. obsessed. β¨--no-cpp-direct-copyβ don't generate direct copy methods for C++ object-based API.--cpp-std CPP_STDβ generate C++ code using features of the selected C++ standard. supportedCPP_STDvalues:c++0xβ generate code compatible with old compilers (VS2010),c++11β use C++11 code generator (default),c++17β use C++17 features in generated code (experimental).
--object-prefixβ customise class prefix for C++ object-based API.--object-suffixβ customise class suffix for C++ object-based API.--go-namespaceβ generate the overrided namespace in Golang.--go-importβ generate the overrided import for flatbuffers in Golang. (default isgithub.com/google/flatbuffers/go).--raw-binaryβ allow binaries without afile_indentifierto be read.
π This may crash flatc(1) given a mismatched schema. like, actually crash. be careful bestie.
--size-prefixedβ input binaries are size prefixed buffers.--protoβ expect input files to be.protofiles (protocol buffers). output the corresponding.fbsfile. currently supports:package,message,enum, nested declarations,import(use-Ifor paths),extend,oneof,group. does not support, but will skip without error:option,service,extensions, and most everything else. it's giving "we tried our best" but honestly still great.--oneof-unionβ translate.protooneofs to flatbuffer unions.--grpcβ generate GRPC interfaces for the specified languages.--schemaβ serialize schemas instead of JSON (use with-b). this will output a binary version of the specified schema that itself corresponds to thereflection/reflection.fbsschema. loading this binary file is the basis for reflection functionality. main character behavior tbh. π--bfbs-commentsβ add doc comments to the binary schema files.--conform FILEβ specify a schema the following schemas should be an evolution of. gives errors if not. super useful to check that schema modifications don't break schema evolution rules.--conform-includes PATHβ include path for the schema given with--conform PATH.--filename-suffix SUFFIXβ the suffix appended to the generated file names. default is_generated.--filename-ext EXTENSIONβ the extension appended to the generated file names. default is language-specific (e.g."h"for C++).
π This should not be used when multiple languages are specified.
--include-prefix PATHβ prefix this path to any generated include statements.--keep-prefixβ keep original prefix of schema include statement.--reflect-typesβ add minimal type reflection to code generation.--reflect-namesβ add minimal type/name reflection.--root-type Tβ select or override the defaultroot_type.--require-explicit-idsβ when parsing schemas, require explicit ids (id: x).--force-defaultsβ emit default values in binary output from JSON.--force-emptyβ when serializing from object API representation, force strings and vectors to empty rather than null.--force-empty-vectorsβ when serializing from object API representation, force vectors to empty rather than null.--flexbuffersβ used with--binaryand--jsonoptions, it generates data using schema-less FlexBuffers.--no-warningsβ inhibit all warning messages. silence, gorgeous.--cs-global-aliasβ prependglobal::to all user generated csharp classes and structs.--json-nested-bytesβ allow anested_flatbufferfield to be parsed as a vector of bytes in JSON.
β οΈ which is unsafe unless checked by a verifier afterwards. no cap, verify it.
--python-no-type-prefix-suffixβ skip emission of Python functions that are prefixed with typenames.--python-typingβ generate Python type annotations.
π ADDITIONAL gRPC OPTIONS π
--grpc-filename-suffixβ[C++]an optional suffix for the generated files' names. for example, compiling gRPC for C++ with--grpc-filename-suffix=.fbswill generate{name}.fbs.hand{name}.fbs.ccfiles.--grpc-additional-headerβ[C++]additional headers to include in the generated files.--grpc-search-pathβ[C++]an optional prefix for the gRPC runtime path. for example, compiling gRPC for C++ with--grpc-search-path=some/pathwill generate the following includes:
#include "some/path/grpcpp/impl/codegen/async_stream.h"
#include "some/path/grpcpp/impl/codegen/async_unary_call.h"
#include "some/path/grpcpp/impl/codegen/method_handler.h"
...
--grpc-use-system-headersβ [C++] okay so this one is a whole vibe question: do you want the generated includes to be#include <header>instead of#include "header.h"for all headers when you're compiling gRPC for C++? π That's it, that's the whole thing.
Like, if you compile gRPC for C++ with --grpc-use-system-headers, bestie, you get this instead:
#include <some/path/grpcpp/impl/codegen/async_stream.h>
#include <some/path/grpcpp/impl/codegen/async_unary_call.h>
#include <some/path/grpcpp/impl/codegen/method_handler.h>
...
NOTE: you can flip this one off with --no-grpc-use-system-headers. No cap. β¨
--grpc-python-typed-handlersβ [Python] do you want the typed handlers that use the generated Python classes, or do you want raw bytes for requests/responses? π This flag is you choosing the typed ones. It's giving type safety, it's giving main character energy. π
π NOTES π
- Short-form options for generators are deprecated π β use the long form whenever possible, fr fr. Do not be out here typing the short ones like it's 2019. π
π SEE ALSO π
- Official documentation β go read it, bestie, iykyk π¦
and that's a wrap on FLATC(1)!! π this page is from January 2025, it's the FLATC(1) situation, and honestly? she ate. πβ¨ go forth and compile something iconic, ily, bye!! ππΈπ«Ά
π¦ where this page comes from
- fedora 43: flatbuffers-compiler 25.2.10-5.fc43 Β· Apache-2.0
- fedora 44: flatbuffers-compiler 25.12.19-2.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms