Boost serialization: archive “unsupported version” exception

后端 未结 2 818
执笔经年
执笔经年 2021-01-18 09:37

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

相关标签:
2条回答
  • 2021-01-18 10:38

    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.

    0 讨论(0)
  • 2021-01-18 10:39

    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);
                }
    }
    
    0 讨论(0)
提交回复
热议问题