Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 16 | #include "generic.hpp" |
| 17 | |
| 18 | #include <phosphor-logging/log.hpp> |
| 19 | |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 20 | #include <format> |
| 21 | |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 22 | namespace openpower |
| 23 | { |
| 24 | namespace pels |
| 25 | { |
| 26 | |
| 27 | using namespace phosphor::logging; |
| 28 | |
| 29 | void Generic::unflatten(Stream& stream) |
| 30 | { |
| 31 | stream >> _header; |
| 32 | |
| 33 | if (_header.size <= SectionHeader::flattenedSize()) |
| 34 | { |
| 35 | throw std::out_of_range( |
| 36 | "Generic::unflatten: SectionHeader::size field too small"); |
| 37 | } |
| 38 | |
| 39 | size_t dataLength = _header.size - SectionHeader::flattenedSize(); |
| 40 | _data.resize(dataLength); |
| 41 | |
| 42 | stream >> _data; |
| 43 | } |
| 44 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 45 | void Generic::flatten(Stream& stream) const |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 46 | { |
| 47 | stream << _header << _data; |
| 48 | } |
| 49 | |
| 50 | Generic::Generic(Stream& pel) |
| 51 | { |
| 52 | try |
| 53 | { |
| 54 | unflatten(pel); |
| 55 | validate(); |
| 56 | } |
| 57 | catch (const std::exception& e) |
| 58 | { |
Matt Spinler | 8ac2050 | 2023-01-04 11:03:58 -0600 | [diff] [blame] | 59 | log<level::ERR>( |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 60 | std::format("Cannot unflatten generic section: {}", e.what()) |
Matt Spinler | 8ac2050 | 2023-01-04 11:03:58 -0600 | [diff] [blame] | 61 | .c_str()); |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 62 | _valid = false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void Generic::validate() |
| 67 | { |
| 68 | // Nothing to validate |
| 69 | _valid = true; |
| 70 | } |
| 71 | |
| 72 | } // namespace pels |
| 73 | } // namespace openpower |