blob: 9d7dfc1ba5bedf6d2a964c84ec090414cbf84db6 [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);
17}
18
19void PelMinimal::raw(std::vector<uint8_t>& pelBuffer) const
20{
21 Stream pelData{pelBuffer};
22
23 // stream from object to buffer
24 _ph->flatten(pelData);
25 _uh->flatten(pelData);
26 _ps->flatten(pelData);
27}
28
29size_t PelMinimal::size() const
30{
31 size_t size = 0;
32
33 // size of private header section
34 if (_ph)
35 {
36 size += _ph->header().size;
37 }
38
39 // size of user header section
40 if (_uh)
41 {
42 size += _uh->header().size;
43 }
44
45 // size of primary SRC section
46 if (_ps)
47 {
48 size += _ph->header().size;
49 }
50
51 return ((size > _maxPELSize) ? _maxPELSize : size);
52}
53
54void PelMinimal::setSubsystem(uint8_t subsystem)
55{
56 _uh->setSubsystem(subsystem);
57}
58
59void PelMinimal::setSeverity(uint8_t severity)
60{
61 _uh->setSeverity(severity);
62}
63
64void PelMinimal::setType(uint8_t type)
65{
66 _uh->setType(type);
67}
68
69void PelMinimal::setAction(uint16_t action)
70{
71 _uh->setAction(action);
72}
73
74void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords)
75{
76 _ps->setSrcWords(srcWords);
77}
78
79void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString)
80{
81 _ps->setAsciiString(asciiString);
82}
83
84uint8_t PelMinimal::getSectionCount()
85{
86 return _ph->getSectionCount();
87}
88
89void PelMinimal::setSectionCount(uint8_t sectionCount)
90{
91 _ph->setSectionCount(sectionCount);
92}
93
94} // namespace pel
95} // namespace attn