blob: c8b377bf663aae079b9fb41be5edd9a685e596da [file] [log] [blame]
Ben Tynerf5210bb2021-01-05 12:58:10 -06001#include "pel_minimal.hpp"
2
3#include "stream.hpp"
4
5namespace attn
6{
7namespace pel
8{
9
10PelMinimal::PelMinimal(std::vector<uint8_t>& data)
11{
austinfcui9e4d1902022-02-22 11:03:49 -060012 initialize(data);
13}
14
15void PelMinimal::initialize(std::vector<uint8_t>& data)
16{
Ben Tynerf5210bb2021-01-05 12:58:10 -060017 Stream pelData{data};
18
19 _ph = std::make_unique<PrivateHeader>(pelData);
20 _uh = std::make_unique<UserHeader>(pelData);
21 _ps = std::make_unique<PrimarySrc>(pelData);
Ben Tynerfeeea832021-04-06 10:08:11 -050022 _eh = std::make_unique<ExtendedUserHeader>(pelData);
Ben Tynerf5210bb2021-01-05 12:58:10 -060023}
24
25void PelMinimal::raw(std::vector<uint8_t>& pelBuffer) const
26{
27 Stream pelData{pelBuffer};
28
29 // stream from object to buffer
30 _ph->flatten(pelData);
31 _uh->flatten(pelData);
32 _ps->flatten(pelData);
Ben Tynerfeeea832021-04-06 10:08:11 -050033 _eh->flatten(pelData);
Ben Tynerf5210bb2021-01-05 12:58:10 -060034}
35
36size_t PelMinimal::size() const
37{
38 size_t size = 0;
39
40 // size of private header section
41 if (_ph)
42 {
43 size += _ph->header().size;
44 }
45
46 // size of user header section
47 if (_uh)
48 {
49 size += _uh->header().size;
50 }
51
52 // size of primary SRC section
53 if (_ps)
54 {
55 size += _ph->header().size;
56 }
57
Ben Tynerfeeea832021-04-06 10:08:11 -050058 // size of extended user section
59 if (_eh)
60 {
61 size += _eh->header().size;
62 }
63
Ben Tynerf5210bb2021-01-05 12:58:10 -060064 return ((size > _maxPELSize) ? _maxPELSize : size);
65}
66
67void PelMinimal::setSubsystem(uint8_t subsystem)
68{
69 _uh->setSubsystem(subsystem);
70}
71
72void PelMinimal::setSeverity(uint8_t severity)
73{
74 _uh->setSeverity(severity);
75}
76
77void PelMinimal::setType(uint8_t type)
78{
79 _uh->setType(type);
80}
81
82void PelMinimal::setAction(uint16_t action)
83{
84 _uh->setAction(action);
85}
86
87void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords)
88{
89 _ps->setSrcWords(srcWords);
90}
91
92void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString)
93{
94 _ps->setAsciiString(asciiString);
95}
96
97uint8_t PelMinimal::getSectionCount()
98{
99 return _ph->getSectionCount();
100}
101
102void PelMinimal::setSectionCount(uint8_t sectionCount)
103{
104 _ph->setSectionCount(sectionCount);
105}
106
Ben Tynerfeeea832021-04-06 10:08:11 -0500107void PelMinimal::setSymptomId(const std::string& symptomId)
108{
109 _eh->setSymptomId(symptomId);
110}
111
Ben Tyner135793a2021-10-27 09:18:41 -0500112void PelMinimal::setPlid(uint32_t plid)
113{
114 _ph->setPlid(plid);
115}
116
Ben Tynerf5210bb2021-01-05 12:58:10 -0600117} // namespace pel
118} // namespace attn