Matt Spinler | 1b5c72b | 2019-07-10 10:32:06 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "stream.hpp" |
| 4 | |
| 5 | #include <cstdint> |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @class SectionHeader |
| 14 | * |
| 15 | * This header is at the start of every PEL section. It has a size |
| 16 | * of 8 bytes. |
| 17 | */ |
| 18 | struct SectionHeader |
| 19 | { |
| 20 | public: |
| 21 | /** |
| 22 | * @brief Constructor |
| 23 | */ |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 24 | SectionHeader() : id(0), size(0), version(0), subType(0), componentID(0) {} |
Matt Spinler | 1b5c72b | 2019-07-10 10:32:06 -0500 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * @brief Constructor |
| 28 | * |
| 29 | * @param[in] id - the ID field |
| 30 | * @param[in] size - the size field |
| 31 | * @param[in] version - the version field |
| 32 | * @param[in] subType - the sub-type field |
| 33 | * @param[in] componentID - the component ID field |
| 34 | */ |
| 35 | SectionHeader(uint16_t id, uint16_t size, uint8_t version, uint8_t subType, |
| 36 | uint16_t componentID) : |
| 37 | id(id), |
| 38 | size(size), version(version), subType(subType), componentID(componentID) |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 39 | {} |
Matt Spinler | 1b5c72b | 2019-07-10 10:32:06 -0500 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * @brief A two character ASCII field which identifies the section type. |
| 43 | */ |
| 44 | uint16_t id; |
| 45 | |
| 46 | /** |
| 47 | * @brief The size of the section in bytes, including this section header. |
| 48 | */ |
| 49 | uint16_t size; |
| 50 | |
| 51 | /** |
| 52 | * @brief The section format version. |
| 53 | */ |
| 54 | uint8_t version; |
| 55 | |
| 56 | /** |
| 57 | * @brief The section sub-type. |
| 58 | */ |
| 59 | uint8_t subType; |
| 60 | |
| 61 | /** |
| 62 | * @brief The component ID, which has various meanings depending on the |
| 63 | * section. |
| 64 | */ |
| 65 | uint16_t componentID; |
| 66 | |
| 67 | /** |
| 68 | * @brief Returns the size of header when flattened into a PEL. |
| 69 | * |
| 70 | * @return size_t - the size of the header |
| 71 | */ |
| 72 | static constexpr size_t flattenedSize() |
| 73 | { |
| 74 | return sizeof(id) + sizeof(size) + sizeof(version) + sizeof(subType) + |
| 75 | sizeof(componentID); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * @brief Stream extraction operator for the SectionHeader |
| 81 | * |
| 82 | * @param[in] s - the stream |
| 83 | * @param[out] header - the SectionHeader object |
| 84 | */ |
| 85 | inline Stream& operator>>(Stream& s, SectionHeader& header) |
| 86 | { |
| 87 | s >> header.id >> header.size >> header.version >> header.subType >> |
| 88 | header.componentID; |
| 89 | return s; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @brief Stream insertion operator for the section header |
| 94 | * |
| 95 | * @param[out] s - the stream |
| 96 | * @param[in] header - the SectionHeader object |
| 97 | */ |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 98 | inline Stream& operator<<(Stream& s, const SectionHeader& header) |
Matt Spinler | 1b5c72b | 2019-07-10 10:32:06 -0500 | [diff] [blame] | 99 | { |
| 100 | s << header.id << header.size << header.version << header.subType |
| 101 | << header.componentID; |
| 102 | return s; |
| 103 | } |
| 104 | |
| 105 | } // namespace pels |
| 106 | } // namespace openpower |