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 Entry Lite H

From Leeroopedia


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

Overview

Header defining the lite MapEntryLite message wrapper that serializes individual map field entries as key-value pair sub-messages.

Description

This header implements the MapEntryLite template class, which wraps a single key-value pair from a protobuf map field into a sub-message for wire-format serialization. In protobuf's wire format, each map entry is serialized as a nested message with field 1 as the key and field 2 as the value. MapEntryLite provides the lite (non-reflection) variant of this wrapper, handling serialization, deserialization, and byte-size calculation for map entries. MNN vendors this header because TensorFlow model files use map fields extensively (e.g., NodeDef.attr), and the map entry serialization logic is essential for correctly parsing these fields.

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_entry_lite.h
  • Lines: 1-654

Signature

namespace google {
namespace protobuf {
namespace internal {
template <typename Derived, typename Key, typename Value,
          WireFormatLite::FieldType kKeyFieldType,
          WireFormatLite::FieldType kValueFieldType>
class MapEntryLite : public MessageLite {
  const Key& key() const;
  const Value& value() const;
};
}  // namespace internal
}  // namespace protobuf
}  // namespace google

Import

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

I/O Contract

Inputs

Name Type Required Description
key Key Yes Map entry key, serialized as field 1 in the sub-message wire format
value Value Yes Map entry value, serialized as field 2 in the sub-message wire format

Outputs

Name Type Description
MapEntryLite MapEntryLite<...> MessageLite-derived wrapper enabling wire-format serialization of a single map entry
byte_size size_t Computed serialized byte size of the key-value pair sub-message

Usage Examples

// MNN internal usage (generated map field code)
// Map entries are implicitly created during map field parsing
auto& attr_map = *node_def.mutable_attr();
attr_map["padding"].set_s("SAME");
// Internally each entry serialized via MapEntryLite

Related Pages

Page Connections

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