Custom archive type

76 views
Skip to first unread message

Vadim

unread,
Jan 7, 2021, 7:29:58 PM1/7/21
to cereal serialization library
Hi,
I would like implement serialization of raw pointers in Cereal (in some restricted cases).   I am porting this code from another library, so I know how to implement it, however I am not sure how to fit it into Cereal API.

What I've tried so far:
1. Derived a class from from BinaryOutputArchive, which tracks extra data needed to serialize pointers.  It also exposes serializePointer and deserializePointer methods.
2. Defined load/save functions for pointers.
(code is attached)

Unfortunately, this fails to compile:
cereal_test.cpp:46:13: error: 'class cereal::BinaryOutputArchive' has no member named 'serializePointer'; did you mean 'serializeDeferments'?
     archive.serializePointer(bar.foo);

Looks like references to my class are getting downcast to BinaryOutputArchive?   Is there something else I need to do in order to register a new archive type?


The other issue I am hitting (if I don't invoke serializePointer() and try to use load/save specializations for pointers) is that Cereal seems to be asserting that raw pointers are not serialized:
common.hpp:114:5: error: static assertion failed: Cereal does not support serializing raw pointers - please use a smart pointer

Can this assert be suppressed without modifying Cereal's source?   I can continue using custom methods of course, but it would be nice if users didn't need to special-case pointers when writing serialize() for their data types.

Thanks!

cereal_test.cpp
Reply all
Reply to author
Forward
0 new messages