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 Wrappers PB CC

From Leeroopedia


Metadata

Attribute Value
Implementation File 3rd_party/protobuf/src/google/protobuf/wrappers.pb.cc
Line Count 1955
Domains Serialization, Type_System
Key Classes DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue
Created 2026-02-10
Knowledge Sources Repo, Doc

Overview

Generated implementation for the protobuf wrapper well-known types. Contains the serialization, deserialization, and utility method implementations for all nine wrapper types (DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value, BoolValue, StringValue, BytesValue).

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

Description

This generated source file corresponds to google/protobuf/wrappers.proto and implements the nine wrapper well-known types. Each wrapper type wraps a single primitive value in a message, which is necessary for:

  • Nullable fields -- In proto3, scalar fields cannot distinguish between "not set" and "default value". Wrapping a scalar in a message allows null semantics via field presence.
  • google.protobuf.Any compatibility -- Wrapping scalars in messages allows them to be stored in Any fields.
  • JSON mapping -- Wrapper types have special JSON representations (e.g., DoubleValue serializes as a plain JSON number, not an object).

Each wrapper class is a full Message subclass with:

  • Default/copy/move constructors and assignment operators.
  • value() getter and set_value() setter for the wrapped scalar.
  • Full serialization (_InternalSerialize), deserialization (_InternalParse), and byte size (ByteSizeLong) implementations.
  • Descriptor and reflection registration via protobuf_AssignDescriptors.

Usage

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

Used when .proto files import google/protobuf/wrappers.proto and reference types such as google.protobuf.DoubleValue.

Code Reference

// Example: DoubleValue implementation pattern (repeated for each wrapper type)
DoubleValue::DoubleValue() : value_(0.0) {}

void DoubleValue::Clear() {
  value_ = 0.0;
  _internal_metadata_.Clear();
}

const char* DoubleValue::_InternalParse(const char* ptr,
                                         ParseContext* ctx) {
  while (!ctx->Done(&ptr)) {
    uint32_t tag;
    ptr = ReadTag(ptr, &tag);
    switch (tag >> 3) {
      case 1:  // double value = 1;
        value_ = DecodeDouble(ptr);
        ptr += 8;
        break;
      default:
        ptr = UnknownFieldParse(tag, _internal_metadata_.mutable_unknown_fields(), ptr, ctx);
        break;
    }
  }
  return ptr;
}

uint8_t* DoubleValue::_InternalSerialize(
    uint8_t* target, io::EpsCopyOutputStream* stream) const {
  if (value_ != 0.0) {
    target = WireFormatLite::WriteDoubleToArray(1, value_, target);
  }
  return target;
}

size_t DoubleValue::ByteSizeLong() const {
  size_t total_size = 0;
  if (value_ != 0.0) {
    total_size += 1 + 8;  // tag + fixed64
  }
  return total_size;
}

I/O Contract

Direction Type Description
Input Wire-format bytes Binary protobuf data containing a single wrapped value
Output Wire-format bytes Serialized wrapper message with tag + value encoding
Value Wrapped primitive Single scalar field accessible via value() / set_value()

Usage Examples

// Using DoubleValue to wrap a nullable double
google::protobuf::DoubleValue dv;
dv.set_value(3.14);

std::string serialized;
dv.SerializeToString(&serialized);

google::protobuf::DoubleValue parsed;
parsed.ParseFromString(serialized);
double val = parsed.value();  // 3.14

Related Pages

Page Connections

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