Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Alibaba MNN FlatBuffers IDL Gen General

From Leeroopedia


Knowledge Sources
Domains Serialization, Code_Generation
Last Updated 2026-02-10 12:00 GMT

Overview

Shared code generator backend for Java and C# that emits FlatBuffers accessor and builder classes for both languages.

Description

idl_gen_general.cpp implements a unified code generation backend for Java and C#. Since these languages share similar object-oriented structures, a single generator handles both with language-specific tweaks for package declarations, namespace syntax, and type mappings. The output consists of one class per table/struct/enum, each in its own source file, following the conventions of each target language.

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_general.cpp
  • Lines: 1-1568

Signature

namespace flatbuffers {
  bool GenerateGeneral(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 + Java language flag *.java source files (one per type)
Parsed Parser object + C# language flag *.cs source files (one per type)

Usage Examples

// Invoked by flatc:
// flatc --java schema.fbs
// flatc --csharp schema.fbs

// Internally:
flatbuffers::Parser parser;
parser.Parse(schema);
flatbuffers::GenerateGeneral(parser, output_path, file_name);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment