Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 1 | #include "dump_serialize.hpp" |
| 2 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 3 | #include <cereal/archives/binary.hpp> |
| 4 | #include <cereal/types/set.hpp> |
| 5 | #include <fstream> |
| 6 | #include <phosphor-logging/log.hpp> |
| 7 | |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 8 | namespace phosphor |
| 9 | { |
| 10 | namespace dump |
| 11 | { |
| 12 | namespace elog |
| 13 | { |
| 14 | |
Jayanth Othayoth | e4693a7 | 2017-09-20 00:01:23 -0500 | [diff] [blame] | 15 | using namespace phosphor::logging; |
| 16 | |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 17 | void serialize(const ElogList& list, const fs::path& dir) |
| 18 | { |
| 19 | std::ofstream os(dir.c_str(), std::ios::binary); |
| 20 | cereal::BinaryOutputArchive oarchive(os); |
| 21 | oarchive(list); |
| 22 | } |
| 23 | |
| 24 | bool deserialize(const fs::path& path, ElogList& list) |
| 25 | { |
Jayanth Othayoth | e4693a7 | 2017-09-20 00:01:23 -0500 | [diff] [blame] | 26 | try |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 27 | { |
Jayanth Othayoth | e4693a7 | 2017-09-20 00:01:23 -0500 | [diff] [blame] | 28 | if (fs::exists(path)) |
| 29 | { |
| 30 | std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); |
| 31 | cereal::BinaryInputArchive iarchive(is); |
| 32 | iarchive(list); |
| 33 | return true; |
| 34 | } |
| 35 | return false; |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 36 | } |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 37 | catch (cereal::Exception& e) |
Jayanth Othayoth | e4693a7 | 2017-09-20 00:01:23 -0500 | [diff] [blame] | 38 | { |
| 39 | log<level::ERR>(e.what()); |
| 40 | fs::remove(path); |
| 41 | return false; |
| 42 | } |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | } // namespace elog |
| 46 | } // namespace dump |
| 47 | } // namespace phosphor |