xref: /openbmc/phosphor-inventory-manager/gen_serialization.hpp.mako (revision 07f0ff74acfc99e8a46af7dec1e5b2bc11855e50)
1## This file is a template.  The comment below is emitted
2## into the rendered file; feel free to edit this file.
3// This file was auto generated.  Do not edit.
4
5#include "config.h"
6
7#include <cereal/types/map.hpp>
8#include <cereal/types/set.hpp>
9#include <cereal/types/string.hpp>
10#include <cereal/types/tuple.hpp>
11#include <cereal/types/vector.hpp>
12% for iface in interfaces:
13#include <${iface.header()}>
14% endfor
15
16% for iface in interfaces:
17<% properties = interface_composite.names(str(iface)) %>\
18CEREAL_CLASS_VERSION(${iface.namespace()}, CLASS_VERSION);
19% endfor
20
21// Emitting signals prior to claiming a well known DBus service name causes
22// un-necessary DBus traffic and wakeups.  De-serialization only happens prior
23// to claiming a well known name, so don't emit signals.
24static constexpr auto skipSignals = true;
25namespace cereal
26{
27// The version we started using cereal NVP from
28static constexpr size_t CLASS_VERSION_WITH_NVP = 2;
29
30% for iface in interfaces:
31<% properties = interface_composite.names(str(iface)) %>\
32template<class Archive>
33void save([[maybe_unused]] Archive& a,
34          [[maybe_unused]] const ${iface.namespace()}& object,
35          const std::uint32_t /* version */)
36{
37% for p in properties:
38<% t = "cereal::make_nvp(\"" + p.CamelCase + "\", object." + p.camelCase + "())"
39%>\
40        a(${t});
41% endfor
42}
43
44template<class Archive>
45void load(Archive& a,
46          [[maybe_unused]] ${iface.namespace()}& object,
47          const std::uint32_t version)
48{
49% for p in properties:
50<% t = "object." + p.camelCase + "()" %>\
51    decltype(${t}) ${p.CamelCase}{};
52% endfor
53    if (version < CLASS_VERSION_WITH_NVP)
54    {
55<%
56    props = ', '.join([p.CamelCase for p in properties])
57%>\
58        a(${props});
59    }
60    else
61    {
62% for p in properties:
63<% t = "cereal::make_nvp(\"" + p.CamelCase + "\", " + p.CamelCase + ")" %>\
64        try
65        {
66            a(${t});
67        }
68        catch (const Exception &e)
69        {
70            // Ignore any exceptions, property value stays default
71        }
72% endfor
73    }
74% for p in properties:
75<% t = "object." + p.camelCase + "(" + p.CamelCase + ", skipSignals)" %>\
76    ${t};
77% endfor
78}
79
80% endfor
81} // namespace cereal
82