| 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); | 
|  | 17 | } | 
|  | 18 |  | 
|  | 19 | void 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 |  | 
|  | 29 | size_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 |  | 
|  | 54 | void PelMinimal::setSubsystem(uint8_t subsystem) | 
|  | 55 | { | 
|  | 56 | _uh->setSubsystem(subsystem); | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | void PelMinimal::setSeverity(uint8_t severity) | 
|  | 60 | { | 
|  | 61 | _uh->setSeverity(severity); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | void PelMinimal::setType(uint8_t type) | 
|  | 65 | { | 
|  | 66 | _uh->setType(type); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | void PelMinimal::setAction(uint16_t action) | 
|  | 70 | { | 
|  | 71 | _uh->setAction(action); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | void PelMinimal::setSrcWords(std::array<uint32_t, numSrcWords> srcWords) | 
|  | 75 | { | 
|  | 76 | _ps->setSrcWords(srcWords); | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | void PelMinimal::setAsciiString(std::array<char, asciiStringSize> asciiString) | 
|  | 80 | { | 
|  | 81 | _ps->setAsciiString(asciiString); | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | uint8_t PelMinimal::getSectionCount() | 
|  | 85 | { | 
|  | 86 | return _ph->getSectionCount(); | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | void PelMinimal::setSectionCount(uint8_t sectionCount) | 
|  | 90 | { | 
|  | 91 | _ph->setSectionCount(sectionCount); | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | } // namespace pel | 
|  | 95 | } // namespace attn |