Implement config parsing

Add a configuration json parsing function to read the configuration file
from /usr/share/binaryblob/config.json for which system file and location
to serialize/deserialize the binarystore blobs. Add a simple unit test for
parsing configs as well.

Signed-off-by: Kun Yi <kunyi731@gmail.com>
Change-Id: Ie86d622e83991365bc202d659f5860ff01190311
diff --git a/parse_config.hpp b/parse_config.hpp
new file mode 100644
index 0000000..b778923
--- /dev/null
+++ b/parse_config.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <cstdint>
+#include <nlohmann/json.hpp>
+#include <string>
+
+using std::uint32_t;
+using json = nlohmann::json;
+
+namespace conf
+{
+
+struct BinaryBlobConfig
+{
+    std::string blobBaseId;  // Required
+    std::string sysFilePath; // Required
+    uint32_t offsetBytes;    // Optional
+    uint32_t maxSizeBytes;   // Optional
+};
+
+/**
+ * @brief Parse parameters from a config json
+ * @param j: input json object
+ * @param config: output BinaryBlobConfig
+ * @throws: exception if config doesn't have required fields
+ */
+static inline void parseFromConfigFile(const json& j, BinaryBlobConfig& config)
+{
+    j.at("blobBaseId").get_to(config.blobBaseId);
+    j.at("sysFilePath").get_to(config.sysFilePath);
+    config.offsetBytes = j.value("offsetBytes", 0);
+    config.maxSizeBytes = j.value("maxSizeBytes", 0);
+}
+
+} // namespace conf