Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 1 | #include "pel_minimal.hpp" |
| 2 | |
| 3 | #include "stream.hpp" |
| 4 | |
| 5 | namespace attn |
| 6 | { |
| 7 | namespace pel |
| 8 | { |
| 9 | |
| 10 | PelMinimal::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 Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 17 | _eh = std::make_unique<ExtendedUserHeader>(pelData); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void 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 Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 28 | _eh->flatten(pelData); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | size_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 Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 53 | // size of extended user section |
| 54 | if (_eh) |
| 55 | { |
| 56 | size += _eh->header().size; |
| 57 | } |
| 58 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 59 | return ((size > _maxPELSize) ? _maxPELSize : size); |
| 60 | } |
| 61 | |
| 62 | void PelMinimal::setSubsystem(uint8_t subsystem) |
| 63 | { |
| 64 | _uh->setSubsystem(subsystem); |
| 65 | } |
| 66 | |
| 67 | void PelMinimal::setSeverity(uint8_t severity) |
| 68 | { |
| 69 | _uh->setSeverity(severity); |
| 70 | } |
| 71 | |
| 72 | void PelMinimal::setType(uint8_t type) |
| 73 | { |
| 74 | _uh->setType(type); |
| 75 | } |
| 76 | |
| 77 | void PelMinimal::setAction(uint16_t action) |
| 78 | { |
| 79 | _uh->setAction(action); |
| 80 | } |
| 81 | |
| 82 | void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords) |
| 83 | { |
| 84 | _ps->setSrcWords(srcWords); |
| 85 | } |
| 86 | |
| 87 | void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString) |
| 88 | { |
| 89 | _ps->setAsciiString(asciiString); |
| 90 | } |
| 91 | |
| 92 | uint8_t PelMinimal::getSectionCount() |
| 93 | { |
| 94 | return _ph->getSectionCount(); |
| 95 | } |
| 96 | |
| 97 | void PelMinimal::setSectionCount(uint8_t sectionCount) |
| 98 | { |
| 99 | _ph->setSectionCount(sectionCount); |
| 100 | } |
| 101 | |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 102 | void PelMinimal::setSymptomId(const std::string& symptomId) |
| 103 | { |
| 104 | _eh->setSymptomId(symptomId); |
| 105 | } |
| 106 | |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 107 | void PelMinimal::setPlid(uint32_t plid) |
| 108 | { |
| 109 | _ph->setPlid(plid); |
| 110 | } |
| 111 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 112 | } // namespace pel |
| 113 | } // namespace attn |