diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2016-11-24 06:50:43 -0600 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2016-12-08 12:37:27 -0600 |
commit | 683bf721d7f524aefd7d06502cfe0dfa755ac063 (patch) | |
tree | 76531961a98ce9c1f9d2af8ffc1cbc72952a3a55 | |
parent | 4a475bda35c8c6c985f81f1dbecdba9a55d46782 (diff) | |
download | openpower-vpd-parser-683bf721d7f524aefd7d06502cfe0dfa755ac063.tar.gz openpower-vpd-parser-683bf721d7f524aefd7d06502cfe0dfa755ac063.zip |
parser : parse keyword section of a record
For a given OpenPOWER VPD record, get to it's keyword section and find
all contained keywords, and read the data for each of those.
Change-Id: I87001b3bc0a7b842543aa387e319b98aac8ca3ff
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r-- | impl.cpp | 37 | ||||
-rw-r--r-- | impl.hpp | 11 |
2 files changed, 48 insertions, 0 deletions
@@ -2,6 +2,7 @@ #include <exception> #include <iostream> #include <iterator> +#include <unordered_map> #include <iomanip> #include <tuple> #include <algorithm> @@ -23,6 +24,7 @@ static const std::unordered_map<std::string, Record> supportedRecords = }; static constexpr auto MAC_ADDRESS_LEN_BYTES = 6; +static constexpr auto LAST_KW = "PF"; static const std::unordered_map<std::string, internal::KeywordInfo> supportedKeywords = @@ -256,6 +258,41 @@ std::string Impl::readKwData(const internal::KeywordInfo& keyword, return {}; } +internal::KeywordMap Impl::readKeywords(Binary::const_iterator iterator) +{ + internal::KeywordMap map {}; + while (true) + { + // Note keyword name + std::string kw(iterator, iterator + lengths::KW_NAME); + if (LAST_KW == kw) + { + // We're done + break; + } + // Jump past keyword name + std::advance(iterator, lengths::KW_NAME); + // Note keyword data length + std::size_t length = *iterator; + // Jump past keyword length + std::advance(iterator, sizeof(KwSize)); + // Pointing to keyword data now + if (supportedKeywords.end() != supportedKeywords.find(kw)) + { + // Keyword is of interest to us + std::string data = readKwData( + (supportedKeywords.find(kw))->second, + length, + iterator); + map.emplace(std::move(kw), std::move(data)); + } + // Jump past keyword data length + std::advance(iterator, length); + } + + return map; +} + } // namespace parser } // namespace vpd } // namespace openpower @@ -28,6 +28,7 @@ namespace internal using KeywordInfo = std::tuple<record::Keyword, keyword::Encoding>; using OffsetList = std::vector<uint32_t>; +using KeywordMap = Parsed::mapped_type; } @@ -113,6 +114,16 @@ class Impl std::size_t dataLength, Binary::const_iterator iterator); + /** @brief While we're pointing at the keyword section of + * a record in the VPD, this will read all contained + * keywords and their values. + * + * @param[in] iterator - iterator pointing to a Keyword in the VPD + * + * @returns map of keyword:data + */ + internal::KeywordMap readKeywords(Binary::const_iterator iterator); + /** @brief Checks if the VHDR record is present in the VPD */ void checkHeader() const; |