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 Struct PB H

From Leeroopedia


Metadata

Attribute Value
Implementation File 3rd_party/protobuf/src/google/protobuf/struct.pb.h
Line Count 1182
Domains Serialization, Type_System
Key Classes Struct, Value, ListValue
Created 2026-02-10
Knowledge Sources Repo, Doc

Overview

Generated header for the Struct well-known type, providing dynamic JSON-like structures within protobuf. Defines Struct (object), Value (variant), and ListValue (array) types.

Usage note: Vendored dependency used internally by MNN for parsing protobuf-based model formats. Not directly imported by end users.

Description

This generated header corresponds to google/protobuf/struct.proto, one of the protobuf well-known types. It provides a schema-free data model analogous to JSON:

  • Struct -- Represents a JSON object as a map<string, Value>. Each key-value pair maps a field name to a dynamically-typed Value.
  • Value -- A variant type that can hold one of: NullValue, double (number_value), string (string_value), bool (bool_value), Struct (struct_value), or ListValue (list_value). Uses a protobuf oneof internally.
  • ListValue -- Represents a JSON array as a repeated Value.
  • NullValue -- An enum with a single value (NULL_VALUE = 0) representing JSON null.

These types are used when protobuf messages need to carry arbitrary structured data, such as configuration payloads or API responses with dynamic schemas.

Usage

#include "google/protobuf/struct.pb.h"

Used wherever google.protobuf.Struct, google.protobuf.Value, or google.protobuf.ListValue appear in .proto definitions.

Code Reference

// Struct: JSON object representation.
class PROTOBUF_EXPORT Struct : public Message {
 public:
  // Map field: map<string, Value> fields = 1;
  int fields_size() const;
  void clear_fields();
  const ::google::protobuf::Map<std::string, Value>& fields() const;
  ::google::protobuf::Map<std::string, Value>* mutable_fields();
};

// Value: dynamic variant type.
class PROTOBUF_EXPORT Value : public Message {
 public:
  enum KindCase {
    kNullValue = 1,
    kNumberValue = 2,
    kStringValue = 3,
    kBoolValue = 4,
    kStructValue = 5,
    kListValue = 6,
    KIND_NOT_SET = 0,
  };

  KindCase kind_case() const;

  // Accessors for each variant.
  double number_value() const;
  void set_number_value(double value);
  const std::string& string_value() const;
  void set_string_value(const std::string& value);
  bool bool_value() const;
  void set_bool_value(bool value);
  const Struct& struct_value() const;
  Struct* mutable_struct_value();
  const ListValue& list_value() const;
  ListValue* mutable_list_value();
};

// ListValue: JSON array representation.
class PROTOBUF_EXPORT ListValue : public Message {
 public:
  int values_size() const;
  const Value& values(int index) const;
  Value* add_values();
};

I/O Contract

Direction Type Description
Input Wire-format bytes or JSON Struct/Value/ListValue can be parsed from binary or JSON format
Output Wire-format bytes or JSON Serializes to binary protobuf or JSON via JsonUtil
Runtime Dynamic typing Value::kind_case() determines the active variant at runtime

Usage Examples

// Building a Struct (JSON-like object) programmatically
google::protobuf::Struct s;
auto* fields = s.mutable_fields();

Value name_val;
name_val.set_string_value("MNN");
(*fields)["name"] = name_val;

Value version_val;
version_val.set_number_value(2.0);
(*fields)["version"] = version_val;

Related Pages

Page Connections

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