boost::archive::xml_oarchive 中的 class_id
XML 序列化是否可以使用更人性化的 class_id 作为 GUID,使用 BOOST_CLASS_EXPORT_GUID
进行描述???
考虑序列化类:
SomeClass* b=new SomeClass("c");
{
boost::archive::xml_oarchive oa(cout);
oa.register_type<SomeClass>();
oa << boost::serialization::make_nvp("b",b);
}
输出将类似于:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="5">
<b class_id="0" tracking_level="1" version="0" object_id="_0">
<name>c</name>
</b>
</boost_serialization>
当您删除 class_id="0" 时,这不会反序列化。 我更喜欢 class_id="SomeClass" 或类似的东西。
Is it possible for XML serialization to use more human friendly class_id as GUID, described using BOOST_CLASS_EXPORT_GUID
???
Consider serializing class:
SomeClass* b=new SomeClass("c");
{
boost::archive::xml_oarchive oa(cout);
oa.register_type<SomeClass>();
oa << boost::serialization::make_nvp("b",b);
}
Output will be like:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="5">
<b class_id="0" tracking_level="1" version="0" object_id="_0">
<name>c</name>
</b>
</boost_serialization>
When you remove class_id="0" this will not deserialize. I would prefer class_id="SomeClass" or something similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,解决方案是将您的类序列化为名称值对。 请参阅 boost 文档中的此项 。
如果您想要两种不同的行为,则必须实现它们。 尝试使用模板专业化:
默认情况下,object_id_type 是 unsigned int (basic_archive.hpp)。 如果您想要不同的东西,您需要实现自己的存档类。
Yes, the solution is to serialize your class in a name-value-pair. See this item at boost documentation.
If you want two diferent behaviours, you will have to implement them. Try with template specialization:
By default object_id_type is unsigned int (basic_archive.hpp). If you want something diferent you need to implement your own archive class.