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 Descriptor CC

From Leeroopedia


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

Overview

Core implementation of the Protocol Buffers Descriptor system providing runtime schema reflection and message introspection.

Description

This is one of the largest and most critical files in the protobuf runtime, implementing the full descriptor infrastructure that enables runtime introspection of protobuf schemas. It includes the construction, validation, and cross-linking of file descriptors, message descriptors, field descriptors, enum descriptors, and service descriptors from their proto definitions. MNN vendors this file because TensorFlow and Caffe model converters rely on the descriptor system to dynamically resolve message types, validate schemas, and perform reflection-based serialization during model format parsing.

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.cc
  • Lines: 1-8025

Signature

namespace google {
namespace protobuf {
const FileDescriptor* DescriptorPool::BuildFile(const FileDescriptorProto& proto);
const Descriptor* DescriptorPool::FindMessageTypeByName(const std::string& name) const;
const FieldDescriptor* Descriptor::FindFieldByName(const std::string& name) const;
const EnumValueDescriptor* EnumDescriptor::FindValueByNumber(int number) const;
}  // namespace protobuf
}  // namespace google

Import

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

I/O Contract

Inputs

Name Type Required Description
proto FileDescriptorProto Yes Parsed .proto file descriptor to build into the pool
name const std::string& Yes Fully qualified type name for descriptor lookups

Outputs

Name Type Description
FileDescriptor const FileDescriptor* Built and cross-linked file descriptor with all contained types
Descriptor const Descriptor* Message descriptor providing field access and nested type enumeration
FieldDescriptor const FieldDescriptor* Individual field descriptor with type, number, and label metadata

Usage Examples

// MNN internal usage
const auto* pool = google::protobuf::DescriptorPool::generated_pool();
const auto* desc = pool->FindMessageTypeByName("tensorflow.GraphDef");
const auto* field = desc->FindFieldByName("node");
int field_count = desc->field_count();

Related Pages

Page Connections

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