Boost 序列化:存档“不支持的版本"例外 [英] Boost serialization: archive "unsupported version" exception

查看:34
本文介绍了Boost 序列化:存档“不支持的版本"例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过文本存档反序列化一些先前使用 Boost 的上层版本(1.46 进行序列化,1.38 进行反序列化)序列化的数据时,我遇到了异常不受支持的版本"..有没有办法降级(在代码中)序列化?

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?

类似于set_library_version"的东西?

Something like "set_library_version"?

推荐答案

错误读取二进制存档,由旧 Boost 版本创建 关于序列化错误的邮件存档帖子.

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);
            }
}

这篇关于Boost 序列化:存档“不支持的版本"例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