refactor metadata pack/unpack functions
Move the `parse` and `combine` functions, which are used to translate
between `map<string,string>` and `vector<string>` for the metadata.
This is in preparation for transitioning the AdditionalData field
from `vector` to `map`.
Tested: Test cases pass. Simple `log-create` call has no change in
behavior.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib968e1fe02903072c300d5387cf91f2d8164b1b4
diff --git a/util.hpp b/util.hpp
index 0ac3878..405e35c 100644
--- a/util.hpp
+++ b/util.hpp
@@ -1,8 +1,10 @@
#pragma once
#include <fstream>
+#include <map>
#include <optional>
#include <string>
+#include <vector>
namespace phosphor::logging::util
{
@@ -23,4 +25,23 @@
*/
void journalSync();
+namespace additional_data
+{
+/** @brief Pull out metadata name and value from the string
+ * <metadata name>=<metadata value>
+ * @param [in] data - metadata key=value entries
+ * @return map of metadata name:value
+ */
+auto parse(const std::vector<std::string>& data)
+ -> std::map<std::string, std::string>;
+/** @brief Combine the metadata keys and values from the map
+ * into a vector of strings that look like:
+ * "<metadata name>=<metadata value>"
+ * @param [in] data - metadata key:value map
+ * @return vector of "key=value" strings
+ */
+auto combine(const std::map<std::string, std::string>& data)
+ -> std::vector<std::string>;
+} // namespace additional_data
+
} // namespace phosphor::logging::util