forked from bblanchon/ArduinoJson
Changed return type of convertToJson() and Converter::toJson() to void
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
HEAD
|
||||
----
|
||||
|
||||
* Changed return type of `convertToJson()` and `Converter<T>::toJson()` to `void`
|
||||
|
||||
v6.18.2 (2021-07-19)
|
||||
-------
|
||||
|
||||
|
@ -13,11 +13,10 @@ struct Date {
|
||||
int year;
|
||||
};
|
||||
|
||||
bool convertToJson(const Date& src, JsonVariant dst) {
|
||||
void convertToJson(const Date& src, JsonVariant dst) {
|
||||
dst["day"] = src.day;
|
||||
dst["month"] = src.month;
|
||||
dst["year"] = src.year;
|
||||
return true;
|
||||
}
|
||||
|
||||
void convertFromJson(JsonVariantConst src, Date& dst) {
|
||||
@ -92,10 +91,9 @@ class Complex {
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
template <>
|
||||
struct Converter<Complex> {
|
||||
static bool toJson(const Complex& src, VariantRef dst) {
|
||||
static void toJson(const Complex& src, VariantRef dst) {
|
||||
dst["real"] = src.real();
|
||||
dst["imag"] = src.imag();
|
||||
return true;
|
||||
}
|
||||
|
||||
static Complex fromJson(VariantConstRef src) {
|
||||
|
@ -173,8 +173,8 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
|
||||
|
||||
template <>
|
||||
struct Converter<ArrayConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ArrayConstRef fromJson(VariantConstRef src) {
|
||||
@ -189,8 +189,8 @@ struct Converter<ArrayConstRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<ArrayRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ArrayRef fromJson(VariantRef src) {
|
||||
|
@ -178,8 +178,8 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
|
||||
return _array.getOrAddElement(_index);
|
||||
}
|
||||
|
||||
friend bool convertToJson(const this_type& src, VariantRef dst) {
|
||||
return dst.set(src.getUpstreamElement());
|
||||
friend void convertToJson(const this_type& src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamElement());
|
||||
}
|
||||
|
||||
TArray _array;
|
||||
|
@ -337,8 +337,8 @@ class JsonDocument : public Visitable {
|
||||
JsonDocument& operator=(const JsonDocument&);
|
||||
};
|
||||
|
||||
inline bool convertToJson(const JsonDocument& src, VariantRef dst) {
|
||||
return dst.set(src.as<VariantConstRef>());
|
||||
inline void convertToJson(const JsonDocument& src, VariantRef dst) {
|
||||
dst.set(src.as<VariantConstRef>());
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -187,8 +187,8 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
|
||||
return _object.getOrAddMember(_key);
|
||||
}
|
||||
|
||||
friend bool convertToJson(const this_type &src, VariantRef dst) {
|
||||
return dst.set(src.getUpstreamMember());
|
||||
friend void convertToJson(const this_type &src, VariantRef dst) {
|
||||
dst.set(src.getUpstreamMember());
|
||||
}
|
||||
|
||||
TObject _object;
|
||||
|
@ -239,8 +239,8 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
|
||||
|
||||
template <>
|
||||
struct Converter<ObjectConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ObjectConstRef fromJson(VariantConstRef src) {
|
||||
@ -255,8 +255,8 @@ struct Converter<ObjectConstRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<ObjectRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static ObjectRef fromJson(VariantRef src) {
|
||||
|
@ -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
|
||||
|
@ -85,7 +85,8 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(const T &value) const {
|
||||
return Converter<T>::toJson(value, *this);
|
||||
Converter<T>::toJson(value, *this);
|
||||
return _pool && !_pool->overflowed();
|
||||
}
|
||||
|
||||
bool ARDUINOJSON_DEPRECATED(
|
||||
@ -94,7 +95,8 @@ class VariantRef : public VariantRefBase<VariantData>,
|
||||
|
||||
template <typename T>
|
||||
FORCE_INLINE bool set(T *value) const {
|
||||
return Converter<T *>::toJson(value, *this);
|
||||
Converter<T *>::toJson(value, *this);
|
||||
return _pool && !_pool->overflowed();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -339,8 +341,8 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
|
||||
|
||||
template <>
|
||||
struct Converter<VariantRef> {
|
||||
static bool toJson(VariantRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static VariantRef fromJson(VariantRef src) {
|
||||
@ -362,8 +364,8 @@ struct Converter<VariantRef> {
|
||||
|
||||
template <>
|
||||
struct Converter<VariantConstRef> {
|
||||
static bool toJson(VariantConstRef src, VariantRef dst) {
|
||||
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
static void toJson(VariantConstRef src, VariantRef dst) {
|
||||
variantCopyFrom(getData(dst), getData(src), getPool(dst));
|
||||
}
|
||||
|
||||
static VariantConstRef fromJson(VariantConstRef src) {
|
||||
|
Reference in New Issue
Block a user