blob: 2e2993b04eaf7e48c6be35905964973bdd58bc5b [file] [log] [blame]
Matt Spinler1b5c72b2019-07-10 10:32:06 -05001#pragma once
2
3#include "stream.hpp"
4
5#include <cstdint>
6
7namespace openpower
8{
9namespace 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 */
18struct SectionHeader
19{
20 public:
21 /**
22 * @brief Constructor
23 */
Patrick Williams2544b412022-10-04 08:41:06 -050024 SectionHeader() : id(0), size(0), version(0), subType(0), componentID(0) {}
Matt Spinler1b5c72b2019-07-10 10:32:06 -050025
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) :
Patrick Williams075c7922024-08-16 15:19:49 -040037 id(id), size(size), version(version), subType(subType),
38 componentID(componentID)
Patrick Williams2544b412022-10-04 08:41:06 -050039 {}
Matt Spinler1b5c72b2019-07-10 10:32:06 -050040
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 */
85inline 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 Spinler06885452019-11-06 10:35:42 -060098inline Stream& operator<<(Stream& s, const SectionHeader& header)
Matt Spinler1b5c72b2019-07-10 10:32:06 -050099{
100 s << header.id << header.size << header.version << header.subType
101 << header.componentID;
102 return s;
103}
104
105} // namespace pels
106} // namespace openpower