Skip to content
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

Deserialize through base class reference? #18

Open
helikopterodaktyl opened this issue May 4, 2018 · 1 comment
Open

Deserialize through base class reference? #18

helikopterodaktyl opened this issue May 4, 2018 · 1 comment

Comments

@helikopterodaktyl
Copy link

I see that there is a sample for serializing through base class reference:

Cereal.registerChildClass!ChildClass;
BaseClass obj = ChildClass(3, 7);
assert(obj.cerealise == [0, 0, 0, 3, 0, 0, 0, 7]);

However, as the assert shows, the derived class name isn't stored anywhere. So when deserializing, you need to know the type anyway. Imagine serializing a BaseClass[]. Some elements of the array are instances of BaseClass, some are instances of ChildClass. Shouldn't in the case of classes an identifier be stored saying what is the real class that is being stored? Something like "assert(obj.cerealise == ["BaseClass", 0, 0, 0, 3, 0, 0, 0, 7]);", so that later on in the code you can do:

Cereal.registerChildClass!ChildClass;
BaseClass obj = datastream.decerealise()

and obj will be actually the ChildClass instance?

@atilaneves
Copy link
Owner

Good point. I added class serialisation mostly for completeness purposes. I wrote cerealed for networking protocols and I can't see how anyone would want to use classes there. I may even have added the serialisation via the base class due to another issue, I don't remember.

This would quite clearly be a bit of work.

@atilaneves atilaneves added the helpwanted Help wanted label May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants