Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "section.hpp" |
| 4 | #include "stream.hpp" |
| 5 | |
| 6 | namespace openpower |
| 7 | { |
| 8 | namespace pels |
| 9 | { |
| 10 | |
| 11 | /** |
| 12 | * @class Generic |
| 13 | * |
| 14 | * This class is used for a PEL section when there is no other class to use. |
| 15 | * It just contains a vector of the raw data. Its purpose is so that a PEL |
| 16 | * can be completely unflattened even if the code doesn't have a class for |
| 17 | * every section type. |
| 18 | */ |
| 19 | class Generic : public Section |
| 20 | { |
| 21 | public: |
| 22 | Generic() = delete; |
| 23 | ~Generic() = default; |
| 24 | Generic(const Generic&) = default; |
| 25 | Generic& operator=(const Generic&) = default; |
| 26 | Generic(Generic&&) = default; |
| 27 | Generic& operator=(Generic&&) = default; |
| 28 | |
| 29 | /** |
| 30 | * @brief Constructor |
| 31 | * |
| 32 | * Fills in this class's data fields from the stream. |
| 33 | * |
| 34 | * @param[in] pel - the PEL data stream |
| 35 | */ |
| 36 | explicit Generic(Stream& pel); |
| 37 | |
| 38 | /** |
| 39 | * @brief Flatten the section into the stream |
| 40 | * |
| 41 | * @param[in] stream - The stream to write to |
| 42 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 43 | void flatten(Stream& stream) const override; |
Matt Spinler | 14d671f | 2019-09-25 13:11:22 -0500 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * @brief Returns the size of this section when flattened into a PEL |
| 47 | * |
| 48 | * @return size_t - the size of the section |
| 49 | */ |
| 50 | size_t flattenedSize() |
| 51 | { |
| 52 | return Section::flattenedSize() + _data.size(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @brief Returns the raw section data |
| 57 | * |
| 58 | * @return std::vector<uint8_t>& |
| 59 | */ |
| 60 | const std::vector<uint8_t>& data() const |
| 61 | { |
| 62 | return _data; |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | /** |
| 67 | * @brief Fills in the object from the stream data |
| 68 | * |
| 69 | * @param[in] stream - The stream to read from |
| 70 | */ |
| 71 | void unflatten(Stream& stream); |
| 72 | |
| 73 | /** |
| 74 | * @brief Validates the section contents |
| 75 | * |
| 76 | * Updates _valid (in Section) with the results. |
| 77 | */ |
| 78 | void validate() override; |
| 79 | |
| 80 | /** |
| 81 | * @brief The section data |
| 82 | */ |
| 83 | std::vector<uint8_t> _data; |
| 84 | }; |
| 85 | |
| 86 | } // namespace pels |
| 87 | } // namespace openpower |