Deepak Kodihalli | 6620e98 | 2017-08-05 13:09:54 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <cereal/archives/json.hpp> |
| 4 | #include <experimental/filesystem> |
| 5 | #include <fstream> |
| 6 | #include "config.h" |
| 7 | |
| 8 | namespace cereal |
| 9 | { |
| 10 | |
| 11 | namespace fs = std::experimental::filesystem; |
| 12 | |
| 13 | using Path = std::string; |
| 14 | using 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 | */ |
| 22 | template <typename T> |
| 23 | inline 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 |