Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]
From: Robert Ramey (ramey_at_[hidden])
Date: 2009-05-31 02:32:51


Sohail Somani wrote:
> Robert Ramey wrote:
>> Sohail Somani wrote:
>>> Robert Ramey wrote:
>>>> Sohail Somani wrote:
>>>>
>>>>> Boost serialization currently does not elegantly handle forward
>>>>> compatibility
>>>> This would be doable if someone wanted to invest the effort. And
>>>> this would not be a huge effort at least in comparison to
>>>> the efforts required to implement a lot of the other features of
>>>> the library.
>>> How would this be done (without breaking backward compatibility)? It
>>> is kind of late so admittedly it might be totally obvious in the
>>> morning.
>>>
>>> I also notice you have not mentioned anything about the 70 billion
>>> dollar bailout for the serialization library and spreading the
>>> wealth. I assume the cheque's in the mail.
>>
>> I purposely overlooked that comment. It seemed to be an
>> attempt at some sort of criticism. It's absolutely amazing to
>> me how much I've been criticised (many times personally)
>> for making this library. I choose to interpret this as
>> acknowledgement (and perhaps resentment) of its success. It's my
>> policy
>> to ignore such comments which almost always results
>> in the least amount of time wasted. Occasionally this
>> doesn't work so I have to waste more time. But generally
>> this policy works well for me.
>
> Just to clarify, my comments were meant as a joke so I apologize if
> you were offended.
>
> Still interested in forward compatibility, if you are inclined to
> elaborate a little.

Here we go. Basically, backward compatibility is handled by code
that looks like the following:

template<class Archive>
void save(Archive &ar, const unsigned int version){
    ar << original_stuff
    ar << stuff_added_version_3;
    ar << stuff_added_version_4;
}

template<class Archive>
void load(Archive &ar, const unsigned int version){
    ar >> original_stuff;
    if(version > 3)
        ar >> stuff_added_version_3;
    if(version > 4)
        ar >> stuff_added_version_4;
    ...
}

So what we need to do is replace the save above with:

template<class Archive>
void save(Archive &ar, const unsigned int version) const {
    ar << original_stuff
    if(version > 3)
        ar << stuff_added_version_3;
    if(version > 4)
        ar << stuff_added_version_4;
}

So that would be fine. Right now version for class T is set with

BOOST_CLASS_VERSION(T, 4)

To generate an original version of the archive "just" use

BOOST_CLASS_VERSION(T, 0)

So we're almost there. To make a "real" system you
need to use something like:

BOOST_CLASS_VERSION(T, VERSION(T, date))

where VERSION is macro which retures the version
used as of the given date (or someother "global" versioning
scheme).. This would be implemented
as some sort of new header to implement this facility.
This might not be the exact implemenation, perhaps
a variation of BOOST_CLASS_VERSION would have
to be implened - whatever. The real point is that this
would require very little - if any - changes to the "guts"
of the library.

Robert Ramey


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net