diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2016-11-22 11:42:51 -0600 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2016-12-08 03:58:38 -0600 |
commit | 810c9defd7cd473d3eef14f177c6a24d6500fae1 (patch) | |
tree | 57b65de3d96a1bc4393d4e4545302e928e2c18cc | |
parent | fc1023d6bf0f09fd6f3beea987c3782bb6551781 (diff) | |
download | openpower-vpd-parser-810c9defd7cd473d3eef14f177c6a24d6500fae1.tar.gz openpower-vpd-parser-810c9defd7cd473d3eef14f177c6a24d6500fae1.zip |
parser : implement header check
This change implements a parser method to check if the OpenPOWER VPD has
the mandatory header record, VHDR.
Change-Id: I9e4cebd8f69e47e1ab0f1b569fe4af2c82a5a137
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r-- | impl.cpp | 55 | ||||
-rw-r--r-- | impl.hpp | 3 |
2 files changed, 58 insertions, 0 deletions
diff --git a/impl.cpp b/impl.cpp new file mode 100644 index 0000000..74a8969 --- /dev/null +++ b/impl.cpp @@ -0,0 +1,55 @@ +#include <exception> +#include <iostream> +#include <iterator> +#include "impl.hpp" + +namespace openpower +{ +namespace vpd +{ +namespace parser +{ + +namespace offsets +{ + +enum Offsets +{ + VHDR = 17 +}; + +} + +namespace lengths +{ + +enum Lengths +{ + RECORD_NAME = 4, + RECORD_MIN = 44, +}; + +} + +void Impl::checkHeader() const +{ + if (vpd.empty() || (lengths::RECORD_MIN > vpd.size())) + { + throw std::runtime_error("Malformed VPD"); + } + else + { + auto iterator = vpd.cbegin(); + std::advance(iterator, offsets::VHDR); + auto stop = std::next(iterator, lengths::RECORD_NAME); + std::string record(iterator, stop); + if ("VHDR" != record) + { + throw std::runtime_error("VHDR record not found"); + } + } +} + +} // namespace parser +} // namespace vpd +} // namespace openpower @@ -54,6 +54,9 @@ class Impl Store run(); private: + /** @brief Checks if the VHDR record is present in the VPD */ + void checkHeader() const; + /** @brief OpenPOWER VPD in binary format */ Binary vpd; |