Kun Yi | 4dc7648 | 2019-03-05 16:06:19 -0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <nlohmann/json.hpp> |
| 5 | #include <string> |
| 6 | |
| 7 | using std::uint32_t; |
| 8 | using json = nlohmann::json; |
| 9 | |
| 10 | namespace conf |
| 11 | { |
| 12 | |
| 13 | struct 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 | */ |
| 27 | static 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 |