有人可以向我解释一下 Boost 序列化中的版本控制是如何工作的。存档版本始终为 10,类版本始终为 0。我认为当存档与上一版本不同时,版本会自动递增。如果我更改了某些内容,我是否必须自己定义版本号?
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="10">
<EventSet class_id="0" tracking_level="0" version="0">
<Size>1</Size>
<Event>
...
</Event>
</EventSet>
</boost_serialization>
文档中没有描述它,但boost_serialization signature="serialization::archive" version="10"
对应于 Boost.Archive 库版本的行,当新版本的 Boost 可用时,它有时会发生变化。
正如文档所解释的那样,EventSet class_id="0" tracking_level="0" version="0"
行对应于类版本。您可以在代码中使用宏"BOOST_CLASS_VERSION(EventSet, 1("更改它。
扩展Michael的答案,boost存档版本取决于您的boost版本,并且每当对输出格式进行一些有意义的更改时都会被撞到。在 https://github.com/boostorg/serialization/blob/develop/src/basic_archive.cpp 的 boost 序列化 git src/basic_archive.cpp
,有一条评论解释了这些版本 在撰写本文时,以下内容如下:
// this should change if the capabilities are added to the library
// such that archives can be created which can't be read by previous
// versions of this library
// 1 - initial version
// 2 - made address tracking optional
// 3 - numerous changes - can't guarantee compatibility with previous versions
// 4 - Boost 1.34
// added item_version to properly support versioning for collections
// 5 - Boost 1.36
// changed serialization of collections: adding version even for primitive
// types caused backwards compatibility breaking change in 1.35
// 6 - Boost 1.41 17 Nov 2009
// serializing collection sizes as std::size_t
// 7 Boost 1.42 2 Feb 2010
// error - changed binary version to 16 bits w/o changing library version #
// That is - binary archives are recorded with #6 even though they are
// different from the previous versions. This means that binary archives
// created with versions 1.42 and 1.43 will have to be fixed with a special
// program which fixes the library version # in the header
// Boost 1.43 6 May 2010
// no change
// 8 - Boost 1.44
// separated version_type into library_version_type and class_version_type
// changed version_type to be stored as 8 bits.
// 10- fixed base64 output/input.
// 11- not changes
// 12- improved serialization of collections
// 13- simplified visibility, removed Borland, removed pfto
// 14- improved visibility, refactor map/set
// 15- corrections to optional and collection loading
// 16- eliminated dependency on <codecvt> which is buggy in some libraries
// and now officially deprecated in the standard
// 17- Boost 1.68 August 2018
// 18- addressed undefined behavior in archive constructors.
// init() called from base wrote archive header before archive
// was fully constructed.