bitsery
bitsery copied to clipboard
How to serializate and deserializate std::vector<std::any> or std::vector<std::variant> ?
Hi,
Variant serialization is straightforward. An example of how different variant types are handled is provided here. To serialize vector of variants you need to use lambda overload for container method. The easiest way is probably to define serialize function for your variant, then it could look like this:
using MyVariant = std::variant<int64_t, MyTuple, MyStruct>;
...
template <typename S>
void serialize(S& s, MyVariant& obj) {
...
}
...
ser.container(obj, [](S& s, MyVariant& data) { s.ext(data, bitsery::ext::StdVariant{});});
As for std::any it's worse... there is no extension for it, so for the moment, you need to it write your self.