How to (de)/serialise a third-party library type?

40 views
Skip to first unread message

Lefteris Kotsonis

unread,
Jan 6, 2022, 8:47:39 AM1/6/22
to cereal serialization library
Is there a way to apply serialisation to a type that is provided by a third-party library (i.e. shouldn't be able to modify the class' code) and has non-default constructor?
I have searched the documentation, stack overflow and google group but haven't been able to find something that doesn't solve this with `friend`.

An example class would be:

class ThirdPartyClass
{
public:
    ThirdPartyClass(SomeType a, SomeType b);
     SomeType getA() const;
     SomeType getB() const;
private:
    SomeType a;
    SomeType b;
};

Again, the constraint here is to avoid forking the third party library to befriend cereal, i.e. it should be done with external functions if I understand correctly.

Thanks in advance!

Erich Keane

unread,
Jan 6, 2022, 11:59:53 AM1/6/22
to lefteris...@gmail.com, cere...@googlegroups.com
Without a default constructor, I don't think you can use the normal serialization method, see: "Default Constructor" section at the bottom of this: https://uscilab.github.io/cereal/serialization_functions.html

You should be able to use smart-pointers to these types via the mechanism described here: https://uscilab.github.io/cereal/pointers


--
You received this message because you are subscribed to the Google Groups "cereal serialization library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cerealcpp+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cerealcpp/3bdf2d84-4477-48ad-914a-0aa5c34b0bc0n%40googlegroups.com.

Alessio M

unread,
Jan 7, 2022, 1:54:50 PM1/7/22
to cereal serialization library

template<class T>
struct cereal::LoadAndConstruct< T >

A class that allows cereal to load smart pointers to types that have no default constructor.

Reply all
Reply to author
Forward
0 new messages