blob: 5bef8adcfef22ad2636658f153d8ce224c2205f8 [file] [log] [blame]
Kun Yi4dc76482019-03-05 16:06:19 -08001#pragma once
2
3#include <cstdint>
4#include <nlohmann/json.hpp>
Willy Tu2b6683f2022-02-20 01:45:42 -08005#include <optional>
Kun Yi4dc76482019-03-05 16:06:19 -08006#include <string>
7
8using std::uint32_t;
9using json = nlohmann::json;
10
11namespace conf
12{
13
14struct BinaryBlobConfig
15{
Willy Tu2b6683f2022-02-20 01:45:42 -080016 std::string blobBaseId; // Required
17 std::string sysFilePath; // Required
18 std::optional<uint32_t> offsetBytes; // Optional
19 std::optional<uint32_t> maxSizeBytes; // Optional
Kun Yi4dc76482019-03-05 16:06:19 -080020};
21
22/**
23 * @brief Parse parameters from a config json
24 * @param j: input json object
25 * @param config: output BinaryBlobConfig
26 * @throws: exception if config doesn't have required fields
27 */
28static inline void parseFromConfigFile(const json& j, BinaryBlobConfig& config)
29{
30 j.at("blobBaseId").get_to(config.blobBaseId);
31 j.at("sysFilePath").get_to(config.sysFilePath);
Willy Tu2b6683f2022-02-20 01:45:42 -080032 if (j.contains("offsetBytes"))
33 {
34 uint32_t val;
35 j.at("offsetBytes").get_to(val);
36 config.offsetBytes = val;
37 }
38
39 if (j.contains("maxSizeBytes"))
40 {
41 uint32_t val;
42 j.at("maxSizeBytes").get_to(val);
43 config.maxSizeBytes = val;
44 }
Kun Yi4dc76482019-03-05 16:06:19 -080045}
46
47} // namespace conf