blob: 13a8b7e28ef348739286542801aced92b59efba6 [file] [log] [blame]
Jayanth Othayoth24964822017-09-04 22:07:06 -05001#include <cereal/types/set.hpp>
2#include <cereal/archives/binary.hpp>
3#include <fstream>
4
Jayanth Othayothe4693a72017-09-20 00:01:23 -05005#include <phosphor-logging/log.hpp>
6
Jayanth Othayoth24964822017-09-04 22:07:06 -05007#include "dump_serialize.hpp"
8
9namespace phosphor
10{
11namespace dump
12{
13namespace elog
14{
15
Jayanth Othayothe4693a72017-09-20 00:01:23 -050016using namespace phosphor::logging;
17
Jayanth Othayoth24964822017-09-04 22:07:06 -050018void 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
25bool deserialize(const fs::path& path, ElogList& list)
26{
Jayanth Othayothe4693a72017-09-20 00:01:23 -050027 try
Jayanth Othayoth24964822017-09-04 22:07:06 -050028 {
Jayanth Othayothe4693a72017-09-20 00:01:23 -050029 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 Othayoth24964822017-09-04 22:07:06 -050037 }
Jayanth Othayothe4693a72017-09-20 00:01:23 -050038 catch(cereal::Exception& e)
39 {
40 log<level::ERR>(e.what());
41 fs::remove(path);
42 return false;
43 }
Jayanth Othayoth24964822017-09-04 22:07:06 -050044}
45
46} // namespace elog
47} // namespace dump
48} // namespace phosphor