Question

Is there any way to remove the extra 6 bytes that are put in the begin of the serialization data when serializing with Boost Serialization ? I just want to use the serialization mechanism, I don't want any version, object tracking or any other header information.

Was it helpful?

Solution

I solved my problem using the implementation level:

BOOST_CLASS_IMPLEMENTATION(MyClass, boost::serialization::object_serializable);

By doing this, the serialization will not include the version in front of the raw serialized data.

OTHER TIPS

If you want to omit version information for all classes (resulting in a more space efficient, but less robust archive), you can combine the BOOST_CLASS_IMPLEMENTATION macro with the default behavior:

namespace boost {
namespace serialization {
template <class T>
struct implementation_level_impl< const T >
{
    template<class U>
    struct traits_class_level {
        typedef BOOST_DEDUCED_TYPENAME U::level type;
    };

    typedef mpl::integral_c_tag tag;

    typedef
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
            is_base_and_derived<boost::serialization::basic_traits, T>,
            traits_class_level< T >,
        //else
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
            is_fundamental< T >,
            mpl::int_<primitive_type>,
        //else
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
            mpl::or_<is_class< T >, is_array< T> >,
            mpl::int_<object_serializable>,
        //else
        BOOST_DEDUCED_TYPENAME mpl::eval_if<
            is_enum< T >,
                mpl::int_<primitive_type>,
        //else
            mpl::int_<not_serializable>
        >
        >
        >
        >::type type;
    BOOST_STATIC_CONSTANT(int, value = type::value);
};
}
}

Use both:

BOOST_CLASS_IMPLEMENTATION( , boost::serialization::object_serializable ) BOOST_CLASS_TRACKING( , boost::serialization::track_never )

in this order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top