diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-16 07:59:59 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-16 07:59:59 +0100 |
commit | 07716595e0c26ba6d19ee6c498280508ca5aa6c2 (patch) | |
tree | da22b4d88e63419a366c48037cbef14f8f43a2b4 /serialize/corrade-array.hpp | |
parent | ae53b814c310d1996db0b818151ef7b205d03b7b (diff) |
a
Diffstat (limited to 'serialize/corrade-array.hpp')
-rw-r--r-- | serialize/corrade-array.hpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/serialize/corrade-array.hpp b/serialize/corrade-array.hpp new file mode 100644 index 00000000..ea450870 --- /dev/null +++ b/serialize/corrade-array.hpp @@ -0,0 +1,28 @@ +#pragma once +#include "compat/exception.hpp" +#include <Corrade/Containers/Array.h> +#include <nlohmann/json.hpp> + +namespace nlohmann { + +template<typename T, typename D> +struct adl_serializer<Corrade::Containers::Array<T, D>> +{ + static void to_json(json& j, const Corrade::Containers::Array<T, D>& array) + { + j.clear(); + for (const T& x : array) + j.push_back(x); + } + + static void from_json(const json& j, Corrade::Containers::Array<T>& array) + { + fm_soft_assert(j.is_array()); + auto size = (uint32_t)j.size(); + array = Corrade::Containers::Array<T>{size}; + for (uint32_t i = 0; i < size; i++) + array[i] = j[i]; + } +}; + +} // namespace nlohmann |