xref: /openbmc/phosphor-logging/extensions/openpower-pels/generic.cpp (revision 40fb54935ce7367636a7156039396ee91cc4d5e2)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation
3 
4 #include "generic.hpp"
5 
6 #include <phosphor-logging/lg2.hpp>
7 
8 namespace openpower
9 {
10 namespace pels
11 {
12 
unflatten(Stream & stream)13 void Generic::unflatten(Stream& stream)
14 {
15     stream >> _header;
16 
17     if (_header.size <= SectionHeader::flattenedSize())
18     {
19         throw std::out_of_range(
20             "Generic::unflatten: SectionHeader::size field too small");
21     }
22 
23     size_t dataLength = _header.size - SectionHeader::flattenedSize();
24     _data.resize(dataLength);
25 
26     stream >> _data;
27 }
28 
flatten(Stream & stream) const29 void Generic::flatten(Stream& stream) const
30 {
31     stream << _header << _data;
32 }
33 
Generic(Stream & pel)34 Generic::Generic(Stream& pel)
35 {
36     try
37     {
38         unflatten(pel);
39         validate();
40     }
41     catch (const std::exception& e)
42     {
43         lg2::error("Cannot unflatten generic section: {EXCEPTION}", "EXCEPTION",
44                    e);
45         _valid = false;
46     }
47 }
48 
validate()49 void Generic::validate()
50 {
51     // Nothing to validate
52     _valid = true;
53 }
54 
55 } // namespace pels
56 } // namespace openpower
57