blob: 281f61cb64866ba74fb1351aa5921d045ec3bfe8 [file] [log] [blame]
#pragma once
#include <cereal/archives/json.hpp>
#include <experimental/filesystem>
#include <fstream>
#include "config.h"
namespace cereal
{
namespace fs = std::experimental::filesystem;
using Path = std::string;
using Interface = std::string;
/** @brief Serialize inventory item
*
* @param[in] path - DBus object path
* @param[in] iface - Inventory interface name
* @param[in] object - Object to be serialized
*/
template <typename T>
inline void serialize(const Path& path, const Interface& iface, const T& object)
{
fs::path p(PIM_PERSIST_PATH);
p /= path;
fs::create_directories(p);
p /= iface;
std::ofstream os(p, std::ios::binary);
cereal::JSONOutputArchive oarchive(os);
oarchive(object);
}
} // namespace cereal