You can create your own Archive
classes and then specialize the serialize()
function template for your classes:
template<>
void serialize(MyBriefOutputArchive& ar, const unsigned int version) {
// Alternative serialization.
}
template<>
void serialize(MyBriefInputArchive& ar, const unsigned int version) {
// Alternative deserialization.
}
To make your own archive classes, you can subclass or copy the Boost classes so they otherwise work identically. Be careful because some archive classes, like boost::binary_oarchive
and boost::binary_iarchive
, have header comments that say they shouldn't be subclassed - you should copy their implementation instead (which is simple as all the work is done in their superclass).
If you use some template meta-programming tricks, you can recognize your own archive class within the generic serialize()
without the need for specializations. This would be preferred under the DRY principle, but it might be easier to get things working with specializations first.