r/cpp • • 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

70 Upvotes

52 comments sorted by

View all comments

Show parent comment

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 .

0

u/[deleted] May 15 '26

[deleted] — view deleted comment

2

u/arihoenig May 15 '26

First or all, yes you are very confused.

Runtime (late) binding is not loading a dll, that is runtime linking late binding or runtime binding is looking up the code to be called on every call (linking established that linkage just once).

Also, at no point did I say that runtime reflection is needed to create a cheat, I said it makes creating a cheat much easier because the metadata that is necessary to support runtime reflection makes reversing trivial. You can still reverse if there is no runtime reflection, but it is much more tedious to document all the data structures as there is not a label for every member name.

...and yes, you can do late binding using some other specific mechanism, but if you want to do late binding for some insane reason, then that is a legitimate time to use runtime reflection.

0

u/[deleted] May 15 '26

[deleted] — view deleted comment

1

u/arihoenig May 15 '26

I didn't say you did need runtime reflection to do it I said it was the only legitimate use for runtime reflection

1

u/Chaosvex May 15 '26

I think you've been arguing with somebody that holds some confused ideas of reflection, to be fair. I've done a whole lot of game reverse engineering and development yet still can't follow what their point is supposed to be.