cereal序列库学习记录

cereal 序列化库使用要点

1. 序列化格式

#include <cereal/archives/binary.hpp>
#include <cereal/archives/portable_binary.hpp>
#include <cereal/archives/xml.hpp>
#include <cereal/archives/json.hpp>

2. 支持STL标准数据格式

#include <cereal/types/xxxx.hpp>

已支持如下格式:
在这里插入图片描述

3. 序列化文档

3.1 二进制文件Binary

#include <cereal/archives/binary.hpp>

The binary archive is also the fastest archive that comes with cereal. Binary archives will ignore name-value pairs and only serialize the values.
When using a binary archive and a file stream (std::fstream), remember to specify the binary flag (std::ios::binary) when constructing the stream.

二进制存档是cereal中速度最快的序列化档案方式,其值存储数值,忽略名称信息。当使用文件流时,需使用std::ios::binary模式。如果需要考虑大小端的差异,需要使用<cereal/archives/portable_binary.hpp>。

3.2 XML格式文件

#include <cereal/archives/xml.hpp>

If you need to have binary equality between floating point numbers, you will need a significant precision for the output (on the order of 10 for floats, 20 for doubles, 40 for long doubles). cereal will use the largest number of digits appropriate for serializing a double by default.

浮点数序列化操作是需指定具体的精度信息,否则按照double类型来默认处理。
3.3 JSON格式文件

#include <cereal/archives/json.hpp>

具体方式同XML档案。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值