1 #include "dump_serialize.hpp" 2 3 #include <cereal/archives/binary.hpp> 4 #include <cereal/types/set.hpp> 5 #include <fstream> 6 #include <phosphor-logging/log.hpp> 7 8 namespace phosphor 9 { 10 namespace dump 11 { 12 namespace elog 13 { 14 15 using namespace phosphor::logging; 16 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 { 26 try 27 { 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; 36 } 37 catch (cereal::Exception& e) 38 { 39 log<level::ERR>(e.what()); 40 fs::remove(path); 41 return false; 42 } 43 } 44 45 } // namespace elog 46 } // namespace dump 47 } // namespace phosphor 48