#include "manager_serialize.hpp" #include #include #include #include #include #include #include #include #include namespace bios_config { /** @brief Function required by Cereal to perform serialization. * * @tparam Archive - Cereal archive type (binary in this case). * @param[in] archive - reference to cereal archive. * @param[in] entry- const reference to bios manager object * @param[in] version - Class version that enables handling a serialized data * across code levels */ template void save(Archive& archive, const Manager& entry, const std::uint32_t /*version*/) { archive(entry.sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager:: baseBIOSTable(), entry.sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager:: pendingAttributes()); } /** @brief Function required by Cereal to perform deserialization. * * @tparam Archive - Cereal archive type (binary in our case). * @param[in] archive - reference to cereal archive. * @param[out] entry - reference to bios manager object * @param[in] version - Class version that enables handling a serialized data * across code levels */ template void load(Archive& archive, Manager& entry, const std::uint32_t /*version*/) { Manager::BaseTable baseTable; Manager::PendingAttributes pendingAttrs; archive(baseTable, pendingAttrs); entry.sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager:: baseBIOSTable(baseTable, true); entry.sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager:: pendingAttributes(pendingAttrs, true); } void serialize(const Manager& obj, const fs::path& path) { std::ofstream os(path.c_str(), std::ios::out | std::ios::binary); cereal::BinaryOutputArchive oarchive(os); oarchive(obj); } bool deserialize(const fs::path& path, Manager& entry) { try { if (fs::exists(path)) { std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); cereal::BinaryInputArchive iarchive(is); iarchive(entry); return true; } return false; } catch (cereal::Exception& e) { lg2::error("Failed to serialize: {ERROR}", "ERROR", e); fs::remove(path); return false; } catch (const std::length_error& e) { lg2::error("Failed to serialize: {ERROR}", "ERROR", e); fs::remove(path); return false; } } } // namespace bios_config