Implementation:Alibaba MNN Protobuf Descriptor H
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Reflection |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Header declaring the Protocol Buffers Descriptor classes for runtime schema reflection, message introspection, and field enumeration.
Description
This header defines the core descriptor class hierarchy: Descriptor (messages), FieldDescriptor (fields), EnumDescriptor (enums), ServiceDescriptor (services), FileDescriptor (files), and DescriptorPool (schema registry). These classes provide a complete runtime representation of .proto schemas, enabling dynamic message creation and reflection-based access. MNN vendors this header because the TensorFlow and Caffe model conversion tools use descriptor-based reflection to navigate model graph structures without hard-coding every message type.
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/descriptor.h - Lines: 1-2417
Signature
namespace google {
namespace protobuf {
class Descriptor { int field_count() const; const FieldDescriptor* field(int i) const; };
class FieldDescriptor { FieldDescriptor::Type type() const; int number() const; };
class EnumDescriptor { const EnumValueDescriptor* FindValueByNumber(int n) const; };
class DescriptorPool { const Descriptor* FindMessageTypeByName(const std::string&) const; };
} // namespace protobuf
} // namespace google
Import
#include "3rd_party/protobuf/src/google/protobuf/descriptor.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A | N/A | N/A | Header-only declarations; provides descriptor class interfaces for schema introspection |
Outputs
| Name | Type | Description |
|---|---|---|
| Descriptor | google::protobuf::Descriptor |
Message-level schema descriptor with field and nested type access |
| FieldDescriptor | google::protobuf::FieldDescriptor |
Field-level metadata including type, name, number, and label |
| DescriptorPool | google::protobuf::DescriptorPool |
Registry for looking up descriptors by fully qualified name |
Usage Examples
// MNN internal usage
#include "google/protobuf/descriptor.h"
const auto* desc = message.GetDescriptor();
for (int i = 0; i < desc->field_count(); ++i) {
const auto* field = desc->field(i);
}