blob: 281f61cb64866ba74fb1351aa5921d045ec3bfe8 [file] [log] [blame]
Deepak Kodihalli6620e982017-08-05 13:09:54 -05001#pragma once
2
3#include <cereal/archives/json.hpp>
4#include <experimental/filesystem>
5#include <fstream>
6#include "config.h"
7
8namespace cereal
9{
10
11namespace fs = std::experimental::filesystem;
12
13using Path = std::string;
14using Interface = std::string;
15
16/** @brief Serialize inventory item
17 *
18 * @param[in] path - DBus object path
19 * @param[in] iface - Inventory interface name
20 * @param[in] object - Object to be serialized
21 */
22template <typename T>
23inline void serialize(const Path& path, const Interface& iface, const T& object)
24{
25 fs::path p(PIM_PERSIST_PATH);
26 p /= path;
27 fs::create_directories(p);
28 p /= iface;
29 std::ofstream os(p, std::ios::binary);
30 cereal::JSONOutputArchive oarchive(os);
31 oarchive(object);
32}
33
34} // namespace cereal