From 0e479894f2bcb6a545f1f17db381c471b6b984a0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 11 Jun 2022 13:38:05 +0200 Subject: a --- anim/serialize.cpp | 24 ++++++++++++++++++------ corrade | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/anim/serialize.cpp b/anim/serialize.cpp index be29dd28..6547f9c4 100644 --- a/anim/serialize.cpp +++ b/anim/serialize.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -17,16 +18,27 @@ struct adl_serializer final { static void from_json(const json& j, Magnum::Vector2i& x); }; -void adl_serializer::to_json(json& j, const Magnum::Vector2i& x) +void adl_serializer::to_json(json& j, const Magnum::Vector2i& val) { - j["x"] = x[0]; - j["y"] = x[1]; + char buf[64]; + snprintf(buf, sizeof(buf), "%d x %d", val[0], val[1]); + j = buf; } -void adl_serializer::from_json(const json& j, Magnum::Vector2i& x) +void adl_serializer::from_json(const json& j, Magnum::Vector2i& val) { - j.at("x").get_to(x[0]); - j.at("y").get_to(x[1]); + std::string str = j; + int x = 0, y = 0, n = 0; + int ret = std::sscanf(str.c_str(), "%d x %d%n", &x, &y, &n); + if (ret != 2 || (std::size_t)n != str.size()) + { + std::string msg; msg.reserve(64 + str.size()); + msg += "failed to parse string '"; + msg += str; + msg += "' as Magnum::Vector2i"; + throw std::out_of_range(msg); + } + val = { x, y }; } } // namespace nlohmann diff --git a/corrade b/corrade index a7da501f..e616d628 160000 --- a/corrade +++ b/corrade @@ -1 +1 @@ -Subproject commit a7da501f5e0e3f748bb8087b3a60dd9be610f3b7 +Subproject commit e616d628dbb3e6f68f530be89ff06d7b3cfa1379 -- cgit v1.2.3