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