Boost序列化:归档“不支持的版本”例外

发布于 2024-11-07 15:10:15 字数 138 浏览 3 评论 0原文

当我尝试通过文本存档反序列化之前使用较高版本的 Boost(1.46 序列化和 1.38 反序列化)序列化的一些数据时,出现异常“不支持的版本”...是否存在降级(在代码中)序列化的方法?

像“set_library_version”之类的东西?

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"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡忘如思 2024-11-14 15:10:15

请参阅读取旧 Boost 版本创建的二进制存档时出错< /em> 关于序列化错误的邮件存档帖子。

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

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

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);
            }
}
你丑哭了我 2024-11-14 15:10:15

使用 text_archive ...我最近也遇到了一个问题。
我最近在Windows上将boost从1.67升级到1.72,在Windows上生成了一些数据。当我在仍使用 Boost 1.67 的 Linux 环境上运行数据时,它会抛出不支持

1.67 的标题看起来像这样

22 serialization::archive 16

,1.72 看起来像

22 serialization::archive 17

我将 17 更改为 16,它对我的​​用例很满意。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文