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