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>
diff --git a/impl.cpp b/impl.cpp
index de1896f..9a6d8f9 100644
--- a/impl.cpp
+++ b/impl.cpp
@@ -2,6 +2,7 @@
#include <exception>
#include <iostream>
#include <iterator>
+#include <unordered_map>
#include <iomanip>
#include <tuple>
#include <algorithm>
@@ -23,6 +24,7 @@
};
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 @@
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