mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Changed return type of convertToJson() and Converter::toJson() to void
This commit is contained in:
		| @@ -12,9 +12,9 @@ namespace ARDUINOJSON_NAMESPACE { | ||||
|  | ||||
| template <typename T, typename Enable> | ||||
| struct Converter { | ||||
|   static bool toJson(const T& src, VariantRef dst) { | ||||
|   static void toJson(const T& src, VariantRef dst) { | ||||
|     // clang-format off | ||||
|     return convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/ | ||||
|     convertToJson(src, dst); // Error here? See https://arduinojson.org/v6/unsupported-set/ | ||||
|     // clang-format on | ||||
|   } | ||||
|  | ||||
| @@ -38,13 +38,11 @@ template <typename T> | ||||
| struct Converter< | ||||
|     T, typename enable_if<is_integral<T>::value && !is_same<bool, T>::value && | ||||
|                           !is_same<char, T>::value>::type> { | ||||
|   static bool toJson(T src, VariantRef dst) { | ||||
|   static void toJson(T src, VariantRef dst) { | ||||
|     VariantData* data = getData(dst); | ||||
|     ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T); | ||||
|     if (!data) | ||||
|       return false; | ||||
|     data->setInteger(src); | ||||
|     return true; | ||||
|     if (data) | ||||
|       data->setInteger(src); | ||||
|   } | ||||
|  | ||||
|   static T fromJson(VariantConstRef src) { | ||||
| @@ -61,8 +59,8 @@ struct Converter< | ||||
|  | ||||
| template <typename T> | ||||
| struct Converter<T, typename enable_if<is_enum<T>::value>::type> { | ||||
|   static bool toJson(T src, VariantRef dst) { | ||||
|     return dst.set(static_cast<Integer>(src)); | ||||
|   static void toJson(T src, VariantRef dst) { | ||||
|     dst.set(static_cast<Integer>(src)); | ||||
|   } | ||||
|  | ||||
|   static T fromJson(VariantConstRef src) { | ||||
| @@ -78,12 +76,10 @@ struct Converter<T, typename enable_if<is_enum<T>::value>::type> { | ||||
|  | ||||
| template <> | ||||
| struct Converter<bool> { | ||||
|   static bool toJson(bool src, VariantRef dst) { | ||||
|   static void toJson(bool src, VariantRef dst) { | ||||
|     VariantData* data = getData(dst); | ||||
|     if (!data) | ||||
|       return false; | ||||
|     data->setBoolean(src); | ||||
|     return true; | ||||
|     if (data) | ||||
|       data->setBoolean(src); | ||||
|   } | ||||
|  | ||||
|   static bool fromJson(VariantConstRef src) { | ||||
| @@ -99,12 +95,10 @@ struct Converter<bool> { | ||||
|  | ||||
| template <typename T> | ||||
| struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> { | ||||
|   static bool toJson(T src, VariantRef dst) { | ||||
|   static void toJson(T src, VariantRef dst) { | ||||
|     VariantData* data = getData(dst); | ||||
|     if (!data) | ||||
|       return false; | ||||
|     data->setFloat(static_cast<Float>(src)); | ||||
|     return true; | ||||
|     if (data) | ||||
|       data->setFloat(static_cast<Float>(src)); | ||||
|   } | ||||
|  | ||||
|   static T fromJson(VariantConstRef src) { | ||||
| @@ -120,8 +114,8 @@ struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> { | ||||
|  | ||||
| template <> | ||||
| struct Converter<const char*> { | ||||
|   static bool toJson(const char* src, VariantRef dst) { | ||||
|     return variantSetString(getData(dst), adaptString(src), getPool(dst)); | ||||
|   static void toJson(const char* src, VariantRef dst) { | ||||
|     variantSetString(getData(dst), adaptString(src), getPool(dst)); | ||||
|   } | ||||
|  | ||||
|   static const char* fromJson(VariantConstRef src) { | ||||
| @@ -163,12 +157,10 @@ canConvertFromJson(VariantConstRef src, const T&) { | ||||
|  | ||||
| template <> | ||||
| struct Converter<SerializedValue<const char*> > { | ||||
|   static bool toJson(SerializedValue<const char*> src, VariantRef dst) { | ||||
|   static void toJson(SerializedValue<const char*> src, VariantRef dst) { | ||||
|     VariantData* data = getData(dst); | ||||
|     if (!data) | ||||
|       return false; | ||||
|     data->setLinkedRaw(src); | ||||
|     return true; | ||||
|     if (data) | ||||
|       data->setLinkedRaw(src); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| @@ -178,10 +170,11 @@ struct Converter<SerializedValue<const char*> > { | ||||
| template <typename T> | ||||
| struct Converter<SerializedValue<T>, | ||||
|                  typename enable_if<!is_same<const char*, T>::value>::type> { | ||||
|   static bool toJson(SerializedValue<T> src, VariantRef dst) { | ||||
|   static void toJson(SerializedValue<T> src, VariantRef dst) { | ||||
|     VariantData* data = getData(dst); | ||||
|     MemoryPool* pool = getPool(dst); | ||||
|     return data != 0 && data->setOwnedRaw(src, pool); | ||||
|     if (data) | ||||
|       data->setOwnedRaw(src, pool); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| @@ -189,9 +182,8 @@ struct Converter<SerializedValue<T>, | ||||
|  | ||||
| template <> | ||||
| struct Converter<decltype(nullptr)> { | ||||
|   static bool toJson(decltype(nullptr), VariantRef dst) { | ||||
|   static void toJson(decltype(nullptr), VariantRef dst) { | ||||
|     variantSetNull(getData(dst)); | ||||
|     return true; | ||||
|   } | ||||
|   static decltype(nullptr) fromJson(VariantConstRef) { | ||||
|     return nullptr; | ||||
| @@ -247,20 +239,19 @@ class MemoryPoolPrint : public Print { | ||||
|   size_t _capacity; | ||||
| }; | ||||
|  | ||||
| inline bool convertToJson(const ::Printable& src, VariantRef dst) { | ||||
| inline void convertToJson(const ::Printable& src, VariantRef dst) { | ||||
|   MemoryPool* pool = getPool(dst); | ||||
|   VariantData* data = getData(dst); | ||||
|   if (!pool || !data) | ||||
|     return false; | ||||
|     return; | ||||
|   MemoryPoolPrint print(pool); | ||||
|   src.printTo(print); | ||||
|   if (print.overflowed()) { | ||||
|     pool->markAsOverflowed(); | ||||
|     data->setNull(); | ||||
|     return false; | ||||
|     return; | ||||
|   } | ||||
|   data->setStringPointer(print.c_str(), storage_policies::store_by_copy()); | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user