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档案。