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 | { |
austinfcui | 9e4d190 | 2022-02-22 11:03:49 -0600 | [diff] [blame^] | 12 | initialize(data); |
| 13 | } |
| 14 | |
| 15 | void PelMinimal::initialize(std::vector<uint8_t>& data) |
| 16 | { |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 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); |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 22 | _eh = std::make_unique<ExtendedUserHeader>(pelData); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | 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); |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 33 | _eh->flatten(pelData); |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | 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 += _ph->header().size; |
| 56 | } |
| 57 | |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 58 | // size of extended user section |
| 59 | if (_eh) |
| 60 | { |
| 61 | size += _eh->header().size; |
| 62 | } |
| 63 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 64 | return ((size > _maxPELSize) ? _maxPELSize : size); |
| 65 | } |
| 66 | |
| 67 | void PelMinimal::setSubsystem(uint8_t subsystem) |
| 68 | { |
| 69 | _uh->setSubsystem(subsystem); |
| 70 | } |
| 71 | |
| 72 | void PelMinimal::setSeverity(uint8_t severity) |
| 73 | { |
| 74 | _uh->setSeverity(severity); |
| 75 | } |
| 76 | |
| 77 | void PelMinimal::setType(uint8_t type) |
| 78 | { |
| 79 | _uh->setType(type); |
| 80 | } |
| 81 | |
| 82 | void PelMinimal::setAction(uint16_t action) |
| 83 | { |
| 84 | _uh->setAction(action); |
| 85 | } |
| 86 | |
| 87 | void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords) |
| 88 | { |
| 89 | _ps->setSrcWords(srcWords); |
| 90 | } |
| 91 | |
| 92 | void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString) |
| 93 | { |
| 94 | _ps->setAsciiString(asciiString); |
| 95 | } |
| 96 | |
| 97 | uint8_t PelMinimal::getSectionCount() |
| 98 | { |
| 99 | return _ph->getSectionCount(); |
| 100 | } |
| 101 | |
| 102 | void PelMinimal::setSectionCount(uint8_t sectionCount) |
| 103 | { |
| 104 | _ph->setSectionCount(sectionCount); |
| 105 | } |
| 106 | |
Ben Tyner | feeea83 | 2021-04-06 10:08:11 -0500 | [diff] [blame] | 107 | void PelMinimal::setSymptomId(const std::string& symptomId) |
| 108 | { |
| 109 | _eh->setSymptomId(symptomId); |
| 110 | } |
| 111 | |
Ben Tyner | 135793a | 2021-10-27 09:18:41 -0500 | [diff] [blame] | 112 | void PelMinimal::setPlid(uint32_t plid) |
| 113 | { |
| 114 | _ph->setPlid(plid); |
| 115 | } |
| 116 | |
Ben Tyner | f5210bb | 2021-01-05 12:58:10 -0600 | [diff] [blame] | 117 | } // namespace pel |
| 118 | } // namespace attn |