PEL: Save AdditionalData in a UserData section

Save the contents of the AdditionalData OpenBMC event log property as
JSON in a UserData PEL section.

For example, if the AdditionalData property, which is an array of
strings, looks like:
    ["KEY1=VALUE1", "KEY=VALUE2"]

Then the data stored as ASCII text in the UserData section is:
    {"KEY1":"VALUE1","KEY2":"VALUE2"}

If one of the keys is "ESEL", then that entry is removed from the
UserData output as that contains a full raw PEL from the host sent down
as ASCII text.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ia6ffabb39fdb4315ec2152744414e44f7d2ec4aa
diff --git a/extensions/openpower-pels/additional_data.hpp b/extensions/openpower-pels/additional_data.hpp
index b855054..f133e0f 100644
--- a/extensions/openpower-pels/additional_data.hpp
+++ b/extensions/openpower-pels/additional_data.hpp
@@ -1,5 +1,6 @@
 #pragma once
 #include <map>
+#include <nlohmann/json.hpp>
 #include <optional>
 #include <string>
 #include <vector>
@@ -67,6 +68,39 @@
         return std::nullopt;
     }
 
+    /**
+     * @brief Remove a key/value pair from the contained data
+     *
+     * @param[in] key - The key of the entry to remove
+     */
+    void remove(const std::string& key)
+    {
+        _data.erase(key);
+    }
+
+    /**
+     * @brief Says if the object has no data
+     *
+     * @return bool true if the object is empty
+     */
+    inline bool empty() const
+    {
+        return _data.empty();
+    }
+
+    /**
+     * @brief Returns the contained data as a JSON object
+     *
+     * Looks like: {"key1":"value1","key2":"value2"}
+     *
+     * @return json - The JSON object
+     */
+    nlohmann::json toJSON() const
+    {
+        nlohmann::json j = _data;
+        return j;
+    }
+
   private:
     /**
      * @brief a map of keys to values