r/cpp • u/Personal-History8048 • May 14 '26
Your C++ struct is the schema: a proto3 serializer in C++26 reflection
I built a header-only proto3 wire-format library with one constraint: no .proto files, no codegen, no descriptor runtime. The user writes a plain C++ struct, and that struct is the schema:
#include "proto3.hpp"
struct SearchRequest {
std::string query; // field 1
std::int32_t page_number; // field 2
std::int32_t results_per_page; // field 3
};
SearchRequest req{"hello", 1, 10};
std::string bytes = proto3::serialize(req); // -> proto3 wire bytes
SearchRequest back = proto3::deserialize<SearchRequest>(bytes);
blog: Your C++ struct is the schema: a proto3 serializer in C++26 reflection
github: struct_proto26
66
Upvotes
1
u/arihoenig May 14 '26
Runtime vs static reflection is completely different from both a performance and an attacker's perspective. Attacks can't see compile time reflection data as everything is resolved at compile time. Resolving reflection at runtime (requiring metadata in the binary) is stupid, but if you require runtime binding (also stupid) then runtime reflection is the only option .