Implementation:Alibaba MNN Protobuf Extension Set H
| Knowledge Sources | |
|---|---|
| Domains | Serialization, Extensibility |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Header declaring the Protocol Buffers ExtensionSet class and related types for managing extension fields on protobuf messages.
Description
This header defines the ExtensionSet class within the google::protobuf::internal namespace, providing the interface for storing, accessing, and serializing extension fields. It includes type-specific getters and setters for all protobuf scalar types, string types, and message types, as well as repeated field variants. The header also defines the ExtensionInfo struct and registration mechanisms for extension fields. MNN vendors this header because the Caffe protobuf schema uses extensions extensively, and the full ExtensionSet infrastructure is needed to correctly parse these model files.
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.h - Lines: 1-1560
Signature
namespace google {
namespace protobuf {
namespace internal {
class PROTOBUF_EXPORT ExtensionSet {
bool Has(int number) const;
void Clear(int number);
size_t SpaceUsedExcludingSelfLong() const;
bool SerializeWithCachedSizes(int start, int end, io::CodedOutputStream* output) const;
};
} // 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 |
|---|---|---|---|
| N/A | N/A | N/A | Header-only declarations; provides the ExtensionSet interface for extension field management |
Outputs
| Name | Type | Description |
|---|---|---|
| ExtensionSet | google::protobuf::internal::ExtensionSet |
Container class managing all extension fields on a protobuf message |
Usage Examples
// MNN internal usage (within generated message code)
#include "google/protobuf/extension_set.h"
internal::ExtensionSet _extensions_;
if (_extensions_.Has(kConvolutionParam)) {
const auto& param = _extensions_.GetMessage(kConvolutionParam, default_instance);
}