Interface & Factory implementation for VPD Parsers

This commit abstracts the implementation logic of different parser.
A parser factory is implemented to provide instance of required
parser based on the type of vpd file needed to be parsed.

The interface should be derived to implement any further parser logic
related to vpd.

Status: This does not add any new function, so basic testing of
VPD parsing, VPD tool and writes was performed.

Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I3ce1a2d6b7e8d8984fd7800132e78ab8a9a21e56
diff --git a/vpd-parser/memory_vpd_parser.cpp b/vpd-parser/memory_vpd_parser.cpp
new file mode 100644
index 0000000..6a4c608
--- /dev/null
+++ b/vpd-parser/memory_vpd_parser.cpp
@@ -0,0 +1,65 @@
+#include "memory_vpd_parser.hpp"
+
+#include <iostream>
+#include <numeric>
+#include <string>
+
+namespace openpower
+{
+namespace vpd
+{
+namespace memory
+{
+namespace parser
+{
+using namespace inventory;
+using namespace constants;
+using namespace std;
+using namespace openpower::vpd::parser;
+
+kwdVpdMap memoryVpdParser::readKeywords(Binary::const_iterator iterator)
+{
+    KeywordVpdMap map{};
+
+    vector<uint8_t> partNumber(iterator, iterator + PART_NUM_LEN);
+
+    advance(iterator, PART_NUM_LEN);
+    vector<uint8_t> serialNumber(iterator, iterator + SERIAL_NUM_LEN);
+
+    advance(iterator, SERIAL_NUM_LEN);
+    vector<uint8_t> ccin(iterator, iterator + CCIN_LEN);
+
+    map.emplace("PN", move(partNumber));
+    map.emplace("SN", move(serialNumber));
+    map.emplace("CC", move(ccin));
+
+    return map;
+}
+
+variant<kwdVpdMap, Store> memoryVpdParser::parse()
+{
+    // check if vpd file is empty
+    if (memVpd.empty())
+    {
+        throw runtime_error("VPD file is empty.");
+    }
+
+    // Read the data and return the map
+    auto iterator = memVpd.cbegin();
+    // point the iterator to DIMM data and skip "11S"
+    advance(iterator, MEMORY_VPD_DATA_START + 3);
+
+    auto vpdDataMap = readKeywords(iterator);
+
+    return vpdDataMap;
+}
+
+std::string memoryVpdParser::getInterfaceName() const
+{
+    return memVpdInf;
+}
+
+} // namespace parser
+} // namespace memory
+} // namespace vpd
+} // namespace openpower
\ No newline at end of file