Serialize and deserialize.

This commit is contained in:
Pcornat 2022-01-14 22:06:25 +01:00
parent 9142896237
commit e762ab05c6
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0

View File

@ -2,6 +2,9 @@
#define BILLYSHEET_ADRESSE_HPP #define BILLYSHEET_ADRESSE_HPP
#include <cstdint> #include <cstdint>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
namespace character::characteristic { namespace character::characteristic {
class Adresse final { class Adresse final {
@ -15,7 +18,29 @@ namespace character::characteristic {
Adresse() noexcept = default; Adresse() noexcept = default;
~Adresse() noexcept = default; ~Adresse() noexcept = default;
[[nodiscard]] std::uint32_t get_base() const { return base; }
[[nodiscard]] std::uint32_t get_carac() const { return carac; }
[[nodiscard]] std::uint32_t get_materiel() const { return materiel; }
[[nodiscard]] std::uint32_t get_additional() const { return additional; }
friend void from_json(const json &j, Adresse &adresse) {
const_cast<std::uint32_t&>(adresse.base) = j.at("base");
adresse.carac = j.at("carac");
adresse.materiel =j.at("materiel");
adresse.additional =j.at("additional");
}
}; };
void to_json(json &j, const Adresse &adresse) {
j.emplace("base", adresse.get_base());
j.emplace("carac", adresse.get_carac());
j.emplace("materiel", adresse.get_materiel());
j.emplace("additional", adresse.get_additional());
}
} }