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 Protobuf Generated TCTable Impl H

From Leeroopedia


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

Overview

Header implementing the tail-call table (TCTable) dispatch mechanism for high-performance protobuf parsing.

Description

This header provides the implementation of the tail-call optimized parsing table, a next-generation parsing strategy that uses computed goto or tail-call function pointers for near-zero-overhead field dispatch. Each entry in the TCTable maps a wire-format tag to a specialized parsing function, enabling the parser to jump directly to the correct handler without loop overhead or branch misprediction. MNN vendors this file as part of the protobuf runtime because it provides the fastest available parsing path for large TensorFlow and Caffe model files where deserialization performance is critical.

Usage

Vendored dependency used internally by MNN for parsing protobuf-based model formats (TensorFlow, Caffe). Not directly imported by end users.

Code Reference

Source Location

  • Repository: Alibaba_MNN
  • File: 3rd_party/protobuf/src/google/protobuf/generated_message_tctable_impl.h
  • Lines: 1-302

Signature

namespace google {
namespace protobuf {
namespace internal {
struct TcFieldData { uint64 data; };
struct TcParseTableBase { const void* fast_entries; uint32 num_fast_entries; };
const char* TcParser::ParseLoop(MessageLite* msg, const char* ptr, ParseContext* ctx, const TcParseTableBase* table);
}  // namespace internal
}  // namespace protobuf
}  // namespace google

Import

#include "3rd_party/protobuf/src/google/protobuf/generated_message_tctable_impl.h"

I/O Contract

Inputs

Name Type Required Description
ptr const char* Yes Pointer into the raw serialized protobuf byte buffer
table const TcParseTableBase* Yes Tail-call parse table mapping tags to handler functions
ctx ParseContext* Yes Parse context tracking recursion depth and buffer boundaries

Outputs

Name Type Description
ptr const char* Updated pointer past the consumed bytes, or nullptr on error
msg MessageLite* Populated message with all parsed fields from the input buffer

Usage Examples

// MNN internal usage (generated fast-path parsing)
static const internal::TcParseTableBase kTcTable = { ... };
const char* ptr = internal::TcParser::ParseLoop(
    this, raw_ptr, &parse_ctx, &kTcTable);
if (ptr == nullptr) { /* parse error */ }

Related Pages

Page Connections

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