blob: 11f589f89766eca9b00431a843ea80d0d4a189cf [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{
12 Stream pelData{data};
13
14 _ph = std::make_unique<PrivateHeader>(pelData);
15 _uh = std::make_unique<UserHeader>(pelData);
16 _ps = std::make_unique<PrimarySrc>(pelData);
Ben Tynerfeeea832021-04-06 10:08:11 -050017 _eh = std::make_unique<ExtendedUserHeader>(pelData);
Ben Tynerf5210bb2021-01-05 12:58:10 -060018}
19
20void PelMinimal::raw(std::vector<uint8_t>& pelBuffer) const
21{
22 Stream pelData{pelBuffer};
23
24 // stream from object to buffer
25 _ph->flatten(pelData);
26 _uh->flatten(pelData);
27 _ps->flatten(pelData);
Ben Tynerfeeea832021-04-06 10:08:11 -050028 _eh->flatten(pelData);
Ben Tynerf5210bb2021-01-05 12:58:10 -060029}
30
31size_t PelMinimal::size() const
32{
33 size_t size = 0;
34
35 // size of private header section
36 if (_ph)
37 {
38 size += _ph->header().size;
39 }
40
41 // size of user header section
42 if (_uh)
43 {
44 size += _uh->header().size;
45 }
46
47 // size of primary SRC section
48 if (_ps)
49 {
50 size += _ph->header().size;
51 }
52
Ben Tynerfeeea832021-04-06 10:08:11 -050053 // size of extended user section
54 if (_eh)
55 {
56 size += _eh->header().size;
57 }
58
Ben Tynerf5210bb2021-01-05 12:58:10 -060059 return ((size > _maxPELSize) ? _maxPELSize : size);
60}
61
62void PelMinimal::setSubsystem(uint8_t subsystem)
63{
64 _uh->setSubsystem(subsystem);
65}
66
67void PelMinimal::setSeverity(uint8_t severity)
68{
69 _uh->setSeverity(severity);
70}
71
72void PelMinimal::setType(uint8_t type)
73{
74 _uh->setType(type);
75}
76
77void PelMinimal::setAction(uint16_t action)
78{
79 _uh->setAction(action);
80}
81
82void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords)
83{
84 _ps->setSrcWords(srcWords);
85}
86
87void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString)
88{
89 _ps->setAsciiString(asciiString);
90}
91
92uint8_t PelMinimal::getSectionCount()
93{
94 return _ph->getSectionCount();
95}
96
97void PelMinimal::setSectionCount(uint8_t sectionCount)
98{
99 _ph->setSectionCount(sectionCount);
100}
101
Ben Tynerfeeea832021-04-06 10:08:11 -0500102void PelMinimal::setSymptomId(const std::string& symptomId)
103{
104 _eh->setSymptomId(symptomId);
105}
106
Ben Tynerf5210bb2021-01-05 12:58:10 -0600107} // namespace pel
108} // namespace attn