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 */ 24 SectionHeader() : id(0), size(0), version(0), subType(0), componentID(0) 25 { 26 } 27 28 /** 29 * @brief Constructor 30 * 31 * @param[in] id - the ID field 32 * @param[in] size - the size field 33 * @param[in] version - the version field 34 * @param[in] subType - the sub-type field 35 * @param[in] componentID - the component ID field 36 */ 37 SectionHeader(uint16_t id, uint16_t size, uint8_t version, uint8_t subType, 38 uint16_t componentID) : 39 id(id), 40 size(size), version(version), subType(subType), componentID(componentID) 41 { 42 } 43 44 /** 45 * @brief A two character ASCII field which identifies the section type. 46 */ 47 uint16_t id; 48 49 /** 50 * @brief The size of the section in bytes, including this section header. 51 */ 52 uint16_t size; 53 54 /** 55 * @brief The section format version. 56 */ 57 uint8_t version; 58 59 /** 60 * @brief The section sub-type. 61 */ 62 uint8_t subType; 63 64 /** 65 * @brief The component ID, which has various meanings depending on the 66 * section. 67 */ 68 uint16_t componentID; 69 70 /** 71 * @brief Returns the size of header when flattened into a PEL. 72 * 73 * @return size_t - the size of the header 74 */ 75 static constexpr size_t flattenedSize() 76 { 77 return sizeof(id) + sizeof(size) + sizeof(version) + sizeof(subType) + 78 sizeof(componentID); 79 } 80 }; 81 82 /** 83 * @brief Stream extraction operator for the SectionHeader 84 * 85 * @param[in] s - the stream 86 * @param[out] header - the SectionHeader object 87 */ 88 inline Stream& operator>>(Stream& s, SectionHeader& header) 89 { 90 s >> header.id >> header.size >> header.version >> header.subType >> 91 header.componentID; 92 return s; 93 } 94 95 /** 96 * @brief Stream insertion operator for the section header 97 * 98 * @param[out] s - the stream 99 * @param[in] header - the SectionHeader object 100 */ 101 inline Stream& operator<<(Stream& s, const SectionHeader& header) 102 { 103 s << header.id << header.size << header.version << header.subType 104 << header.componentID; 105 return s; 106 } 107 108 } // namespace pels 109 } // namespace openpower 110