Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]
From: Sohail Somani (sohail_at_[hidden])
Date: 2009-05-31 23:24:27


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.

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?

-- 
Sohail Somani
http://uint32t.blogspot.com

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