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 Core Header

From Leeroopedia


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

Overview

Main FlatBuffers API header providing FlatBufferBuilder, Verifier, Table, Struct, and zero-copy buffer access.

Description

flatbuffers.h is the central header of the FlatBuffers library and contains the full C++ API surface. It defines FlatBufferBuilder for constructing serialized buffers, Verifier for validating untrusted data, and Table/Struct base classes for generated accessors. MNN relies on this header extensively for reading and writing neural network model files in a zero-copy manner.

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/include/flatbuffers/flatbuffers.h
  • Lines: 1-2585

Signature

class FlatBufferBuilder;
class Verifier;
struct Table;
struct Struct;
template<typename T> const T *GetRoot(const void *buf);

Import

#include "flatbuffers/flatbuffers.h"

I/O Contract

Input Output
Structured data via builder API calls Serialized binary FlatBuffer in a contiguous byte buffer
Raw byte buffer Zero-copy typed accessors via GetRoot<T>()
Untrusted byte buffer Boolean validity result from Verifier

Usage Examples

#include "flatbuffers/flatbuffers.h"

// Build a buffer
flatbuffers::FlatBufferBuilder builder(1024);
auto name = builder.CreateString("model");
// ... add fields, finish buffer ...

// Read back zero-copy
auto buf = builder.GetBufferPointer();
auto root = flatbuffers::GetRoot<MyTable>(buf);

// Verify untrusted data
flatbuffers::Verifier verifier(buf, builder.GetSize());
bool ok = root->Verify(verifier);

Related Pages

Page Connections

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