Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 1 | #include <cereal/types/string.hpp> |
| 2 | #include <cereal/types/vector.hpp> |
| 3 | #include <cereal/types/tuple.hpp> |
| 4 | #include <cereal/archives/binary.hpp> |
| 5 | #include <fstream> |
| 6 | #include "elog_serialize.hpp" |
| 7 | |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace logging |
| 11 | { |
| 12 | |
| 13 | fs::path serialize(const Entry& e, const fs::path& dir) |
| 14 | { |
| 15 | auto path = dir / std::to_string(e.id()); |
| 16 | std::ofstream os(path.c_str(), std::ios::binary); |
| 17 | cereal::BinaryOutputArchive oarchive(os); |
| 18 | oarchive(e); |
| 19 | return path; |
| 20 | } |
| 21 | |
| 22 | bool deserialize(const fs::path& path, Entry& e) |
| 23 | { |
| 24 | if (fs::exists(path)) |
| 25 | { |
| 26 | std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); |
| 27 | cereal::BinaryInputArchive iarchive(is); |
| 28 | iarchive(e); |
| 29 | return true; |
| 30 | } |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | } // namespace logging |
| 35 | } // namespace phosphor |