Need multiple deserializers for same type

19 views
Skip to first unread message

Dilip Simha

unread,
Mar 29, 2021, 8:50:29 PM3/29/21
to cereal serialization library
I use cereal to load and save a particular data type, let's say "class T1 { int a; int b;};"
The json file is something like:
```
{
...
...
"10" : {
  ...
  "a" : "100",
  "b" : "200",
  ....
  }
...
}
```
I use the deserializer:

cereal::JSONInputArchive *my_file = ....;

*my_file >> cereal::make_nvp(std::to_string(i), t1);


```cpp
template<class Archive>
load(Archive &ar, T1 &t1, std::uint32_t const version) 
{
....
    ar(CEREAL_NVP(a));
    ar(CEREAL_NVP(b));
....
}

```
I wish to have another deserializer that only deserializes b and skips everything else.

```cpp
template<class Archive>
load(Archive &ar, T1 &t1, std::uint32_t const version) 
{
    ar(CEREAL_NVP(b));
}

```
How do I do this ?
My real use-case type T1 has hundreds/thousands of variables and hence I can't afford to deserialize everything.
Reply all
Reply to author
Forward
0 new messages