DBus calls to update VPD cache data for Interfaces

This commit implements required bus call to update vpd cache
once the data has been updated on the hardware.
It updates data for Common interface,Extra interface and COM
interface.

To test on simics use following procedure
- Hexdump the vpd file of EEPROM you want
to update in a .txt file.
- To update data of keyword for any record
make "busctl call" to WriteKeyword.
-After successful execution, agaim hexdump
VPD file of same EEPROM in another .txt
file.
-Difference can be observed in both the
file w.r.t. updated data and ECC.

once complete call has been made, updated
data in cache can be seen using following command
on simics.
- busctl intrsopect <service> <object_path>
- busctl introspect <service> <object_path>
<interface_name>

Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
Change-Id: I7997a027b631de25e254be9811c1926902fda8ec
diff --git a/utils.cpp b/utils.cpp
index e0bf6f4..6f2bfe4 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -1,6 +1,7 @@
 #include "utils.hpp"
 
-#include <iostream>
+#include "defines.hpp"
+
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/server.hpp>
 
@@ -74,5 +75,46 @@
     return lowByte;
 }
 
+/** @brief Encodes a keyword for D-Bus.
+ */
+string encodeKeyword(const string& kw, const string& encoding)
+{
+    if (encoding == "MAC")
+    {
+        string res{};
+        size_t first = kw[0];
+        res += toHex(first >> 4);
+        res += toHex(first & 0x0f);
+        for (size_t i = 1; i < kw.size(); ++i)
+        {
+            res += ":";
+            res += toHex(kw[i] >> 4);
+            res += toHex(kw[i] & 0x0f);
+        }
+        return res;
+    }
+    else if (encoding == "DATE")
+    {
+        // Date, represent as
+        // <year>-<month>-<day> <hour>:<min>
+        string res{};
+        static constexpr uint8_t skipPrefix = 3;
+
+        auto strItr = kw.begin();
+        advance(strItr, skipPrefix);
+        for_each(strItr, kw.end(), [&res](size_t c) { res += c; });
+
+        res.insert(BD_YEAR_END, 1, '-');
+        res.insert(BD_MONTH_END, 1, '-');
+        res.insert(BD_DAY_END, 1, ' ');
+        res.insert(BD_HOUR_END, 1, ':');
+
+        return res;
+    }
+    else // default to string encoding
+    {
+        return string(kw.begin(), kw.end());
+    }
+}
 } // namespace vpd
 } // namespace openpower