From 1e3417f8d09f71314016cbcc139dbae2320a67e6 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 15 May 2022 03:11:39 +0200 Subject: [PATCH] Fix (de)serialization of std::int8_t/std::uint8_t Those types are not supported by RapidJSON and therefore need extra handling. --- lib/json/reflector.h | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/json/reflector.h b/lib/json/reflector.h index e2c89c6..8a2e0fc 100644 --- a/lib/json/reflector.h +++ b/lib/json/reflector.h @@ -148,12 +148,24 @@ inline void push(const Type &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAP /*! * \brief Pushes the specified integer/float/boolean to the specified value. */ -template , std::is_floating_point> * = nullptr> +template , Traits::Not>, Traits::Not>>, + std::is_floating_point> * = nullptr> inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator) { value.Set(reflectable, allocator); } +/*! + * \brief Pushes the specified 8-bit integer to the specified value. + */ +template , std::is_same> * = nullptr> +inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator) +{ + value.Set(static_cast(reflectable), allocator); +} + /*! * \brief Pushes the specified enumeration item to the specified value. */ @@ -517,7 +529,8 @@ void pull(Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue>, Traits::Any, std::is_floating_point>> * = nullptr> + Traits::EnableIf>, Traits::Not>, + Traits::Not>, Traits::Any, std::is_floating_point>> * = nullptr> inline void pull( Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue> &value, JsonDeserializationErrors *errors) { @@ -530,6 +543,20 @@ inline void pull( reflectable = value.Is() ? value.Get() : static_cast(value.GetDouble()); } +/*! + * \brief Pulls the integer or float from the specified value which is supposed and checked to contain the right type. + */ +template , std::is_same> * = nullptr> +inline void pull( + Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue> &value, JsonDeserializationErrors *errors) +{ + int i = 0; + pull(i, value, errors); + if (value.IsNumber()) { + reflectable = static_cast(i); + } +} + /*! * \brief Pulls the boolean from the specified value which is supposed and checked to contain the right type. */