blob: 766830cebcd257a48d524dde06e30ebb1a413127 [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 {
Willy Tu62872f52022-02-24 15:53:42 -080034 j.at("offsetBytes").get_to(config.offsetBytes.emplace());
Willy Tu2b6683f2022-02-20 01:45:42 -080035 }
36
37 if (j.contains("maxSizeBytes"))
38 {
Willy Tu62872f52022-02-24 15:53:42 -080039 j.at("maxSizeBytes").get_to(config.maxSizeBytes.emplace());
Willy Tu2b6683f2022-02-20 01:45:42 -080040 }
Kun Yi4dc76482019-03-05 16:06:19 -080041}
42
43} // namespace conf