1 #include "pel_minimal.hpp"
2 
3 #include "stream.hpp"
4 
5 namespace attn
6 {
7 namespace pel
8 {
9 
PelMinimal(std::vector<uint8_t> & data)10 PelMinimal::PelMinimal(std::vector<uint8_t>& data)
11 {
12     initialize(data);
13 }
14 
initialize(std::vector<uint8_t> & data)15 void PelMinimal::initialize(std::vector<uint8_t>& data)
16 {
17     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);
22     _eh = std::make_unique<ExtendedUserHeader>(pelData);
23 }
24 
raw(std::vector<uint8_t> & pelBuffer) const25 void 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);
33     _eh->flatten(pelData);
34 }
35 
size() const36 size_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 += _ps->header().size;
56     }
57 
58     // size of extended user section
59     if (_eh)
60     {
61         size += _eh->header().size;
62     }
63 
64     return ((size > _maxPELSize) ? _maxPELSize : size);
65 }
66 
setSubsystem(uint8_t subsystem)67 void PelMinimal::setSubsystem(uint8_t subsystem)
68 {
69     _uh->setSubsystem(subsystem);
70 }
71 
setSeverity(uint8_t severity)72 void PelMinimal::setSeverity(uint8_t severity)
73 {
74     _uh->setSeverity(severity);
75 }
76 
setType(uint8_t type)77 void PelMinimal::setType(uint8_t type)
78 {
79     _uh->setType(type);
80 }
81 
setAction(uint16_t action)82 void PelMinimal::setAction(uint16_t action)
83 {
84     _uh->setAction(action);
85 }
86 
setSrcWords(std::array<uint32_t,numSrcWords> srcWords)87 void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords)
88 {
89     _ps->setSrcWords(srcWords);
90 }
91 
setAsciiString(std::array<char,asciiStringSize> asciiString)92 void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString)
93 {
94     _ps->setAsciiString(asciiString);
95 }
96 
getSectionCount()97 uint8_t PelMinimal::getSectionCount()
98 {
99     return _ph->getSectionCount();
100 }
101 
setSectionCount(uint8_t sectionCount)102 void PelMinimal::setSectionCount(uint8_t sectionCount)
103 {
104     _ph->setSectionCount(sectionCount);
105 }
106 
setSymptomId(const std::string & symptomId)107 void PelMinimal::setSymptomId(const std::string& symptomId)
108 {
109     _eh->setSymptomId(symptomId);
110 }
111 
setPlid(uint32_t plid)112 void PelMinimal::setPlid(uint32_t plid)
113 {
114     _ph->setPlid(plid);
115 }
116 
117 } // namespace pel
118 } // namespace attn
119