| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| 3 | |
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 4 | #include "generic.hpp" |
| 5 | |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 7 | |
| 8 | namespace openpower |
| 9 | { |
| 10 | namespace pels |
| 11 | { |
| 12 | |
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 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 | |
| Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 29 | void Generic::flatten(Stream& stream) const |
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 30 | { |
| 31 | stream << _header << _data; |
| 32 | } |
| 33 | |
| 34 | Generic::Generic(Stream& pel) |
| 35 | { |
| 36 | try |
| 37 | { |
| 38 | unflatten(pel); |
| 39 | validate(); |
| 40 | } |
| 41 | catch (const std::exception& e) |
| 42 | { |
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 43 | lg2::error("Cannot unflatten generic section: {EXCEPTION}", "EXCEPTION", |
| 44 | e); |
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 45 | _valid = false; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void Generic::validate() |
| 50 | { |
| 51 | // Nothing to validate |
| 52 | _valid = true; |
| 53 | } |
| 54 | |
| 55 | } // namespace pels |
| 56 | } // namespace openpower |