8000 Serializing IDs and mapping them back on deserialization · Issue #860 · USCiLab/cereal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Serializing IDs and mapping them back on deserialization #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Placeblock opened this issue Apr 11, 2025 · 0 comments
Open

Serializing IDs and mapping them back on deserialization #860

Placeblock opened this issue Apr 11, 2025 · 0 comments

Comments

@Placeblock
Copy link

I have two structs like that:

struct Inner {
  uint32_t id;
  // Some other data...
};

struct Outer {
  Inner *node;

  template <class Archive> 
  void serialize(Archive &archive) {
    archive(node->id);
  }
};

Now I have a bunch of Outer and Inner Objects.
When serializing the Outer objects, I just serialize the ID of the Inner.
The Serialization of the Inner Objects happens elsewhere.

Now I deserialize the Inner Objects to a map like std::map<uint32_t, Inner*>.
Then I want to deserialize the Outer Objects using Cereal. When deserializing an Outer object, I want to read the ID, look the already deserialized Inner Object up in the map and store it inside the Outer Node. For this I thought an implementation of the load method as mentioned in the documentation could work. This means when deserializing the Outer object I need to have accesss to this map. I do not want the Map to be static. Is there another way to give the deserializer this "context"? Are there other ways to acomplish my goal? Maybe my approach is totally wrong?

Appreciate your time, have a great day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0