cereal
cereal copied to clipboard
feature: named variants in json serialization
Hello,
I made some changes to how variants are represented in json for my use case and putting it here in case you would also find it useful.
example output:
- g++ --std=c++17 m.cpp
{
"value0": {
"variant": {
"index": 0,
"data": {
"id": 5
}
}
}
}
- g++ -DCEREAL_NAMED_VARIANT --std=c++17 m.cpp
{
"value0": {
"variant": {
"type": "LoadInstrument",
"LoadInstrument": {
"id": 5
}
}
}
}
code example: https://gist.github.com/miartad/3b290142284a4bed0a8c1736d9cc62ed
As discussed in another pull request, this is problematic since std::variant
allows for the same type to exist multiple times. So this makes no sense in general.
are variants with multiples of same types supported by cereal? in my test these types of variants do not compile with cereal.