upgrade to 6.18

This commit is contained in:
proddy
2021-05-06 10:10:37 +02:00
parent 3c1b30a5e4
commit 9211d29e17
144 changed files with 1001 additions and 906 deletions

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,9 +1,11 @@
ArduinoJson: change log ArduinoJson: change log
======================= =======================
HEAD v6.18.0 (2021-05-05)
---- -------
* Added support for custom converters (issue #687)
* Added support for `Printable` (issue #1444)
* Removed support for `char` values, see below (issue #1498) * Removed support for `char` values, see below (issue #1498)
* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported` * `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported`
* `deserializeMsgPack()` inserts `null` instead of returning `NotSupported` * `deserializeMsgPack()` inserts `null` instead of returning `NotSupported`
@@ -11,9 +13,17 @@ HEAD
* Added `JsonVariant::is<JsonArrayConst/JsonObjectConst>()` (issue #1412) * Added `JsonVariant::is<JsonArrayConst/JsonObjectConst>()` (issue #1412)
* Added `JsonVariant::is<JsonVariant/JsonVariantConst>()` (issue #1412) * Added `JsonVariant::is<JsonVariant/JsonVariantConst>()` (issue #1412)
* Changed `JsonVariantConst::is<JsonArray/JsonObject>()` to return `false` (issue #1412) * Changed `JsonVariantConst::is<JsonArray/JsonObject>()` to return `false` (issue #1412)
* Simplified `JsonVariant::as<T>()` to always return `T` (see below)
* Updated folders list in `.mbedignore` (PR #1515 by @AGlass0fMilk)
* Fixed member-call-on-null-pointer in `getMember()` when array is empty
* `serializeMsgPack(doc, buffer, size)` doesn't add null-terminator anymore (issue #1545)
* `serializeJson(doc, buffer, size)` adds null-terminator only if there is enough room
* PlatformIO: set `build.libArchive` to `false` (PR #1550 by @askreet)
> ### BREAKING CHANGES > ### BREAKING CHANGES
> >
> #### Support for `char` removed
>
> We cannot cast a `JsonVariant` to a `char` anymore, so the following will break: > We cannot cast a `JsonVariant` to a `char` anymore, so the following will break:
> ```c++ > ```c++
> char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)' > char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)'
@@ -33,6 +43,31 @@ HEAD
> int8_t age; > int8_t age;
> doc["age"] = age; // OK > doc["age"] = age; // OK
> ``` > ```
> A deprecation warning with the message "Support for `char` is deprecated, use `int8_t` or `uint8_t` instead" was added to allow a smooth transition.
>
> #### `as<T>()` always returns `T`
>
> Previously, `JsonVariant::as<T>()` could return a type different from `T`.
> The most common example is `as<char*>()` that returned a `const char*`.
> While this feature simplified a few use cases, it was confusing and complicated the
> implementation of custom converters.
>
> Starting from this version, `as<T>` doesn't try to auto-correct the return type and always return `T`,
> which means that you cannot write this anymore:
>
> ```c++
> Serial.println(doc["sensor"].as<char*>()); // error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
> ```
>
> Instead, you must write:
>
> ```c++
> Serial.println(doc["sensor"].as<const char*>()); // OK
> ```
>
> A deprecation warning with the message "Replace `as<char*>()` with `as<const char*>()`" was added to allow a smooth transition.
>
> #### `DeserializationError::NotSupported` removed
> >
> On a different topic, `DeserializationError::NotSupported` has been removed. > On a different topic, `DeserializationError::NotSupported` has been removed.
> Instead of returning this error: > Instead of returning this error:
@@ -40,7 +75,9 @@ HEAD
> * `deserializeJson()` leaves `\uXXXX` unchanged (only when `ARDUINOJSON_DECODE_UNICODE` is `0`) > * `deserializeJson()` leaves `\uXXXX` unchanged (only when `ARDUINOJSON_DECODE_UNICODE` is `0`)
> * `deserializeMsgPack()` replaces unsupported values with `null`s > * `deserializeMsgPack()` replaces unsupported values with `null`s
> >
> Lastly, a very minor change conserns `JsonVariantConst::is<T>()`. > #### Const-aware `is<T>()`
>
> Lastly, a very minor change concerns `JsonVariantConst::is<T>()`.
> It used to return `true` for `JsonArray` and `JsonOject`, but now it returns `false`. > It used to return `true` for `JsonArray` and `JsonOject`, but now it returns `false`.
> Instead, you must use `JsonArrayConst` and `JsonObjectConst`. > Instead, you must use `JsonArrayConst` and `JsonObjectConst`.

View File

@@ -2,7 +2,7 @@
--- ---
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.17.3)](https://www.ardu-badge.com/ArduinoJson/6.17.3) [![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.18.0)](https://www.ardu-badge.com/ArduinoJson/6.18.0)
[![Continuous Integration](https://github.com/bblanchon/ArduinoJson/workflows/Continuous%20Integration/badge.svg?branch=6.x)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x) [![Continuous Integration](https://github.com/bblanchon/ArduinoJson/workflows/Continuous%20Integration/badge.svg?branch=6.x)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
@@ -34,10 +34,11 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* Deduplicates strings * Deduplicates strings
* Versatile * Versatile
* [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme) * [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme)
* Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme) * Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/?utm_source=github&utm_medium=readme) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme)
* Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme) * Supports [Arduino's `Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/?utm_source=github&utm_medium=readme) and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme)
* [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme) * [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme)
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer) * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer)
* Supports custom converters
* Portable * Portable
* Usable on any C++ project (not limited to Arduino) * Usable on any C++ project (not limited to Arduino)
* Compatible with C++98 * Compatible with C++98
@@ -86,7 +87,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) * [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme) * [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme)
* [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme) * [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme)
* [Changelog](changelog.md) * [Changelog](CHANGELOG.md)
* Vibrant user community * Vibrant user community
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search) * Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search)
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson) * [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -27,7 +27,7 @@
#include "ArduinoJson/Collection/CollectionImpl.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp"
#include "ArduinoJson/Object/MemberProxy.hpp" #include "ArduinoJson/Object/MemberProxy.hpp"
#include "ArduinoJson/Object/ObjectImpl.hpp" #include "ArduinoJson/Object/ObjectImpl.hpp"
#include "ArduinoJson/Variant/VariantAsImpl.hpp" #include "ArduinoJson/Variant/ConverterImpl.hpp"
#include "ArduinoJson/Variant/VariantCompare.hpp" #include "ArduinoJson/Variant/VariantCompare.hpp"
#include "ArduinoJson/Variant/VariantImpl.hpp" #include "ArduinoJson/Variant/VariantImpl.hpp"

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -164,4 +164,42 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
private: private:
MemoryPool* _pool; MemoryPool* _pool;
}; };
template <>
struct Converter<ArrayConstRef> {
static bool toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
}
static ArrayConstRef fromJson(VariantConstRef src) {
return ArrayConstRef(variantAsArray(getData(src)));
}
static bool checkJson(VariantConstRef src) {
const VariantData* data = getData(src);
return data && data->isArray();
}
};
template <>
struct Converter<ArrayRef> {
static bool toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
}
static ArrayRef fromJson(VariantRef src) {
VariantData* data = getData(src);
MemoryPool* pool = getPool(src);
return ArrayRef(pool, data != 0 ? data->asArray() : 0);
}
static bool checkJson(VariantConstRef) {
return false;
}
static bool checkJson(VariantRef src) {
VariantData* data = getData(src);
return data && data->isArray();
}
};
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -9,6 +9,8 @@
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
// Forward declarations. // Forward declarations.
class ArrayRef;
class ObjectRef;
template <typename> template <typename>
class ElementProxy; class ElementProxy;

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -65,10 +65,18 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
} }
template <typename T> template <typename T>
FORCE_INLINE typename VariantAs<T>::type as() const { FORCE_INLINE typename enable_if<!is_same<T, char*>::value, T>::type as()
const {
return getUpstreamElement().template as<T>(); return getUpstreamElement().template as<T>();
} }
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, char*>::value, const char*>::type
ARDUINOJSON_DEPRECATED("Replace as<char*>() with as<const char*>()")
as() const {
return as<const char*>();
}
template <typename T> template <typename T>
FORCE_INLINE operator T() const { FORCE_INLINE operator T() const {
return getUpstreamElement(); return getUpstreamElement();
@@ -170,6 +178,10 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
return _array.getOrAddElement(_index); return _array.getOrAddElement(_index);
} }
friend bool convertToJson(const this_type& src, VariantRef dst) {
return dst.set(src.getUpstreamElement());
}
TArray _array; TArray _array;
const size_t _index; const size_t _index;
}; };

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -76,7 +76,8 @@ class ArrayCopier1D : public Visitor<size_t> {
VariantSlot* slot = array.head(); VariantSlot* slot = array.head();
while (slot != 0 && size < _capacity) { while (slot != 0 && size < _capacity) {
_destination[size++] = variantAs<T>(slot->data()); _destination[size++] =
Converter<T>::fromJson(VariantConstRef(slot->data()));
slot = slot->next(); slot = slot->next();
} }
return size; return size;

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -115,6 +115,8 @@ inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
} }
inline VariantSlot* CollectionData::getSlot(size_t index) const { inline VariantSlot* CollectionData::getSlot(size_t index) const {
if (!_head)
return 0;
return _head->next(index); return _head->next(index);
} }

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -21,12 +21,12 @@ class JsonDocument : public Visitable {
} }
template <typename T> template <typename T>
typename VariantAs<T>::type as() { T as() {
return getVariant().template as<T>(); return getVariant().template as<T>();
} }
template <typename T> template <typename T>
typename VariantConstAs<T>::type as() const { T as() const {
return getVariant().template as<T>(); return getVariant().template as<T>();
} }
@@ -70,7 +70,7 @@ class JsonDocument : public Visitable {
} }
bool set(const JsonDocument& src) { bool set(const JsonDocument& src) {
return to<VariantRef>().set(src.as<VariantRef>()); return to<VariantRef>().set(src.as<VariantConstRef>());
} }
template <typename T> template <typename T>
@@ -337,4 +337,8 @@ class JsonDocument : public Visitable {
JsonDocument& operator=(const JsonDocument&); JsonDocument& operator=(const JsonDocument&);
}; };
inline bool convertToJson(const JsonDocument& src, VariantRef dst) {
return dst.set(src.as<VariantConstRef>());
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -14,6 +14,8 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename TWriter> template <typename TWriter>
class JsonSerializer : public Visitor<size_t> { class JsonSerializer : public Visitor<size_t> {
public: public:
static const bool producesText = true;
JsonSerializer(TWriter writer) : _formatter(writer) {} JsonSerializer(TWriter writer) : _formatter(writer) {}
FORCE_INLINE size_t visitArray(const CollectionData &array) { FORCE_INLINE size_t visitArray(const CollectionData &array) {
@@ -71,13 +73,13 @@ class JsonSerializer : public Visitor<size_t> {
return bytesWritten(); return bytesWritten();
} }
size_t visitNegativeInteger(UInt value) { size_t visitSignedInteger(Integer value) {
_formatter.writeNegativeInteger(value); _formatter.writeInteger(value);
return bytesWritten(); return bytesWritten();
} }
size_t visitPositiveInteger(UInt value) { size_t visitUnsignedInteger(UInt value) {
_formatter.writePositiveInteger(value); _formatter.writeInteger(value);
return bytesWritten(); return bytesWritten();
} }

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -16,7 +16,7 @@ class PrettyJsonSerializer : public JsonSerializer<TWriter> {
typedef JsonSerializer<TWriter> base; typedef JsonSerializer<TWriter> base;
public: public:
PrettyJsonSerializer(TWriter &writer) : base(writer), _nesting(0) {} PrettyJsonSerializer(TWriter writer) : base(writer), _nesting(0) {}
size_t visitArray(const CollectionData &array) { size_t visitArray(const CollectionData &array) {
VariantSlot *slot = array.head(); VariantSlot *slot = array.head();

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -12,6 +12,7 @@
#include <ArduinoJson/Numbers/Integer.hpp> #include <ArduinoJson/Numbers/Integer.hpp>
#include <ArduinoJson/Polyfills/assert.hpp> #include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/attributes.hpp> #include <ArduinoJson/Polyfills/attributes.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Serialization/CountingDecorator.hpp> #include <ArduinoJson/Serialization/CountingDecorator.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -75,28 +76,31 @@ class TextFormatter {
FloatParts<T> parts(value); FloatParts<T> parts(value);
writePositiveInteger(parts.integral); writeInteger(parts.integral);
if (parts.decimalPlaces) if (parts.decimalPlaces)
writeDecimals(parts.decimal, parts.decimalPlaces); writeDecimals(parts.decimal, parts.decimalPlaces);
if (parts.exponent < 0) { if (parts.exponent) {
writeRaw("e-");
writePositiveInteger(-parts.exponent);
}
if (parts.exponent > 0) {
writeRaw('e'); writeRaw('e');
writePositiveInteger(parts.exponent); writeInteger(parts.exponent);
} }
} }
void writeNegativeInteger(UInt value) {
writeRaw('-');
writePositiveInteger(value);
}
template <typename T> template <typename T>
void writePositiveInteger(T value) { typename enable_if<is_signed<T>::value>::type writeInteger(T value) {
typedef typename make_unsigned<T>::type unsigned_type;
unsigned_type unsigned_value;
if (value < 0) {
writeRaw('-');
unsigned_value = unsigned_type(unsigned_type(~value) + 1);
} else {
unsigned_value = unsigned_type(value);
}
writeInteger(unsigned_value);
}
template <typename T>
typename enable_if<is_unsigned<T>::value>::type writeInteger(T value) {
char buffer[22]; char buffer[22];
char *end = buffer + sizeof(buffer); char *end = buffer + sizeof(buffer);
char *begin = end; char *begin = end;

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -27,7 +27,7 @@ class MsgPackDeserializer {
template <typename TFilter> template <typename TFilter>
DeserializationError parse(VariantData &variant, TFilter filter, DeserializationError parse(VariantData &variant, TFilter filter,
NestingLimit nestingLimit) { NestingLimit nestingLimit) {
parseVariant(variant, filter, nestingLimit); parseVariant(&variant, filter, nestingLimit);
return _foundSomething ? _error : DeserializationError::EmptyInput; return _foundSomething ? _error : DeserializationError::EmptyInput;
} }
@@ -41,9 +41,9 @@ class MsgPackDeserializer {
} }
template <typename TFilter> template <typename TFilter>
bool parseVariant(VariantData &variant, TFilter filter, bool parseVariant(VariantData *variant, TFilter filter,
NestingLimit nestingLimit) { NestingLimit nestingLimit) {
uint8_t code = 0; uint8_t code = 0; // TODO: why do we need to initialize this variable?
if (!readByte(code)) if (!readByte(code))
return false; return false;
@@ -61,12 +61,12 @@ class MsgPackDeserializer {
case 0xc2: case 0xc2:
if (allowValue) if (allowValue)
variant.setBoolean(false); variant->setBoolean(false);
return true; return true;
case 0xc3: case 0xc3:
if (allowValue) if (allowValue)
variant.setBoolean(true); variant->setBoolean(true);
return true; return true;
case 0xc4: // bin 8 (not supported) case 0xc4: // bin 8 (not supported)
@@ -217,7 +217,7 @@ class MsgPackDeserializer {
} }
if (allowValue) if (allowValue)
variant.setInteger(static_cast<int8_t>(code)); variant->setInteger(static_cast<int8_t>(code));
return true; return true;
} }
@@ -263,39 +263,39 @@ class MsgPackDeserializer {
} }
template <typename T> template <typename T>
bool readInteger(VariantData &variant) { bool readInteger(VariantData *variant) {
T value; T value;
if (!readInteger(value)) if (!readInteger(value))
return false; return false;
variant.setInteger(value); variant->setInteger(value);
return true; return true;
} }
template <typename T> template <typename T>
typename enable_if<sizeof(T) == 4, bool>::type readFloat( typename enable_if<sizeof(T) == 4, bool>::type readFloat(
VariantData &variant) { VariantData *variant) {
T value; T value;
if (!readBytes(value)) if (!readBytes(value))
return false; return false;
fixEndianess(value); fixEndianess(value);
variant.setFloat(value); variant->setFloat(value);
return true; return true;
} }
template <typename T> template <typename T>
typename enable_if<sizeof(T) == 8, bool>::type readDouble( typename enable_if<sizeof(T) == 8, bool>::type readDouble(
VariantData &variant) { VariantData *variant) {
T value; T value;
if (!readBytes(value)) if (!readBytes(value))
return false; return false;
fixEndianess(value); fixEndianess(value);
variant.setFloat(value); variant->setFloat(value);
return true; return true;
} }
template <typename T> template <typename T>
typename enable_if<sizeof(T) == 4, bool>::type readDouble( typename enable_if<sizeof(T) == 4, bool>::type readDouble(
VariantData &variant) { VariantData *variant) {
uint8_t i[8]; // input is 8 bytes uint8_t i[8]; // input is 8 bytes
T value; // output is 4 bytes T value; // output is 4 bytes
uint8_t *o = reinterpret_cast<uint8_t *>(&value); uint8_t *o = reinterpret_cast<uint8_t *>(&value);
@@ -303,12 +303,12 @@ class MsgPackDeserializer {
return false; return false;
doubleToFloat(i, o); doubleToFloat(i, o);
fixEndianess(value); fixEndianess(value);
variant.setFloat(value); variant->setFloat(value);
return true; return true;
} }
template <typename T> template <typename T>
bool readString(VariantData &variant) { bool readString(VariantData *variant) {
T size; T size;
if (!readInteger(size)) if (!readInteger(size))
return false; return false;
@@ -331,10 +331,10 @@ class MsgPackDeserializer {
return skipBytes(size); return skipBytes(size);
} }
bool readString(VariantData &variant, size_t n) { bool readString(VariantData *variant, size_t n) {
if (!readString(n)) if (!readString(n))
return false; return false;
variant.setStringPointer(_stringStorage.save(), variant->setStringPointer(_stringStorage.save(),
typename TStringStorage::storage_policy()); typename TStringStorage::storage_policy());
return true; return true;
} }
@@ -357,7 +357,7 @@ class MsgPackDeserializer {
} }
template <typename TSize, typename TFilter> template <typename TSize, typename TFilter>
bool readArray(VariantData &variant, TFilter filter, bool readArray(VariantData *variant, TFilter filter,
NestingLimit nestingLimit) { NestingLimit nestingLimit) {
TSize size; TSize size;
if (!readInteger(size)) if (!readInteger(size))
@@ -366,7 +366,7 @@ class MsgPackDeserializer {
} }
template <typename TFilter> template <typename TFilter>
bool readArray(VariantData &variant, size_t n, TFilter filter, bool readArray(VariantData *variant, size_t n, TFilter filter,
NestingLimit nestingLimit) { NestingLimit nestingLimit) {
if (nestingLimit.reached()) { if (nestingLimit.reached()) {
_error = DeserializationError::TooDeep; _error = DeserializationError::TooDeep;
@@ -375,7 +375,7 @@ class MsgPackDeserializer {
bool allowArray = filter.allowArray(); bool allowArray = filter.allowArray();
CollectionData *array = allowArray ? &variant.toArray() : 0; CollectionData *array = allowArray ? &variant->toArray() : 0;
TFilter memberFilter = filter[0U]; TFilter memberFilter = filter[0U];
@@ -392,7 +392,7 @@ class MsgPackDeserializer {
value = 0; value = 0;
} }
if (!parseVariant(*value, memberFilter, nestingLimit.decrement())) if (!parseVariant(value, memberFilter, nestingLimit.decrement()))
return false; return false;
} }
@@ -400,7 +400,7 @@ class MsgPackDeserializer {
} }
template <typename TSize, typename TFilter> template <typename TSize, typename TFilter>
bool readObject(VariantData &variant, TFilter filter, bool readObject(VariantData *variant, TFilter filter,
NestingLimit nestingLimit) { NestingLimit nestingLimit) {
TSize size; TSize size;
if (!readInteger(size)) if (!readInteger(size))
@@ -409,14 +409,14 @@ class MsgPackDeserializer {
} }
template <typename TFilter> template <typename TFilter>
bool readObject(VariantData &variant, size_t n, TFilter filter, bool readObject(VariantData *variant, size_t n, TFilter filter,
NestingLimit nestingLimit) { NestingLimit nestingLimit) {
if (nestingLimit.reached()) { if (nestingLimit.reached()) {
_error = DeserializationError::TooDeep; _error = DeserializationError::TooDeep;
return false; return false;
} }
CollectionData *object = filter.allowObject() ? &variant.toObject() : 0; CollectionData *object = filter.allowObject() ? &variant->toObject() : 0;
for (; n; --n) { for (; n; --n) {
if (!readKey()) if (!readKey())
@@ -444,7 +444,7 @@ class MsgPackDeserializer {
member = 0; member = 0;
} }
if (!parseVariant(*member, memberFilter, nestingLimit.decrement())) if (!parseVariant(member, memberFilter, nestingLimit.decrement()))
return false; return false;
} }

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -17,6 +17,8 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename TWriter> template <typename TWriter>
class MsgPackSerializer : public Visitor<size_t> { class MsgPackSerializer : public Visitor<size_t> {
public: public:
static const bool producesText = false;
MsgPackSerializer(TWriter writer) : _writer(writer) {} MsgPackSerializer(TWriter writer) : _writer(writer) {}
template <typename T> template <typename T>
@@ -101,30 +103,37 @@ class MsgPackSerializer : public Visitor<size_t> {
return bytesWritten(); return bytesWritten();
} }
size_t visitNegativeInteger(UInt value) { size_t visitSignedInteger(Integer value) {
UInt negated = UInt(~value + 1); if (value > 0) {
if (value <= 0x20) { visitUnsignedInteger(static_cast<UInt>(value));
writeInteger(int8_t(negated)); } else if (value >= -0x20) {
} else if (value <= 0x80) { writeInteger(int8_t(value));
} else if (value >= -0x80) {
writeByte(0xD0); writeByte(0xD0);
writeInteger(int8_t(negated)); writeInteger(int8_t(value));
} else if (value <= 0x8000) { } else if (value >= -0x8000) {
writeByte(0xD1); writeByte(0xD1);
writeInteger(int16_t(negated)); writeInteger(int16_t(value));
} else if (value <= 0x80000000) { }
#if ARDUINOJSON_USE_LONG_LONG
else if (value >= -0x80000000LL)
#else
else
#endif
{
writeByte(0xD2); writeByte(0xD2);
writeInteger(int32_t(negated)); writeInteger(int32_t(value));
} }
#if ARDUINOJSON_USE_LONG_LONG #if ARDUINOJSON_USE_LONG_LONG
else { else {
writeByte(0xD3); writeByte(0xD3);
writeInteger(int64_t(negated)); writeInteger(int64_t(value));
} }
#endif #endif
return bytesWritten(); return bytesWritten();
} }
size_t visitPositiveInteger(UInt value) { size_t visitUnsignedInteger(UInt value) {
if (value <= 0x7F) { if (value <= 0x7F) {
writeInteger(uint8_t(value)); writeInteger(uint8_t(value));
} else if (value <= 0xFF) { } else if (value <= 0xFF) {

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -15,84 +15,86 @@
#endif #endif
#include <ArduinoJson/Numbers/Float.hpp> #include <ArduinoJson/Numbers/Float.hpp>
#include <ArduinoJson/Numbers/FloatTraits.hpp>
#include <ArduinoJson/Numbers/Integer.hpp>
#include <ArduinoJson/Polyfills/limits.hpp> #include <ArduinoJson/Polyfills/limits.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
// uint32 -> int32
// uint64 -> int32
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
typename enable_if<is_integral<TOut>::value && sizeof(TOut) <= sizeof(TIn), typename enable_if<is_integral<TIn>::value && is_unsigned<TIn>::value &&
is_integral<TOut>::value && sizeof(TOut) <= sizeof(TIn),
bool>::type bool>::type
canStorePositiveInteger(TIn value) { canConvertNumber(TIn value) {
return value <= TIn(numeric_limits<TOut>::highest()); return value <= TIn(numeric_limits<TOut>::highest());
} }
// uint32 -> int64
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
typename enable_if<is_integral<TOut>::value && sizeof(TIn) < sizeof(TOut), typename enable_if<is_integral<TIn>::value && is_unsigned<TIn>::value &&
is_integral<TOut>::value && sizeof(TIn) < sizeof(TOut),
bool>::type bool>::type
canStorePositiveInteger(TIn) { canConvertNumber(TIn) {
return true; return true;
} }
// uint32 -> float
// int32 -> float
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
typename enable_if<is_floating_point<TOut>::value, bool>::type typename enable_if<is_integral<TIn>::value && is_floating_point<TOut>::value,
canStorePositiveInteger(TIn) { bool>::type
canConvertNumber(TIn) {
return true; return true;
} }
// int64 -> int32
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
typename enable_if<is_floating_point<TOut>::value, bool>::type typename enable_if<is_integral<TIn>::value && is_signed<TIn>::value &&
canStoreNegativeInteger(TIn) { is_integral<TOut>::value && is_signed<TOut>::value &&
sizeof(TOut) < sizeof(TIn),
bool>::type
canConvertNumber(TIn value) {
return value >= TIn(numeric_limits<TOut>::lowest()) &&
value <= TIn(numeric_limits<TOut>::highest());
}
// int32 -> int32
// int32 -> int64
template <typename TOut, typename TIn>
typename enable_if<is_integral<TIn>::value && is_signed<TIn>::value &&
is_integral<TOut>::value && is_signed<TOut>::value &&
sizeof(TIn) <= sizeof(TOut),
bool>::type
canConvertNumber(TIn) {
return true; return true;
} }
// int32 -> uint32
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
typename enable_if<is_integral<TOut>::value && is_signed<TOut>::value && typename enable_if<is_integral<TIn>::value && is_signed<TIn>::value &&
sizeof(TOut) <= sizeof(TIn), is_integral<TOut>::value && is_unsigned<TOut>::value,
bool>::type bool>::type
canStoreNegativeInteger(TIn value) { canConvertNumber(TIn value) {
return value <= TIn(numeric_limits<TOut>::highest()) + 1; if (value < 0)
}
template <typename TOut, typename TIn>
typename enable_if<is_integral<TOut>::value && is_signed<TOut>::value &&
sizeof(TIn) < sizeof(TOut),
bool>::type
canStoreNegativeInteger(TIn) {
return true;
}
template <typename TOut, typename TIn>
typename enable_if<is_integral<TOut>::value && is_unsigned<TOut>::value,
bool>::type
canStoreNegativeInteger(TIn) {
return false; return false;
return value <= TIn(numeric_limits<TOut>::highest());
} }
// float -> int32
// float -> int64
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
TOut convertPositiveInteger(TIn value) { typename enable_if<is_floating_point<TIn>::value &&
return canStorePositiveInteger<TOut>(value) ? TOut(value) : 0; !is_floating_point<TOut>::value,
} bool>::type
canConvertNumber(TIn value) {
template <typename TOut, typename TIn>
TOut convertNegativeInteger(TIn value) {
return canStoreNegativeInteger<TOut>(value) ? TOut(~value + 1) : 0;
}
template <typename TOut, typename TIn>
typename enable_if<is_floating_point<TOut>::value, TOut>::type convertFloat(
TIn value) {
return TOut(value);
}
template <typename TOut, typename TIn>
typename enable_if<!is_floating_point<TOut>::value, TOut>::type convertFloat(
TIn value) {
return value >= numeric_limits<TOut>::lowest() && return value >= numeric_limits<TOut>::lowest() &&
value <= numeric_limits<TOut>::highest() value <= numeric_limits<TOut>::highest();
? TOut(value) }
: 0;
template <typename TOut, typename TIn>
TOut convertNumber(TIn value) {
return canConvertNumber<TOut>(value) ? TOut(value) : 0;
} }
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -10,7 +10,7 @@
#include <ArduinoJson/Polyfills/ctype.hpp> #include <ArduinoJson/Polyfills/ctype.hpp>
#include <ArduinoJson/Polyfills/math.hpp> #include <ArduinoJson/Polyfills/math.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp> #include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Variant/VariantAs.hpp> #include <ArduinoJson/Variant/Converter.hpp>
#include <ArduinoJson/Variant/VariantData.hpp> #include <ArduinoJson/Variant/VariantData.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -69,12 +69,18 @@ inline bool parseNumber(const char* s, VariantData& result) {
} }
if (*s == '\0') { if (*s == '\0') {
if (is_negative) if (is_negative) {
result.setNegativeInteger(UInt(mantissa)); const mantissa_t sintMantissaMax = mantissa_t(1)
else << (sizeof(Integer) * 8 - 1);
result.setPositiveInteger(UInt(mantissa)); if (mantissa <= sintMantissaMax) {
result.setInteger(Integer(~mantissa + 1));
return true; return true;
} }
} else {
result.setInteger(UInt(mantissa));
return true;
}
}
// avoid mantissa overflow // avoid mantissa overflow
while (mantissa > traits::mantissa_max) { while (mantissa > traits::mantissa_max) {
@@ -142,6 +148,6 @@ inline T parseNumber(const char* s) {
VariantData value; VariantData value;
value.init(); // VariantData is a POD, so it has no constructor value.init(); // VariantData is a POD, so it has no constructor
parseNumber(s, value); parseNumber(s, value);
return variantAs<T>(&value); return Converter<T>::fromJson(VariantConstRef(&value));
} }
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -46,20 +46,6 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
template <typename TValue> template <typename TValue>
FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type &>::type FORCE_INLINE typename enable_if<!is_array<TValue>::value, this_type &>::type
operator=(const TValue &src) { operator=(const TValue &src) {
/********************************************************************
** THIS IS NOT A BUG IN THE LIBRARY **
** -------------------------------- **
** Get a compilation error pointing here? **
** It doesn't mean the error *is* here. **
** Often, it's because you try to assign the wrong value type. **
** **
** For example: **
** char age = 42 **
** doc["age"] = age; **
** Instead, use: **
** int8_t age = 42; **
** doc["age"] = age; **
********************************************************************/
getOrAddUpstreamMember().set(src); getOrAddUpstreamMember().set(src);
return *this; return *this;
} }
@@ -81,9 +67,17 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
return getUpstreamMember().isNull(); return getUpstreamMember().isNull();
} }
template <typename TValue> template <typename T>
FORCE_INLINE typename VariantAs<TValue>::type as() const { FORCE_INLINE typename enable_if<!is_same<T, char *>::value, T>::type as()
return getUpstreamMember().template as<TValue>(); const {
return getUpstreamMember().template as<T>();
}
template <typename T>
FORCE_INLINE typename enable_if<is_same<T, char *>::value, const char *>::type
ARDUINOJSON_DEPRECATED("Replace as<char*>() with as<const char*>()")
as() const {
return as<const char *>();
} }
template <typename T> template <typename T>
@@ -193,6 +187,10 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
return _object.getOrAddMember(_key); return _object.getOrAddMember(_key);
} }
friend bool convertToJson(const this_type &src, VariantRef dst) {
return dst.set(src.getUpstreamMember());
}
TObject _object; TObject _object;
TStringRef _key; TStringRef _key;
}; };

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -236,4 +236,42 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
private: private:
MemoryPool* _pool; MemoryPool* _pool;
}; };
template <>
struct Converter<ObjectConstRef> {
static bool toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
}
static ObjectConstRef fromJson(VariantConstRef src) {
return ObjectConstRef(variantAsObject(getData(src)));
}
static bool checkJson(VariantConstRef src) {
const VariantData* data = getData(src);
return data && data->isObject();
}
};
template <>
struct Converter<ObjectRef> {
static bool toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst));
}
static ObjectRef fromJson(VariantRef src) {
VariantData* data = getData(src);
MemoryPool* pool = getPool(src);
return ObjectRef(pool, data != 0 ? data->asObject() : 0);
}
static bool checkJson(VariantConstRef) {
return false;
}
static bool checkJson(VariantRef src) {
VariantData* data = getData(src);
return data && data->isObject();
}
};
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License
@@ -8,23 +8,32 @@
#define FORCE_INLINE // __forceinline causes C4714 when returning std::string #define FORCE_INLINE // __forceinline causes C4714 when returning std::string
#define NO_INLINE __declspec(noinline) #define NO_INLINE __declspec(noinline)
#define DEPRECATED(msg) __declspec(deprecated(msg))
#ifndef ARDUINOJSON_DEPRECATED
#define ARDUINOJSON_DEPRECATED(msg) __declspec(deprecated(msg))
#endif
#elif defined(__GNUC__) // GCC or Clang #elif defined(__GNUC__) // GCC or Clang
#define FORCE_INLINE __attribute__((always_inline)) #define FORCE_INLINE __attribute__((always_inline))
#define NO_INLINE __attribute__((noinline)) #define NO_INLINE __attribute__((noinline))
#ifndef ARDUINOJSON_DEPRECATED
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define DEPRECATED(msg) __attribute__((deprecated(msg))) #define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated(msg)))
#else #else
#define DEPRECATED(msg) __attribute__((deprecated)) #define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated))
#endif
#endif #endif
#else // Other compilers #else // Other compilers
#define FORCE_INLINE #define FORCE_INLINE
#define NO_INLINE #define NO_INLINE
#define DEPRECATED(msg)
#ifndef ARDUINOJSON_DEPRECATED
#define ARDUINOJSON_DEPRECATED(msg)
#endif
#endif #endif

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

View File

@@ -1,4 +1,4 @@
// ArduinoJson - arduinojson.org // ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021 // Copyright Benoit Blanchon 2014-2021
// MIT License // MIT License

Some files were not shown because too many files have changed in this diff Show More