blob: 4771e2e68fd7b505fd5254edd503ad6e138479af [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 Tu7f107802023-11-06 23:05:25 -080016 std::string blobBaseId; // Required
17 std::string sysFilePath; // Required
18 std::optional<uint32_t> offsetBytes; // Optional
19 std::optional<uint32_t> maxSizeBytes; // Optional
20 std::optional<std::string> aliasBlobBaseId; // Optional
21 bool migrateToAlias = false; // Optional
Kun Yi4dc76482019-03-05 16:06:19 -080022};
23
24/**
25 * @brief Parse parameters from a config json
26 * @param j: input json object
27 * @param config: output BinaryBlobConfig
28 * @throws: exception if config doesn't have required fields
29 */
30static inline void parseFromConfigFile(const json& j, BinaryBlobConfig& config)
31{
32 j.at("blobBaseId").get_to(config.blobBaseId);
33 j.at("sysFilePath").get_to(config.sysFilePath);
Willy Tu2b6683f2022-02-20 01:45:42 -080034 if (j.contains("offsetBytes"))
35 {
Willy Tu62872f52022-02-24 15:53:42 -080036 j.at("offsetBytes").get_to(config.offsetBytes.emplace());
Willy Tu2b6683f2022-02-20 01:45:42 -080037 }
38
39 if (j.contains("maxSizeBytes"))
40 {
Willy Tu62872f52022-02-24 15:53:42 -080041 j.at("maxSizeBytes").get_to(config.maxSizeBytes.emplace());
Willy Tu2b6683f2022-02-20 01:45:42 -080042 }
Willy Tu7f107802023-11-06 23:05:25 -080043
44 if (j.contains("aliasBlobBaseId"))
45 {
46 j.at("aliasBlobBaseId").get_to(config.aliasBlobBaseId.emplace());
47 }
48
49 if (j.contains("migrateToAlias"))
50 {
51 config.migrateToAlias = j.at("migrateToAlias");
52 }
Kun Yi4dc76482019-03-05 16:06:19 -080053}
54
55} // namespace conf