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-06-01 00:46:31


Sohail Somani wrote:
> Robert Ramey wrote:
>> Sohail Somani wrote:
>>> 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;
>> }
>
> Just typing out loud: Forward compatibility is the ability to load an
> archive with a version of 4 into an application with a version of 3.

To me forward compatability is he ability to create a version 3 archive
with a version 4 program. Hmmm - now that I read that, it doesn't
look right. I guess that should be called "complete" backward
compatibility. I don't see how it is possible while writing version
3 progam to know what version 4 is going to save.

>
> So if we have std::vector<SomeClass> and in version 4, I add an int to
> SomeClass, I'm pretty sure it would cause the whole thing to go boom
> when loading an archive from version 4 into version 3.
>
> I'm not sure if the above avoids this problem, does it?


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