Implementation:Alibaba MNN FlatBuffers IDL Gen CPP
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Code_Generation |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
C++ code generator backend that emits header files with zero-copy accessors and builder classes from FlatBuffers schemas.
Description
idl_gen_cpp.cpp implements the C++ code generation backend for flatc. It traverses the parsed schema tree and emits a single _generated.h header containing struct accessors, table accessors with vtable lookups, builder classes, verifier methods, and optional mutation accessors. This is the most critical generator for MNN since the framework uses C++ generated code for all model file I/O.
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/idl_gen_cpp.cpp - Lines: 1-2763
Signature
namespace flatbuffers {
bool GenerateCPP(const Parser &parser,
const std::string &path,
const std::string &file_name);
}
Import
#include "flatbuffers/idl.h"
// Generator invoked internally by flatc
I/O Contract
| Input | Output |
|---|---|
| Parsed Parser object with schema definitions | *_generated.h C++ header file with accessors and builders
|
Usage Examples
// Invoked by flatc, not directly:
// flatc --cpp --gen-mutable --scoped-enums model.fbs
// Internally:
flatbuffers::Parser parser;
parser.Parse(schema);
flatbuffers::GenerateCPP(parser, output_path, file_name);