Protocol Buffers 35.1 (the C++ runtime), through C++23 modules.
English · 简体中文 · Upstream · Releases · mcpp · Index
The upstream C++ API is unchanged: google::protobuf::Message, DescriptorPool,
util::MessageDifferencer, Timestamp are the upstream entities. The library is
compat.protobuf 35.1 over compat.abseil 20250512.1, built from the releases, and the
codegen feature adds protoc, built for the build machine from the same release, with
protogen, a build rule that generates the code of every .proto during the build.
import mcpplibs.mwrap.protobuf;: messages, descriptors, reflection, arenas, repeated fields, maps, text format, the well-known types; re-exports the modules belowimport mcpplibs.mwrap.protobuf.io;: coded and zero-copy streams, the tokenizerimport mcpplibs.mwrap.protobuf.util;: JSON (json::),MessageDifferencer,TimeUtil,FieldMaskUtil, delimited messagesimport mcpplibs.mwrap.protobuf.compiler;: parsing.protofiles at run time (Importer,Parser)import mcpplibs.mwrap.protobuf.io.gzip;:GzipInputStream,GzipOutputStream(featuregzip)
More Modules API -> Usage · every exported name
mcpp new people --template mcpplibs.mwrap.protobuf@35.1
cd people
mcpp runThe default template describes a message type at run time and uses it through reflection:
wire bytes, text and JSON, then Timestamp arithmetic, Struct and Any — no protoc. With
--template mcpplibs.mwrap.protobuf@35.1:codegen, proto/addressbook.proto is compiled by
protoc during the build and the generated classes are used with the module.
[dependencies]
mcpplibs.mwrap.protobuf = { version = "35.1", features = ["codegen"] }// build.mcpp
import mcpp;
import protogen;
int main() { return protogen::generate_all() ? 0 : 1; }// src/main.cpp: includes first (the prelude, then generated headers), imports after
#include <mwrap/protobuf/prelude.hpp>
#include "addressbook.pb.h"
import std;
import mcpplibs.mwrap.protobuf;| Feature | Purpose |
|---|---|
codegen |
protoc for the build machine, from the same release, and the protogen rule (not on Windows: protoc is not built there) |
gzip |
GzipInputStream / GzipOutputStream over compat.zlib, import mcpplibs.mwrap.protobuf.io.gzip; |
upb |
protobuf's C runtime from the same release, as gRPC links it (one protobuf in a program with both) |
protobuf's API takes and returns Abseil types (absl::Status, absl::string_view, which
is std::string_view); this package exports no absl name. To name them, import
mcpplibs.mwrap.abseil or include the Abseil header. With GCC every #include of a
translation unit comes before its first import; one that includes generated headers
includes <mwrap/protobuf/prelude.hpp> first. The version macros are constants in
mcpplibs::mwrap::protobuf::macros; GOOGLE_PROTOBUF_VERIFY_VERSION and the other
macros come from <mwrap/protobuf/macros.hpp>.
CI on Linux (x86_64, aarch64; GCC 16 and LLVM 23), macOS and Windows builds the modules
and runs the tests in the dev and release profiles: wire bytes, text and JSON round trips,
the well-known types, MessageDifferencer and FieldMaskUtil, coded and delimited streams,
a .proto parsed at run time, every macro mapping, header mixing; the gzip feature; and
code generation through protogen (not on Windows). The Web row runs the tests as
wasm32 under node. The export audit derives the record again from the headers on the
Linux LLVM row. A separate job scaffolds both templates as an installed package and runs
them.
Apache-2.0 for the wrapper, by mcpp-community (NOTICE). Protocol Buffers remains under the BSD 3-Clause License (upstream/protobuf/LICENSE, README), utf8_range under MIT (upstream/utf8_range/LICENSE), and Abseil, which it links, under Apache-2.0 (upstream/abseil-cpp/LICENSE).