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 Reflection Impl

From Leeroopedia


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

Overview

Runtime reflection utilities implementing dynamic field access, buffer resizing, and object copying for FlatBuffers.

Description

reflection.cpp provides the implementation of the reflection utilities declared in reflection.h. It includes functions for dynamically getting and setting field values by reflection metadata, resizing vectors within an existing buffer, copying objects between FlatBuffers, and verifying buffers using reflection schema data. These operations enable runtime manipulation of FlatBuffers without compile-time generated code.

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/reflection.cpp
  • Lines: 1-683

Signature

namespace flatbuffers {
  void ResizeVector(const reflection::Schema &schema, uoffset_t newsize,
                    const reflection::Object &objectdef, Table *table);
  Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
                                   const reflection::Schema &schema,
                                   const reflection::Object &objectdef,
                                   const Table &table);
}

Import

#include "flatbuffers/reflection.h"

I/O Contract

Input Output
Table + Field descriptor + new size Resized vector within the mutable FlatBuffer
Source Table + Schema + FlatBufferBuilder Deep copy of the table as a new offset in the builder
Table + Field descriptor + new value Modified field value in-place in the buffer

Usage Examples

#include "flatbuffers/reflection.h"

auto &schema = *reflection::GetSchema(bfbs_data);
auto *root_def = schema.root_table();

// Copy a table into a new builder
flatbuffers::FlatBufferBuilder fbb;
auto copy = flatbuffers::CopyTable(fbb, schema, *root_def,
                                    *flatbuffers::GetAnyRoot(buffer));
fbb.Finish(copy);

Related Pages

Page Connections

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