Implementation:Alibaba MNN FlatBuffers Flatc
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Code_Generation |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Main compiler driver for flatc, orchestrating schema parsing and dispatching to language-specific code generators.
Description
flatc.cpp implements the FlatCompiler class which serves as the entry point for the flatc command-line tool. It parses command-line arguments, invokes the schema parser, and dispatches to the appropriate code generator backend based on the requested target language. The compiler supports output for C++, Java, C#, Go, Python, JavaScript, TypeScript, PHP, Dart, Lua, Lobster, Rust, and JSON.
Usage
Vendored dependency used internally by MNN for model serialization. Not directly imported by end users.
Code Reference
Source Location
- Repository: Alibaba_MNN
- File:
3rd_party/flatbuffers/src/flatc.cpp - Lines: 1-470
Signature
class FlatCompiler {
public:
int Go(int argc, const char **argv);
void ParseAndGenerateFiles(const std::string &filename);
void Error(const std::string &err, bool usage = true);
};
Import
#include "flatbuffers/flatc.h"
I/O Contract
| Input | Output |
|---|---|
Command-line arguments + .fbs schema files |
Generated source files in the target language(s) |
--binary flag + schema + JSON data |
Binary FlatBuffer file |
Usage Examples
// Typical command-line invocation (not C++ API):
// flatc --cpp --gen-mutable schema.fbs
// Programmatic usage:
FlatCompiler compiler;
const char *argv[] = {"flatc", "--cpp", "schema.fbs"};
int result = compiler.Go(3, argv);