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