Implementation:Alibaba MNN FlatBuffers IDL Parser
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Schema_Parsing |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Full schema parser for .fbs files that builds an in-memory representation of FlatBuffers schemas.
Description
idl_parser.cpp implements the core Parser class that tokenizes and parses FlatBuffers schema files (.fbs) into an in-memory abstract representation. It handles all schema constructs including tables, structs, enums, unions, namespaces, includes, attributes, and rpc_service declarations. The parser also supports parsing JSON data against a known schema for binary conversion. At 3172 lines, this is the largest single file in the vendored FlatBuffers source tree.
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_parser.cpp - Lines: 1-3172
Signature
namespace flatbuffers {
class Parser {
public:
bool Parse(const char *source, const char **include_paths = nullptr,
const char *source_filename = nullptr);
bool SetRootType(const char *name);
SymbolTable<StructDef> structs_;
SymbolTable<EnumDef> enums_;
};
}
Import
#include "flatbuffers/idl.h"
I/O Contract
| Input | Output |
|---|---|
Raw .fbs schema text + optional include paths |
Populated Parser with structs_, enums_, services_ symbol tables
|
| JSON text + previously parsed schema | Binary FlatBuffer in Parser::builder_
|
Usage Examples
#include "flatbuffers/idl.h"
flatbuffers::Parser parser;
const char *include_paths[] = {"schemas/", nullptr};
bool ok = parser.Parse(schema_text, include_paths, "model.fbs");
if (ok) {
parser.SetRootType("Net");
// Schema is now ready for code generation or JSON parsing
}