summaryrefslogtreecommitdiffstats
path: root/dump_serialize.cpp
blob: 799b1421c71f555056339f9aad14a5e2386f680d (plain)
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
47
#include "dump_serialize.hpp"

#include <cereal/archives/binary.hpp>
#include <cereal/types/set.hpp>
#include <fstream>
#include <phosphor-logging/log.hpp>

namespace phosphor
{
namespace dump
{
namespace elog
{

using namespace phosphor::logging;

void serialize(const ElogList& list, const fs::path& dir)
{
    std::ofstream os(dir.c_str(), std::ios::binary);
    cereal::BinaryOutputArchive oarchive(os);
    oarchive(list);
}

bool deserialize(const fs::path& path, ElogList& list)
{
    try
    {
        if (fs::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 (cereal::Exception& e)
    {
        log<level::ERR>(e.what());
        fs::remove(path);
        return false;
    }
}

} // namespace elog
} // namespace dump
} // namespace phosphor
OpenPOWER on IntegriCloud