blob: b77892370397ecbc16d07a593923d7f1abc4d2ee [file] [log] [blame]
Kun Yi4dc76482019-03-05 16:06:19 -08001#pragma once
2
3#include <cstdint>
4#include <nlohmann/json.hpp>
5#include <string>
6
7using std::uint32_t;
8using json = nlohmann::json;
9
10namespace conf
11{
12
13struct BinaryBlobConfig
14{
15 std::string blobBaseId; // Required
16 std::string sysFilePath; // Required
17 uint32_t offsetBytes; // Optional
18 uint32_t maxSizeBytes; // Optional
19};
20
21/**
22 * @brief Parse parameters from a config json
23 * @param j: input json object
24 * @param config: output BinaryBlobConfig
25 * @throws: exception if config doesn't have required fields
26 */
27static inline void parseFromConfigFile(const json& j, BinaryBlobConfig& config)
28{
29 j.at("blobBaseId").get_to(config.blobBaseId);
30 j.at("sysFilePath").get_to(config.sysFilePath);
31 config.offsetBytes = j.value("offsetBytes", 0);
32 config.maxSizeBytes = j.value("maxSizeBytes", 0);
33}
34
35} // namespace conf