blob: 78d9e81024c64aec84b46644d055f549ced6b0c5 [file] [log] [blame]
Matt Spinler14d671f2019-09-25 13:11:22 -05001#include "generic.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace openpower
6{
7namespace pels
8{
9
10using namespace phosphor::logging;
11
12void Generic::unflatten(Stream& stream)
13{
14 stream >> _header;
15
16 if (_header.size <= SectionHeader::flattenedSize())
17 {
18 throw std::out_of_range(
19 "Generic::unflatten: SectionHeader::size field too small");
20 }
21
22 size_t dataLength = _header.size - SectionHeader::flattenedSize();
23 _data.resize(dataLength);
24
25 stream >> _data;
26}
27
28void Generic::flatten(Stream& stream)
29{
30 stream << _header << _data;
31}
32
33Generic::Generic(Stream& pel)
34{
35 try
36 {
37 unflatten(pel);
38 validate();
39 }
40 catch (const std::exception& e)
41 {
42 log<level::ERR>("Cannot unflatten generic section",
43 entry("ERROR=%s", e.what()));
44 _valid = false;
45 }
46}
47
48void Generic::validate()
49{
50 // Nothing to validate
51 _valid = true;
52}
53
54} // namespace pels
55} // namespace openpower