7

I've got the exception "unsupported version" when I try to deserialize through a text archive some data previously serialized with a upper version of Boost (1.46 to serialize and 1.38 to deserialize)...is there a way to downgrade (in the code) the serialization?

Something like "set_library_version"?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
marco
  • 295
  • 3
  • 13

2 Answers2

6

See the Error read binary archive, created by old Boost version mail archive post about the serialization error.

It says that the code below does the job:

void load_override(version_type & t, int version){

    library_version_type lvt = this->get_library_version();
    if (boost::archive::library_version_type(7) < lvt){
        this->detail_common_iarchive::load_override(t, version);
    }
    else
        if (boost::archive::library_version_type(6) < lvt){
            uint_least16_t x = 0;
            * this->This() >> x;
            t = boost::archive::version_type(x);
        }
        else
            if (boost::archive::library_version_type(3) == lvt ||
                boost::archive::library_version_type(5) == lvt){

                #pragma message("CTMS fix for serialization bug (lack of backwards compatibility) introduced by Boost 1.45.")
                // Up to 255 versions
                unsigned char x = 0;
                * this->This() >> x;
                t = version_type(x);
            }
            else{
                unsigned int x = 0;
                * this->This() >> x;
                t = boost::archive::version_type(x);
            }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
O.C.
  • 6,711
  • 1
  • 25
  • 26
  • first of all, thanks for your reply...but actually I don't use load/save function, but a unique function called serialize...like the boost serialization example...how can I do? – marco May 16 '11 at 13:02
  • The link talks about that. It says that backward compatibility is broken "Prior to 1.44 the archive version was written as "one byte". Starting with 1.44 archive version type changed from 'version_type' to 'library_version_type' and is expected to be read as two bytes. " Read the link careful and recompile using the the code that i pasted. i think this is the only solution. – O.C. May 16 '11 at 13:29
2

Using text_archive ... I had a recent issue with this also. I recently upgraded boost from 1.67 to 1.72 on Windows, generated some data on Windows. When I ran the data on my Linux environment which is still on Boost 1.67, it throws not supported.

The header for 1.67 looked like this

22 serialization::archive 16

and 1.72 looked like

22 serialization::archive 17

I changed 17 to 16 and it was happy for my use case.

denn
  • 350
  • 3
  • 4
  • 1
    Erm. Only do this as a data recovery hack. You are risking undefined behaviour (in fact, you're already in unspecified territory, it's just luck that it looks like it still does something sensible. Please iff you must do this, run with ASAN/UBSAN and triple-check the results) – sehe Mar 30 '21 at 22:52