Re:Why Rust helps even if you have to use a lot of `unsafe`
by gpderetta on Wednesday August 02, 2023 @11:58AM
(#36972662)
FWIW using std::variant (or whatever is your in-house variant) to store message types is very common.
Also in well designed low level binary protocols message types have a discriminant header already so often common to wrap them in an ad hoc-variant which doesn't have a separate discriminant.
I haven't seen anything in C++ that's both as easy and as airtight as a Rust enum with serde's automatic serialization macro on the top.