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 Extension Set CC

From Leeroopedia


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

Overview

Implementation of the Protocol Buffers ExtensionSet class for managing extension fields on protobuf messages.

Description

This file implements the ExtensionSet class, which stores and manages extension fields that extend a protobuf message beyond its originally defined fields. Extensions allow third-party code to add fields to existing message types without modifying the original .proto definition. The implementation handles serialization, deserialization, merging, and clearing of extension fields across all supported types (scalars, strings, messages, repeated fields). MNN vendors this file because Caffe model formats heavily use protobuf extensions to define layer-specific parameters within the generic LayerParameter 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/extension_set.cc
  • Lines: 1-2255

Signature

namespace google {
namespace protobuf {
namespace internal {
bool ExtensionSet::Has(int number) const;
int32 ExtensionSet::GetInt32(int number, int32 default_value) const;
void ExtensionSet::SetInt32(int number, FieldType type, int32 value, const FieldDescriptor*);
void ExtensionSet::MergeFrom(const ExtensionSet& other);
}  // namespace internal
}  // namespace protobuf
}  // namespace google

Import

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

I/O Contract

Inputs

Name Type Required Description
number int Yes Field number identifying the extension field
value various Yes Value to set for the specified extension field
type FieldType Yes Wire type of the extension field for serialization

Outputs

Name Type Description
field value various Retrieved extension field value (int32, string, message, etc.)
has bool Whether the specified extension field is present

Usage Examples

// MNN internal usage (within generated extension accessors)
internal::ExtensionSet extensions_;
extensions_.SetInt32(field_number, FieldType::TYPE_INT32, 42, nullptr);
int32 val = extensions_.GetInt32(field_number, 0);
extensions_.MergeFrom(other.extensions_);

Related Pages

Page Connections

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