| 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 |  | 
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 18 | #include <phosphor-logging/lg2.hpp> | 
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 19 |  | 
 | 20 | namespace openpower | 
 | 21 | { | 
 | 22 | namespace pels | 
 | 23 | { | 
 | 24 |  | 
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 25 | void Generic::unflatten(Stream& stream) | 
 | 26 | { | 
 | 27 |     stream >> _header; | 
 | 28 |  | 
 | 29 |     if (_header.size <= SectionHeader::flattenedSize()) | 
 | 30 |     { | 
 | 31 |         throw std::out_of_range( | 
 | 32 |             "Generic::unflatten: SectionHeader::size field too small"); | 
 | 33 |     } | 
 | 34 |  | 
 | 35 |     size_t dataLength = _header.size - SectionHeader::flattenedSize(); | 
 | 36 |     _data.resize(dataLength); | 
 | 37 |  | 
 | 38 |     stream >> _data; | 
 | 39 | } | 
 | 40 |  | 
| Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 41 | void Generic::flatten(Stream& stream) const | 
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 42 | { | 
 | 43 |     stream << _header << _data; | 
 | 44 | } | 
 | 45 |  | 
 | 46 | Generic::Generic(Stream& pel) | 
 | 47 | { | 
 | 48 |     try | 
 | 49 |     { | 
 | 50 |         unflatten(pel); | 
 | 51 |         validate(); | 
 | 52 |     } | 
 | 53 |     catch (const std::exception& e) | 
 | 54 |     { | 
| Arya K Padman | 5bc2653 | 2024-04-10 06:19:25 -0500 | [diff] [blame] | 55 |         lg2::error("Cannot unflatten generic section: {EXCEPTION}", "EXCEPTION", | 
 | 56 |                    e); | 
| Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 57 |         _valid = false; | 
 | 58 |     } | 
 | 59 | } | 
 | 60 |  | 
 | 61 | void Generic::validate() | 
 | 62 | { | 
 | 63 |     // Nothing to validate | 
 | 64 |     _valid = true; | 
 | 65 | } | 
 | 66 |  | 
 | 67 | } // namespace pels | 
 | 68 | } // namespace openpower |