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 Map H

From Leeroopedia


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

Overview

Header implementing the Protocol Buffers Map container class for key-value map fields in protobuf messages.

Description

This header defines the google::protobuf::Map template class, which provides the underlying container for protobuf map fields (e.g., map<string, int32>). The Map class implements an interface similar to std::unordered_map but with arena-aware allocation and optimized serialization support. It uses a custom hash table implementation tuned for protobuf's access patterns. MNN vendors this header because TensorFlow model files extensively use map fields for attribute dictionaries (map<string, AttrValue>) in node definitions, making efficient map handling essential for model 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/map.h
  • Lines: 1-1377

Signature

namespace google {
namespace protobuf {
template <typename Key, typename T>
class Map {
  T& operator[](const Key& key);
  const_iterator find(const Key& key) const;
  size_type size() const;
  std::pair<iterator, bool> insert(const value_type& value);
};
}  // namespace protobuf
}  // namespace google

Import

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

I/O Contract

Inputs

Name Type Required Description
key Key Yes Map key (string, int32, int64, uint32, uint64, bool, or sint types)
value T Yes Map value (any protobuf scalar, enum, or message type)

Outputs

Name Type Description
Map container google::protobuf::Map<Key, T> Arena-aware hash map with STL-compatible iterator interface
iterator Map<Key, T>::iterator Bidirectional iterator over key-value pairs

Usage Examples

// MNN internal usage (TensorFlow NodeDef attr parsing)
const auto& attrs = node_def.attr();
auto it = attrs.find("dtype");
if (it != attrs.end()) {
  const AttrValue& val = it->second;
}

Related Pages

Page Connections

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