我要评分
获取效率
正确性
完整性
易理解

Protobuf

Latest Updates

  • [2026-06-30]: Released V1.0.1: Added parsing optimizations for Map and StringBlock and supports the C++23 resize_and_overwrite feature.
  • [2026-03-30]: Released V1.0.0: Added varint packed encoding and decoding optimizations and enabled the SIMDUTF verification algorithm.

Project Introduction

Overview

Protocol Buffers (Protobuf) is an open-source mechanism developed by Google for serializing structured data. It is language-neutral, platform-neutral, and extensible, designed for efficient data exchange and storage in distributed systems. Protobuf also supports seamless integration with RPC frameworks such as bRPC/gRPC. Its core advantages include small serialized size, fast parsing speed, and support for multi-version protocol compatibility and evolution. Additionally, it provides runtime libraries across multiple languages including C++, Java, Python, and Go.

Core Modules

Protobuf consists of two main core components: the compiler module (protoc) and the runtime module (language-specific runtime). The internal modules are organized as follows:

  • Descriptor module: Defines metadata structures for messages, enums, and services (e.g., Descriptor, FieldDescriptor).
  • Message core module: Provides fundamental capabilities for message serialization, deserialization, and field access.
  • I/O encoding and decoding module: Implements reading, writing, and encoding of binary streams (e.g., variable-length integers, packed arrays).
  • Utility module: Provides auxiliary capabilities such as JSON conversion, message comparison, and time type processing.
  • Compiler plugin module: Supports custom code generation logic to adapt to different language outputs.
  • Editions feature module: Implements syntax parsing and feature control for different protocol editions (e.g., 2023/2024), including features like default field values and repeated field encoding.

Core External API Functions

The following table lists the core API functions exposed by Protobuf (using C++ as an example), such as message operations, I/O encoding and decoding, utility functions.

Message Serialization and Deserialization

Function/MethodDescription
MessageLite::SerializeToStringSerializes a message into a binary string.
MessageLite::SerializeToArraySerializes a message into a byte array.
MessageLite::SerializeToCodedStreamSerializes a message to a coded stream.
MessageLite::SerializeToOstreamSerializes a message to an output stream.
MessageLite::ParseFromStringDeserializes a message from a binary string.
MessageLite::ParseFromArrayDeserializes a message from a byte array.
MessageLite::ParseFromCodedStreamDeserializes a message from a coded stream.
MessageLite::ParseFromIstreamDeserializes a message from an input stream.
MessageLite::ByteSizeLongCalculates the byte size after serialization.

Basic Message Operations

Function/MethodDescription
MessageLite::ClearClears the values of all fields in the message.
MessageLite::IsInitializedChecks if all required fields are initialized.
MessageLite::GetTypeNameGets the message type name.
Message::CopyFromCopies field data from another message of the same type.
Message::MergeFromMerges fields from another message into the current message.
Message::DebugStringGenerates a human-readable debugging string.
Message::SpaceUsedLongCalculates the memory size occupied by the message.

Reflection Interfaces

Function/MethodDescription
Message::GetDescriptorGets the descriptor of the message.
Message::GetReflectionGets the reflection interface of the message.
Reflection::GetInt32/Int64/...Gets the field value via reflection (supporting various types).
Reflection::SetInt32/Int64/...Sets the field value via reflection (supporting various types).
Reflection::HasFieldChecks if a field has been set.
Reflection::ClearFieldClears a specified field.
Reflection::ListFieldsLists all fields that have been set.

Descriptor Queries

Function/MethodDescription
Descriptor::nameGets the message type name.
Descriptor::full_nameGets the fully qualified name of the message.
Descriptor::field_countGets the number of fields.
Descriptor::FindFieldByNameFinds a field descriptor by field name.
Descriptor::FindFieldByNumberFinds a field descriptor by field tag number.
FieldDescriptor::nameGets the field name.
FieldDescriptor::numberGets the field tag number.
FieldDescriptor::typeGets the field type.
FieldDescriptor::is_repeatedChecks if the field is a repeated field.

Arena Memory Management

Function/MethodDescription
Arena::Create<T>Creates an object instance in the arena memory pool to reduce memory fragmentation.
Arena::CreateArray<T>Creates an array in the arena memory pool.
Arena::ResetResets the arena memory pool, releasing all allocated objects.
Arena::SpaceAllocatedGets the size of the memory allocated by the arena.
Arena::OwnTakes ownership of a heap object, allowing its lifecycle to be managed by the arena.
MessageLite::GetArenaGets the pointer to the arena where the message resides.

I/O Encoding and Decoding

Function/MethodDescription
CodedInputStream::ReadVarint32Reads a 32-bit variable-length integer from the input stream.
CodedInputStream::ReadVarint64Reads a 64-bit variable-length integer from the input stream.
CodedInputStream::ReadStringReads a string from the input stream.
CodedInputStream::ReadTagReads a field tag.
CodedInputStream::PushLimitSets a read limit to prevent buffer overflow.
CodedOutputStream::WriteVarint32Writes a 32-bit variable-length integer to the output stream.
CodedOutputStream::WriteVarint64Writes a 64-bit variable-length integer to the output stream.
CodedOutputStream::WriteStringWrites a string to the output stream and encodes it.
CodedOutputStream::WriteTagWrites a field tag.

JSON Conversion

