Implementation:Alibaba MNN Protobuf Generated Table Driven H
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Parsing |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Header providing table-driven parsing support structures for efficient protobuf message deserialization.
Description
This header defines the data structures and entry points for table-driven protobuf parsing, an optimization that replaces per-field switch statements with lookup tables. The table-driven approach uses compact metadata tables to direct the parser to the correct field handler, reducing code size and improving instruction cache utilization. MNN vendors this header as part of the protobuf runtime because generated code for TensorFlow and Caffe model proto files may reference these table-driven parsing structures for efficient deserialization of model data.
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_table_driven.h - Lines: 1-351
Signature
namespace google {
namespace protobuf {
namespace internal {
struct ParseTableField { uint32 offset; uint32 has_bit; uint32 aux_idx; };
struct ParseTable { const ParseTableField* fields; const uint32* has_bits; };
bool MergePartialFromCodedStream(MessageLite* msg, const ParseTable& table, io::CodedInputStream* input);
} // namespace internal
} // namespace protobuf
} // namespace google
Import
#include "3rd_party/protobuf/src/google/protobuf/generated_message_table_driven.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| table | const ParseTable& |
Yes | Compiled parse table containing field offsets and type metadata |
| input | io::CodedInputStream* |
Yes | Input stream containing serialized protobuf wire-format data |
Outputs
| Name | Type | Description |
|---|---|---|
| success | bool |
Whether the table-driven parse completed successfully |
| msg | MessageLite* |
Populated message object with parsed field values |
Usage Examples
// MNN internal usage (called by generated code)
static const internal::ParseTable kParseTable = { fields, has_bits, ... };
bool ok = internal::MergePartialFromCodedStream(
this, kParseTable, input);
// Fields populated via table-driven dispatch