Deepak Kodihalli | 810c9de | 2016-11-22 11:42:51 -0600 | [diff] [blame^] | 1 | #include <exception> |
| 2 | #include <iostream> |
| 3 | #include <iterator> |
| 4 | #include "impl.hpp" |
| 5 | |
| 6 | namespace openpower |
| 7 | { |
| 8 | namespace vpd |
| 9 | { |
| 10 | namespace parser |
| 11 | { |
| 12 | |
| 13 | namespace offsets |
| 14 | { |
| 15 | |
| 16 | enum Offsets |
| 17 | { |
| 18 | VHDR = 17 |
| 19 | }; |
| 20 | |
| 21 | } |
| 22 | |
| 23 | namespace lengths |
| 24 | { |
| 25 | |
| 26 | enum Lengths |
| 27 | { |
| 28 | RECORD_NAME = 4, |
| 29 | RECORD_MIN = 44, |
| 30 | }; |
| 31 | |
| 32 | } |
| 33 | |
| 34 | void Impl::checkHeader() const |
| 35 | { |
| 36 | if (vpd.empty() || (lengths::RECORD_MIN > vpd.size())) |
| 37 | { |
| 38 | throw std::runtime_error("Malformed VPD"); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | auto iterator = vpd.cbegin(); |
| 43 | std::advance(iterator, offsets::VHDR); |
| 44 | auto stop = std::next(iterator, lengths::RECORD_NAME); |
| 45 | std::string record(iterator, stop); |
| 46 | if ("VHDR" != record) |
| 47 | { |
| 48 | throw std::runtime_error("VHDR record not found"); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | } // namespace parser |
| 54 | } // namespace vpd |
| 55 | } // namespace openpower |