提升序列化:归档“不支持的版本”异常

问题描述 投票:5回答:1

当我尝试通过文本存档反序列化一些以前使用Boost的高级版本(1.46序列化和1.38反序列化)序列化的数据时,我得到了“不支持的版本”的例外...有没有办法降级(在代码)序列化?

像“set_library_version”之类的东西?

serialization boost archive
1个回答
5
投票

有关序列化错误,请参阅Error read binary archive, created by old Boost version邮件存档文章。

它说下面的代码完成了这项工作:

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);
            }
}
© www.soinside.com 2019 - 2024. All rights reserved.