Enable Cereal class versioning
Cereal class versioning helps to handle data de-serialization
across different class versions that differ in the way, a particular
data is serialized.
For more reading, refer Cereal official documentation;
http://uscilab.github.io/cereal/serialization_functions.html
Change-Id: Ic5d01090b7a7679ef2bf638da786abbd033007bc
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/configure.ac b/configure.ac
index 28f51ae..49bc3dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -69,5 +69,9 @@
AC_CHECK_HEADER(sdbusplus/server.hpp, ,[AC_MSG_ERROR([Could not find sdbusplus/server.hpp...openbmc/sdbusplus package required])])
AC_CHECK_HEADER(phosphor-logging/log.hpp, ,[AC_MSG_ERROR([Could not find phosphor-logging/log.hpp...openbmc/phosphor-logging package required])])
+AC_ARG_VAR(CLASS_VERSION, [Class version to register with Cereal])
+AS_IF([test "x$CLASS_VERSION" == "x"], [CLASS_VERSION=1])
+AC_DEFINE_UNQUOTED([CLASS_VERSION], [$CLASS_VERSION], [Class version to register with Cereal])
+
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 8debe8a..884372d 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -16,6 +16,8 @@
#include "host_state_manager.hpp"
#include "config.h"
+// Register class version with Cereal
+CEREAL_CLASS_VERSION(phosphor::state::manager::Host, CLASS_VERSION);
namespace phosphor
{
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index 35a4bdd..6b5e97e 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -4,6 +4,7 @@
#include <functional>
#include <experimental/filesystem>
#include <cereal/access.hpp>
+#include <cereal/cereal.hpp>
#include <sdbusplus/bus.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
@@ -184,9 +185,11 @@
*
* @tparam Archive - Cereal archive type (binary in our case).
* @param[in] archive - reference to Cereal archive.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
*/
template<class Archive>
- void save(Archive& archive) const
+ void save(Archive& archive, const std::uint32_t version) const
{
archive(convertForMessage(sdbusplus::xyz::openbmc_project::
State::server::Host::
@@ -203,9 +206,11 @@
*
* @tparam Archive - Cereal archive type (binary in our case).
* @param[in] archive - reference to Cereal archive.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
*/
template<class Archive>
- void load(Archive& archive)
+ void load(Archive& archive, const std::uint32_t version)
{
std::string reqTranState;
std::string bootProgress;