Ver código fonte

refactor: enable 64-bit integer usage in Jsonizer and unsigned support

Sam Jaffe 2 anos atrás
pai
commit
ad15cf48a4
1 arquivos alterados com 6 adições e 2 exclusões
  1. 6 2
      include/serializer/jsonizer.tpp

+ 6 - 2
include/serializer/jsonizer.tpp

@@ -59,8 +59,10 @@ template <typename T> Json::Value Jsonizer::to_json(T const & value) const {
     return static_cast<double>(value);
   } else if constexpr (std::is_same_v<bool, T>) {
     return value;
+  } else if constexpr (std::is_arithmetic_v<T> && std::is_unsigned_v<T>) {
+    return static_cast<uint64_t>(value);
   } else if constexpr (std::is_arithmetic_v<T>) {
-    return static_cast<int>(value);
+    return static_cast<int64_t>(value);
   } else if constexpr (detail::is_associative_container_v<T>) {
     Json::Value rval;
     using K = std::decay_t<typename T::key_type>;
@@ -147,8 +149,10 @@ void Jsonizer::from_json(T & value, Json::Value const & json) const {
     value = static_cast<T>(json.asDouble());
   } else if constexpr (std::is_same_v<bool, T>) {
     value = json.asBool();
+  } else if constexpr (std::is_arithmetic_v<T> && std::is_unsigned_v<T>) {
+    value = static_cast<T>(json.asUInt64());
   } else if constexpr (std::is_arithmetic_v<T>) {
-    value = static_cast<T>(json.asInt());
+    value = static_cast<T>(json.asInt64());
   } else {
     from_json_impl(value, json);
   }