From e762ab05c681de8699408f9e2df9bd10206e0083 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Fri, 14 Jan 2022 22:06:25 +0100 Subject: [PATCH] Serialize and deserialize. --- include/characteristic/adresse.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/characteristic/adresse.hpp b/include/characteristic/adresse.hpp index ab2fdb2..0dda21e 100644 --- a/include/characteristic/adresse.hpp +++ b/include/characteristic/adresse.hpp @@ -2,6 +2,9 @@ #define BILLYSHEET_ADRESSE_HPP #include +#include + +using json = nlohmann::json; namespace character::characteristic { class Adresse final { @@ -15,7 +18,29 @@ namespace character::characteristic { 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(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()); + } }