1 #include "dump_serialize.hpp" 2 3 #include <cereal/archives/binary.hpp> 4 #include <cereal/types/set.hpp> 5 #include <phosphor-logging/lg2.hpp> 6 7 #include <fstream> 8 9 namespace phosphor 10 { 11 namespace dump 12 { 13 namespace elog 14 { 15 16 void serialize(const ElogList& list, const std::filesystem::path& dir) 17 { 18 std::ofstream os(dir.c_str(), std::ios::binary); 19 cereal::BinaryOutputArchive oarchive(os); 20 oarchive(list); 21 } 22 23 bool deserialize(const std::filesystem::path& path, ElogList& list) 24 { 25 try 26 { 27 if (std::filesystem::exists(path)) 28 { 29 std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); 30 cereal::BinaryInputArchive iarchive(is); 31 iarchive(list); 32 return true; 33 } 34 return false; 35 } 36 catch (const cereal::Exception& e) 37 { 38 lg2::error("Failed to deserialize, errormsg: {ERROR}", "ERROR", e); 39 std::filesystem::remove(path); 40 return false; 41 } 42 } 43 44 } // namespace elog 45 } // namespace dump 46 } // namespace phosphor 47