Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 1 | #include "generic.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/log.hpp> |
| 4 | |
| 5 | namespace openpower |
| 6 | { |
| 7 | namespace pels |
| 8 | { |
| 9 | |
| 10 | using namespace phosphor::logging; |
| 11 | |
| 12 | void 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 | |
| 28 | void Generic::flatten(Stream& stream) |
| 29 | { |
| 30 | stream << _header << _data; |
| 31 | } |
| 32 | |
| 33 | Generic::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 | |
| 48 | void Generic::validate() |
| 49 | { |
| 50 | // Nothing to validate |
| 51 | _valid = true; |
| 52 | } |
| 53 | |
| 54 | } // namespace pels |
| 55 | } // namespace openpower |