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 JS TS

From Leeroopedia


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

Overview

JavaScript and TypeScript code generator backend that produces FlatBuffers accessor modules for web and Node.js environments.

Description

idl_gen_js_ts.cpp implements a combined JavaScript/TypeScript code generation backend for flatc. It generates ES module or CommonJS compatible code with classes that read FlatBuffer data through typed array views. When targeting TypeScript, it additionally emits type annotations and interface declarations for compile-time type safety. The generated code depends on the flatbuffers npm package.

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_js_ts.cpp
  • Lines: 1-1335

Signature

namespace flatbuffers {
  bool GenerateJSTS(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 + JS flag *_generated.js JavaScript module
Parsed Parser object + TS flag *_generated.ts TypeScript module with type annotations

Usage Examples

// Invoked by flatc:
// flatc --js schema.fbs
// flatc --ts schema.fbs

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

Related Pages

Page Connections

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