Function/MethodDescription
util::MessageToJsonStringConverts a Protobuf message into a JSON string.
util::JsonStringToMessageParses a JSON string into a Protobuf message.
util::BinaryToJsonStringConverts binary Protobuf data into a JSON string.
util::JsonToBinaryStringConverts a JSON string into binary Protobuf data.

Message Comparison

Function/MethodDescription
util::MessageDifferencer::EqualsCompares whether the field values of two messages are completely identical.
util::MessageDifferencer::EquivalentCompares whether two messages are equivalent (taking default values into account).
util::MessageDifferencer::ComparePerforms message comparison and returns the differences.
MessageDifferencer::ReportDifferencesToStringOutputs the message differences as a string.

Dynamic Messages

Function/MethodDescription
DynamicMessageFactory::GetPrototypeCreates a prototype of a dynamic message based on a descriptor.
DynamicMessage::NewCreates an instance of a dynamic message.

Directory Structure

The project directory structure is as follows:

# Document Directory
README_EN.md                          # Project description
LICENSE                            # Code license
docs/
├── LICENSE                        # Document license
└── en/
    ├── api_reference.md           # API Reference
    ├── installation_guide.md      # Installation Guide
    ├── quick_start.md             # Quick Start
    └── release_notes.md           # Release Notes
    
# Code Directory
protobuf/
├── src/                          # Source code of the C++ runtime and protoc compiler
│   ├── google/protobuf/          # Core runtime library
│   │   ├── compiler/             # Code generator (C++, Java, Python, etc.)
│   │   ├── io/                   # I/O encoding and decoding
│   │   ├── util/                 # Utility classes (JSON conversion, etc.)
│   │   └── ...
│   └── ...
├── java/                         # Java runtime
├── python/                       # Python runtime
├── rust/                         # Rust runtime
├── ruby/                         # Ruby runtime
├── php/                          # PHP runtime
├── csharp/                       # C# runtime
├── objectivec/                   # Objective-C runtime
├── upb/                          # Micro Protobuf C implementation
├── hpb/                          # High-performance C++ binding
├── conformance/                  # Cross-language consistency test
├── benchmarks/                   # Performance benchmark test
├── cmake/                        # CMake configuration file
├── bazel/                        # Bazel build rules
├── third_party/                  # Third-party dependencies
├── docs/                         # Documents
└── BUILD.bazel                   # Bazel build file

Release Notes

For detailed information about feature changes in each Kunpeng-optimized Protobuf release, see Release Notes.

Environment Deployment

For details about the compilation environment, dependency obtaining, and installation procedure of Kunpeng-optimized Protobuf, see Installation Guide.

Quick Start

To quickly get started with Protobuf, see Quick Start.

Documents

NameDescription
Release NotesProvides basic information and feature updates of each version of Kunpeng-optimized Protobuf.
Quick StartProvides quick start examples and compilation instructions for Kunpeng-optimized Protobuf.
API ReferenceProvides descriptions and definitions of APIs related to varint encoding and decoding optimization.
Installation GuideProvides detailed guidance on environment configuration, compilation, and installation of Kunpeng-optimized Protobuf code.

Disclaimer

To Protobuf users

  • This software is intended solely for debugging and development. You are responsible for any risks and should carefully review the following information:

    • This code repository contributes to the Protobuf open-source project solely for performance optimization of certain Protobuf functions on Kunpeng processors. It strictly adheres to the coding style and methods, as well as security design of the native open-source software. Any vulnerability and security issues of the software shall be resolved by the corresponding upstream communities according to their response mechanisms. Please pay attention to the notifications and version updates released by the upstream communities. The Kunpeng computing community does not assume any responsibility for software vulnerabilities and security issues.
    • Data processing and deletion: Users are responsible for managing and deleting any data generated while using this software. Users are advised to delete such data promptly after use to prevent information leakage.
    • Data confidentiality and transmission: Users understand and agree not to share or transmit any data generated by this software. Neither the software nor its developers are responsible for any information leakage, data breaches, or other negative consequences.
    • User input security: Users are responsible for the security of any commands they enter and for any risks or losses resulting from improper input. The software and its developers are not liable for issues caused by incorrect command usage.
  • Disclaimer scope: This disclaimer applies to all individuals and entities using this software. By using the software, you acknowledge and accept this statement and assume all risks and responsibilities arising from its use. If you do not agree, please stop using the software immediately.

  • Before using this software, please read and understand the preceding disclaimer. If you have any questions, contact the developer.

To data owners

If you do not want your dataset to be mentioned in the Protobuf optimization repository, or if you wish to update its description, please submit an issue on GitCode. We will delete or update your description according to your request. Thank you for your understanding and support.

License

Protobuf is licensed under BSD-3-Clause. For details, see LICENSE.

The documents of Protobuf are licensed under CC-BY 4.0. For details, see LICENSE.

Contribution Statement

We welcome your contributions to the community. If you have any questions/suggestions or want to provide feedback on feature requirements and bug reports, you can submit issues. For details, see the contribution guideline. You are also welcome to share insights in the Discussions. Thank you for your support.

Acknowledgments

Protobuf is jointly developed by the following Huawei department:

  • Kunpeng Computing BoostKit Development Dept

Thank you to everyone in the community for your PRs. We warmly welcome contributions to Protobuf!