// This file is generated by tools/codegen.sh
// DO NOT EDIT IT.

// clang-format off

//  To parse this JSON data, first install
//
//      json.hpp  https://github.com/nlohmann/json
//
//  Then include this file, and then do
//
//     Generators.hpp data = nlohmann::json::parse(jsonString);

#pragma once

#include <optional>
#include <nlohmann/json.hpp>
#include "linglong/cdi/types/helper.hpp"

#include "linglong/cdi/types/Cdi.hpp"
#include "linglong/cdi/types/Device.hpp"
#include "linglong/cdi/types/ContainerEdits.hpp"
#include "linglong/cdi/types/LinuxNetDevice.hpp"
#include "linglong/cdi/types/Mount.hpp"
#include "linglong/cdi/types/IntelRdt.hpp"
#include "linglong/cdi/types/Hook.hpp"
#include "linglong/cdi/types/DeviceNode.hpp"

namespace linglong {
namespace cdi {
namespace types {
void from_json(const json & j, DeviceNode & x);
void to_json(json & j, const DeviceNode & x);

void from_json(const json & j, Hook & x);
void to_json(json & j, const Hook & x);

void from_json(const json & j, IntelRdt & x);
void to_json(json & j, const IntelRdt & x);

void from_json(const json & j, Mount & x);
void to_json(json & j, const Mount & x);

void from_json(const json & j, LinuxNetDevice & x);
void to_json(json & j, const LinuxNetDevice & x);

void from_json(const json & j, ContainerEdits & x);
void to_json(json & j, const ContainerEdits & x);

void from_json(const json & j, Device & x);
void to_json(json & j, const Device & x);

void from_json(const json & j, Cdi & x);
void to_json(json & j, const Cdi & x);

inline void from_json(const json & j, DeviceNode& x) {
x.gid = get_stack_optional<int64_t>(j, "gid");
x.hostPath = get_stack_optional<std::string>(j, "hostPath");
x.major = get_stack_optional<int64_t>(j, "major");
x.minor = get_stack_optional<int64_t>(j, "minor");
x.path = j.at("path").get<std::string>();
x.permissions = get_stack_optional<std::string>(j, "permissions");
x.type = get_stack_optional<std::string>(j, "type");
x.uid = get_stack_optional<int64_t>(j, "uid");
}

inline void to_json(json & j, const DeviceNode & x) {
j = json::object();
if (x.gid) {
j["gid"] = x.gid;
}
if (x.hostPath) {
j["hostPath"] = x.hostPath;
}
if (x.major) {
j["major"] = x.major;
}
if (x.minor) {
j["minor"] = x.minor;
}
j["path"] = x.path;
if (x.permissions) {
j["permissions"] = x.permissions;
}
if (x.type) {
j["type"] = x.type;
}
if (x.uid) {
j["uid"] = x.uid;
}
}

inline void from_json(const json & j, Hook& x) {
x.args = get_stack_optional<std::vector<std::string>>(j, "args");
x.env = get_stack_optional<std::vector<std::string>>(j, "env");
x.hookName = j.at("hookName").get<std::string>();
x.path = j.at("path").get<std::string>();
x.timeout = get_stack_optional<int64_t>(j, "timeout");
}

inline void to_json(json & j, const Hook & x) {
j = json::object();
if (x.args) {
j["args"] = x.args;
}
if (x.env) {
j["env"] = x.env;
}
j["hookName"] = x.hookName;
j["path"] = x.path;
if (x.timeout) {
j["timeout"] = x.timeout;
}
}

inline void from_json(const json & j, IntelRdt& x) {
x.closID = get_stack_optional<std::string>(j, "closID");
x.enableMonitoring = get_stack_optional<bool>(j, "enableMonitoring");
x.l3CacheSchema = get_stack_optional<std::string>(j, "l3CacheSchema");
x.memBWSchema = get_stack_optional<std::string>(j, "memBwSchema");
x.schemata = get_stack_optional<std::vector<std::string>>(j, "schemata");
}

inline void to_json(json & j, const IntelRdt & x) {
j = json::object();
if (x.closID) {
j["closID"] = x.closID;
}
if (x.enableMonitoring) {
j["enableMonitoring"] = x.enableMonitoring;
}
if (x.l3CacheSchema) {
j["l3CacheSchema"] = x.l3CacheSchema;
}
if (x.memBWSchema) {
j["memBwSchema"] = x.memBWSchema;
}
if (x.schemata) {
j["schemata"] = x.schemata;
}
}

inline void from_json(const json & j, Mount& x) {
x.containerPath = j.at("containerPath").get<std::string>();
x.hostPath = j.at("hostPath").get<std::string>();
x.options = get_stack_optional<std::vector<std::string>>(j, "options");
x.type = get_stack_optional<std::string>(j, "type");
}

inline void to_json(json & j, const Mount & x) {
j = json::object();
j["containerPath"] = x.containerPath;
j["hostPath"] = x.hostPath;
if (x.options) {
j["options"] = x.options;
}
if (x.type) {
j["type"] = x.type;
}
}

inline void from_json(const json & j, LinuxNetDevice& x) {
x.hostInterfaceName = j.at("hostInterfaceName").get<std::string>();
x.name = j.at("name").get<std::string>();
}

inline void to_json(json & j, const LinuxNetDevice & x) {
j = json::object();
j["hostInterfaceName"] = x.hostInterfaceName;
j["name"] = x.name;
}

inline void from_json(const json & j, ContainerEdits& x) {
x.additionalGids = get_stack_optional<std::vector<int64_t>>(j, "additionalGids");
x.deviceNodes = get_stack_optional<std::vector<DeviceNode>>(j, "deviceNodes");
x.env = get_stack_optional<std::vector<std::string>>(j, "env");
x.hooks = get_stack_optional<std::vector<Hook>>(j, "hooks");
x.intelRdt = get_stack_optional<IntelRdt>(j, "intelRdt");
x.mounts = get_stack_optional<std::vector<Mount>>(j, "mounts");
x.netDevices = get_stack_optional<std::vector<LinuxNetDevice>>(j, "netDevices");
}

inline void to_json(json & j, const ContainerEdits & x) {
j = json::object();
if (x.additionalGids) {
j["additionalGids"] = x.additionalGids;
}
if (x.deviceNodes) {
j["deviceNodes"] = x.deviceNodes;
}
if (x.env) {
j["env"] = x.env;
}
if (x.hooks) {
j["hooks"] = x.hooks;
}
if (x.intelRdt) {
j["intelRdt"] = x.intelRdt;
}
if (x.mounts) {
j["mounts"] = x.mounts;
}
if (x.netDevices) {
j["netDevices"] = x.netDevices;
}
}

inline void from_json(const json & j, Device& x) {
x.annotations = get_stack_optional<std::map<std::string, std::string>>(j, "annotations");
x.containerEdits = j.at("containerEdits").get<ContainerEdits>();
x.name = j.at("name").get<std::string>();
}

inline void to_json(json & j, const Device & x) {
j = json::object();
if (x.annotations) {
j["annotations"] = x.annotations;
}
j["containerEdits"] = x.containerEdits;
j["name"] = x.name;
}

inline void from_json(const json & j, Cdi& x) {
x.annotations = get_stack_optional<std::map<std::string, std::string>>(j, "annotations");
x.cdiVersion = j.at("cdiVersion").get<std::string>();
x.containerEdits = get_stack_optional<ContainerEdits>(j, "containerEdits");
x.devices = j.at("devices").get<std::vector<Device>>();
x.kind = j.at("kind").get<std::string>();
}

inline void to_json(json & j, const Cdi & x) {
j = json::object();
if (x.annotations) {
j["annotations"] = x.annotations;
}
j["cdiVersion"] = x.cdiVersion;
if (x.containerEdits) {
j["containerEdits"] = x.containerEdits;
}
j["devices"] = x.devices;
j["kind"] = x.kind;
}
}
}
}

// clang-format on
