diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md index 072f20974..b933294b5 100644 --- a/CHANGELOG_LATEST.md +++ b/CHANGELOG_LATEST.md @@ -28,4 +28,5 @@ - maintenance settings for time/date as extra setting - move api/mqtt formats to `settings`, add `enum format` - UI improvements for editing Dallas Sensor details -- Rest GET commands can also require authentication (via bearer access token) for better security +- RESTful GET commands can also require authentication (via bearer access token) for better security +- Updated AsyncMqttClient to 0.9.0 and ArduinoJson to 6.18.3 diff --git a/lib/ArduinoJson/CHANGELOG.md b/lib/ArduinoJson/CHANGELOG.md index f3866b3c8..a1bbc5d24 100644 --- a/lib/ArduinoJson/CHANGELOG.md +++ b/lib/ArduinoJson/CHANGELOG.md @@ -1,6 +1,31 @@ ArduinoJson: change log ======================= +v6.18.3 (2021-07-27) +------- + +* Changed return type of `convertToJson()` and `Converter::toJson()` to `void` +* Added `as()` and `is()` + +v6.18.2 (2021-07-19) +------- + +* Removed a symlink because the Arduino Library Specification forbids it + +v6.18.1 (2021-07-03) +------- + +* Fixed support for `volatile float` and `volatile double` (issue #1557) +* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560) +* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572) +* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas) +* Added fake class `InvalidConversion` to easily identify invalid conversions (issue #1585) +* Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64) +* Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator` +* Added `JsonArray::clear()` (issue #1597) +* Fixed `JsonVariant::as()` (issue #1601) +* Added support for ESP-IDF component build (PR #1562 by @qt1, PR #1599 by @andreaskuster) + v6.18.0 (2021-05-05) ------- diff --git a/lib/ArduinoJson/README.md b/lib/ArduinoJson/README.md index c30028435..a9dfbc7f5 100644 --- a/lib/ArduinoJson/README.md +++ b/lib/ArduinoJson/README.md @@ -2,7 +2,7 @@ --- -[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.18.0)](https://www.ardu-badge.com/ArduinoJson/6.18.0) +[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.18.3)](https://www.ardu-badge.com/ArduinoJson/6.18.3) [![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) [![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) @@ -33,15 +33,15 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme) * Deduplicates strings * 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 [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`](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 [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 [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/?utm_source=github&utm_medium=readme), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme) and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/?utm_source=github&utm_medium=readme) + * Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/?utm_source=github&utm_medium=readme) and [`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 [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 + * Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/?utm_source=github&utm_medium=readme) * Portable * Usable on any C++ project (not limited to Arduino) - * Compatible with C++98 + * Compatible with C++98, C++11, C++14 and C++17 * Zero warnings with `-Wall -Wextra -pedantic` and `/W4` * [Header-only library](https://en.wikipedia.org/wiki/Header-only) * Works with virtually any board @@ -81,15 +81,17 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) + * Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/) * Well documented * [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) * [Examples](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) + * [Troubleshooter](https://arduinojson.org/v6/troubleshooter/?utm_source=github&utm_medium=readme) * [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme) * [Changelog](CHANGELOG.md) * 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) * [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson) * [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed) @@ -132,9 +134,11 @@ serializeJson(doc, Serial); See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme) -## Support the project +## Support the project ❤️ -Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)! +Do you like this library? +Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)! What? You don't like it but you *love* it? -We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time. +You can support the project by [purchasing my book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme). +Alternatively, you can make a recurring donation via [GitHub Sponsors](https://github.com/sponsors/bblanchon). diff --git a/lib/ArduinoJson/src/ArduinoJson.hpp b/lib/ArduinoJson/src/ArduinoJson.hpp index 28d42eef5..d16ca08cd 100644 --- a/lib/ArduinoJson/src/ArduinoJson.hpp +++ b/lib/ArduinoJson/src/ArduinoJson.hpp @@ -7,11 +7,11 @@ #include "ArduinoJson/Configuration.hpp" #if !ARDUINOJSON_DEBUG -#ifdef __clang__ -#pragma clang system_header -#elif defined __GNUC__ -#pragma GCC system_header -#endif +# ifdef __clang__ +# pragma clang system_header +# elif defined __GNUC__ +# pragma GCC system_header +# endif #endif #include "ArduinoJson/Array/ArrayRef.hpp" diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp index a991db0d7..4f8d0c631 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp @@ -161,14 +161,20 @@ class ArrayRef : public ArrayRefBase, _data->removeElement(index); } + void clear() const { + if (!_data) + return; + _data->clear(); + } + private: MemoryPool* _pool; }; template <> struct Converter { - 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) { @@ -183,8 +189,8 @@ struct Converter { template <> struct Converter { - 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) { @@ -193,6 +199,8 @@ struct Converter { return ArrayRef(pool, data != 0 ? data->asArray() : 0); } + static InvalidConversion fromJson(VariantConstRef); + static bool checkJson(VariantConstRef) { return false; } diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp index c6062e492..c1016eb01 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp @@ -10,8 +10,8 @@ #include #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) +# pragma warning(push) +# pragma warning(disable : 4522) #endif namespace ARDUINOJSON_NAMESPACE { @@ -178,8 +178,8 @@ class ElementProxy : public VariantOperators >, 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; @@ -189,5 +189,5 @@ class ElementProxy : public VariantOperators >, } // namespace ARDUINOJSON_NAMESPACE #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp index 49a24beed..f814bcdf2 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -62,9 +62,9 @@ inline bool CollectionData::copyFrom(const CollectionData& src, VariantData* var; if (s->key() != 0) { if (s->ownsKey()) - var = addMember(RamStringAdapter(s->key()), pool); + var = addMember(adaptString(const_cast(s->key())), pool); else - var = addMember(ConstRamStringAdapter(s->key()), pool); + var = addMember(adaptString(s->key()), pool); } else { var = addElement(pool); } @@ -107,7 +107,7 @@ template inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { VariantSlot* slot = _head; while (slot) { - if (key.equals(slot->key())) + if (key.compare(slot->key()) == 0) break; slot = slot->next(); } diff --git a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp index 0c0d4c489..332abb6a7 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp @@ -5,251 +5,269 @@ #pragma once #if __cplusplus >= 201103L -#define ARDUINOJSON_HAS_LONG_LONG 1 -#define ARDUINOJSON_HAS_NULLPTR 1 -#define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 +# define ARDUINOJSON_HAS_LONG_LONG 1 +# define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 #else -#define ARDUINOJSON_HAS_LONG_LONG 0 -#define ARDUINOJSON_HAS_NULLPTR 0 -#define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 +# define ARDUINOJSON_HAS_LONG_LONG 0 +# define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 +#endif + +#ifndef ARDUINOJSON_HAS_NULLPTR +# if __cplusplus >= 201103L +# define ARDUINOJSON_HAS_NULLPTR 1 +# else +# define ARDUINOJSON_HAS_NULLPTR 0 +# endif #endif #if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG -#define ARDUINOJSON_HAS_INT64 1 +# define ARDUINOJSON_HAS_INT64 1 #else -#define ARDUINOJSON_HAS_INT64 0 +# define ARDUINOJSON_HAS_INT64 0 #endif // Small or big machine? #ifndef ARDUINOJSON_EMBEDDED_MODE -#if defined(ARDUINO) /* Arduino*/ \ - || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ - || defined(__XC) /* MPLAB XC compiler */ \ - || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ - || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ -#define ARDUINOJSON_EMBEDDED_MODE 1 -#else -#define ARDUINOJSON_EMBEDDED_MODE 0 -#endif +# if defined(ARDUINO) /* Arduino*/ \ + || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ + || defined(__XC) /* MPLAB XC compiler */ \ + || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ + || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ +# define ARDUINOJSON_EMBEDDED_MODE 1 +# else +# define ARDUINOJSON_EMBEDDED_MODE 0 +# endif #endif // Auto enable std::stream if the right headers are here and no conflicting // macro is defined #if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) -#if __has_include() && \ +# if __has_include() && \ __has_include() && \ !defined(min) && \ !defined(max) -#define ARDUINOJSON_ENABLE_STD_STREAM 1 -#else -#define ARDUINOJSON_ENABLE_STD_STREAM 0 -#endif +# define ARDUINOJSON_ENABLE_STD_STREAM 1 +# else +# define ARDUINOJSON_ENABLE_STD_STREAM 0 +# endif #endif // Auto enable std::string if the right header is here and no conflicting // macro is defined #if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) -#if __has_include() && !defined(min) && !defined(max) -#define ARDUINOJSON_ENABLE_STD_STRING 1 -#else -#define ARDUINOJSON_ENABLE_STD_STRING 0 +# if __has_include() && !defined(min) && !defined(max) +# define ARDUINOJSON_ENABLE_STD_STRING 1 +# else +# define ARDUINOJSON_ENABLE_STD_STRING 0 +# endif #endif + +#ifndef ARDUINOJSON_ENABLE_STRING_VIEW +# ifdef __has_include +# if __has_include() && __cplusplus >= 201703L +# define ARDUINOJSON_ENABLE_STRING_VIEW 1 +# endif +# endif +#endif +#ifndef ARDUINOJSON_ENABLE_STRING_VIEW +# define ARDUINOJSON_ENABLE_STRING_VIEW 0 #endif #if ARDUINOJSON_EMBEDDED_MODE // Store floats by default to reduce the memory usage (issue #134) -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 0 -#endif +# ifndef ARDUINOJSON_USE_DOUBLE +# define ARDUINOJSON_USE_DOUBLE 0 +# endif // Store longs by default, because they usually match the size of a float. -#ifndef ARDUINOJSON_USE_LONG_LONG -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif +# ifndef ARDUINOJSON_USE_LONG_LONG +# define ARDUINOJSON_USE_LONG_LONG 0 +# endif // Embedded systems usually don't have std::string -#ifndef ARDUINOJSON_ENABLE_STD_STRING -#define ARDUINOJSON_ENABLE_STD_STRING 0 -#endif +# ifndef ARDUINOJSON_ENABLE_STD_STRING +# define ARDUINOJSON_ENABLE_STD_STRING 0 +# endif // Embedded systems usually don't have std::stream -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 0 -#endif +# ifndef ARDUINOJSON_ENABLE_STD_STREAM +# define ARDUINOJSON_ENABLE_STD_STREAM 0 +# endif // Limit nesting as the stack is likely to be small -#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT -#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 -#endif +# ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 +# endif // Number of bits to store the pointer to next node // (saves RAM but limits the number of values in a document) -#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE -#if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2 +# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE +# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2 // Address space == 16-bit => max 127 values -#define ARDUINOJSON_SLOT_OFFSET_SIZE 1 -#else +# define ARDUINOJSON_SLOT_OFFSET_SIZE 1 +# else // Address space > 16-bit => max 32767 values -#define ARDUINOJSON_SLOT_OFFSET_SIZE 2 -#endif -#endif +# define ARDUINOJSON_SLOT_OFFSET_SIZE 2 +# endif +# endif #else // ARDUINOJSON_EMBEDDED_MODE // On a computer we have plenty of memory so we can use doubles -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 1 -#endif +# ifndef ARDUINOJSON_USE_DOUBLE +# define ARDUINOJSON_USE_DOUBLE 1 +# endif // Use long long when available -#ifndef ARDUINOJSON_USE_LONG_LONG -#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 -#define ARDUINOJSON_USE_LONG_LONG 1 -#else -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif -#endif +# ifndef ARDUINOJSON_USE_LONG_LONG +# if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 +# define ARDUINOJSON_USE_LONG_LONG 1 +# else +# define ARDUINOJSON_USE_LONG_LONG 0 +# endif +# endif // On a computer, we can use std::string -#ifndef ARDUINOJSON_ENABLE_STD_STRING -#define ARDUINOJSON_ENABLE_STD_STRING 1 -#endif +# ifndef ARDUINOJSON_ENABLE_STD_STRING +# define ARDUINOJSON_ENABLE_STD_STRING 1 +# endif // On a computer, we can assume std::stream -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 1 -#endif +# ifndef ARDUINOJSON_ENABLE_STD_STREAM +# define ARDUINOJSON_ENABLE_STD_STREAM 1 +# endif // On a computer, the stack is large so we can increase nesting limit -#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT -#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 -#endif +# ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +# define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 +# endif // Number of bits to store the pointer to next node -#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE -#define ARDUINOJSON_SLOT_OFFSET_SIZE 4 -#endif +# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE +# define ARDUINOJSON_SLOT_OFFSET_SIZE 4 +# endif #endif // ARDUINOJSON_EMBEDDED_MODE #ifdef ARDUINO -#include +# include // Enable support for Arduino's String class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 -#endif +# ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +# define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +# endif // Enable support for Arduino's Stream class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM -#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 -#endif +# ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM +# define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 +# endif // Enable support for Arduino's Print class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT -#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1 -#endif +# ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT +# define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1 +# endif #else // ARDUINO // Disable support for Arduino's String class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 -#endif +# ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +# define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 +# endif // Disable support for Arduino's Stream class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM -#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 -#endif +# ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM +# define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 +# endif // Disable support for Arduino's Print class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT -#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 -#endif +# ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT +# define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 +# endif #endif // ARDUINO #ifndef ARDUINOJSON_ENABLE_PROGMEM -#if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \ - defined(pgm_read_ptr) && defined(pgm_read_float) -#define ARDUINOJSON_ENABLE_PROGMEM 1 -#else -#define ARDUINOJSON_ENABLE_PROGMEM 0 -#endif +# if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \ + defined(pgm_read_ptr) && defined(pgm_read_float) +# define ARDUINOJSON_ENABLE_PROGMEM 1 +# else +# define ARDUINOJSON_ENABLE_PROGMEM 0 +# endif #endif // Convert unicode escape sequence (\u0123) to UTF-8 #ifndef ARDUINOJSON_DECODE_UNICODE -#define ARDUINOJSON_DECODE_UNICODE 1 +# define ARDUINOJSON_DECODE_UNICODE 1 #endif // Ignore comments in input #ifndef ARDUINOJSON_ENABLE_COMMENTS -#define ARDUINOJSON_ENABLE_COMMENTS 0 +# define ARDUINOJSON_ENABLE_COMMENTS 0 #endif // Support NaN in JSON #ifndef ARDUINOJSON_ENABLE_NAN -#define ARDUINOJSON_ENABLE_NAN 0 +# define ARDUINOJSON_ENABLE_NAN 0 #endif // Support Infinity in JSON #ifndef ARDUINOJSON_ENABLE_INFINITY -#define ARDUINOJSON_ENABLE_INFINITY 0 +# define ARDUINOJSON_ENABLE_INFINITY 0 #endif // Control the exponentiation threshold for big numbers // CAUTION: cannot be more that 1e9 !!!! #ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD -#define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 +# define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 #endif // Control the exponentiation threshold for small numbers #ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD -#define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 +# define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 #endif #ifndef ARDUINOJSON_LITTLE_ENDIAN -#if defined(_MSC_VER) || \ - (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ - defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64) -#define ARDUINOJSON_LITTLE_ENDIAN 1 -#else -#define ARDUINOJSON_LITTLE_ENDIAN 0 -#endif +# if defined(_MSC_VER) || \ + (defined(__BYTE_ORDER__) && \ + __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ + defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64) +# define ARDUINOJSON_LITTLE_ENDIAN 1 +# else +# define ARDUINOJSON_LITTLE_ENDIAN 0 +# endif #endif #ifndef ARDUINOJSON_ENABLE_ALIGNMENT -#if defined(__AVR) -#define ARDUINOJSON_ENABLE_ALIGNMENT 0 -#else -#define ARDUINOJSON_ENABLE_ALIGNMENT 1 -#endif +# if defined(__AVR) +# define ARDUINOJSON_ENABLE_ALIGNMENT 0 +# else +# define ARDUINOJSON_ENABLE_ALIGNMENT 1 +# endif #endif #ifndef ARDUINOJSON_TAB -#define ARDUINOJSON_TAB " " +# define ARDUINOJSON_TAB " " #endif #ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION -#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 +# define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 #endif #ifndef ARDUINOJSON_STRING_BUFFER_SIZE -#define ARDUINOJSON_STRING_BUFFER_SIZE 32 +# define ARDUINOJSON_STRING_BUFFER_SIZE 32 #endif #ifndef ARDUINOJSON_DEBUG -#ifdef __PLATFORMIO_BUILD_DEBUG__ -#define ARDUINOJSON_DEBUG 1 -#else -#define ARDUINOJSON_DEBUG 0 -#endif +# ifdef __PLATFORMIO_BUILD_DEBUG__ +# define ARDUINOJSON_DEBUG 1 +# else +# define ARDUINOJSON_DEBUG 0 +# endif #endif #if ARDUINOJSON_HAS_NULLPTR && defined(nullptr) -#error nullptr is defined as a macro. Remove the faulty #define or #undef nullptr +# error nullptr is defined as a macro. Remove the faulty #define or #undef nullptr // See https://github.com/bblanchon/ArduinoJson/issues/1355 #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp index 7b617111a..11ec7df66 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -9,7 +9,7 @@ #include #if ARDUINOJSON_ENABLE_STD_STREAM -#include +# include #endif namespace ARDUINOJSON_NAMESPACE { diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp index e965c8256..9ae2d5987 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp @@ -40,17 +40,17 @@ struct BoundedReader { #include #if ARDUINOJSON_ENABLE_ARDUINO_STREAM -#include +# include #endif #if ARDUINOJSON_ENABLE_ARDUINO_STRING -#include +# include #endif #if ARDUINOJSON_ENABLE_PROGMEM -#include +# include #endif #if ARDUINOJSON_ENABLE_STD_STREAM -#include +# include #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp b/lib/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp index d67d93496..d81853c3a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp @@ -32,7 +32,7 @@ class JsonDocument : public Visitable { void clear() { _pool.clear(); - _data.setNull(); + _data.init(); } template @@ -304,15 +304,15 @@ class JsonDocument : public Visitable { protected: JsonDocument() : _pool(0, 0) { - _data.setNull(); + _data.init(); } JsonDocument(MemoryPool pool) : _pool(pool) { - _data.setNull(); + _data.init(); } JsonDocument(char* buf, size_t capa) : _pool(buf, capa) { - _data.setNull(); + _data.init(); } ~JsonDocument() {} @@ -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()); +inline void convertToJson(const JsonDocument& src, VariantRef dst) { + dst.set(src.as()); } } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Json/Latch.hpp b/lib/ArduinoJson/src/ArduinoJson/Json/Latch.hpp index aef1fe368..70866d6b7 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Json/Latch.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Json/Latch.hpp @@ -45,7 +45,8 @@ class Latch { } TReader _reader; - char _current; + char _current; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject) + // Not initialized in constructor (+10 bytes on AVR) bool _loaded; #if ARDUINOJSON_DEBUG bool _ended; diff --git a/lib/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp b/lib/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp index 18694f14e..7795671ff 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp @@ -155,7 +155,6 @@ class TextFormatter { protected: CountingDecorator _writer; - size_t _length; private: TextFormatter &operator=(const TextFormatter &); // cannot be assigned diff --git a/lib/ArduinoJson/src/ArduinoJson/Json/Utf16.hpp b/lib/ArduinoJson/src/ArduinoJson/Json/Utf16.hpp index 4e2750f3b..e2b901056 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Json/Utf16.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Json/Utf16.hpp @@ -12,10 +12,10 @@ // we choose to ignore the problem to reduce the size of the code // Garbage in => Garbage out #if defined(__GNUC__) -#if __GNUC__ >= 7 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif +# if __GNUC__ >= 7 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +# endif #endif namespace ARDUINOJSON_NAMESPACE { @@ -31,7 +31,7 @@ inline bool isLowSurrogate(uint16_t codeunit) { class Codepoint { public: - Codepoint() : _highSurrogate(0) {} + Codepoint() : _highSurrogate(0), _codepoint(0) {} bool append(uint16_t codeunit) { if (isHighSurrogate(codeunit)) { @@ -61,7 +61,7 @@ class Codepoint { } // namespace ARDUINOJSON_NAMESPACE #if defined(__GNUC__) -#if __GNUC__ >= 8 -#pragma GCC diagnostic pop -#endif +# if __GNUC__ >= 8 +# pragma GCC diagnostic pop +# endif #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Memory/MemoryPool.hpp b/lib/ArduinoJson/src/ArduinoJson/Memory/MemoryPool.hpp index 49debf856..04e5b2d28 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Memory/MemoryPool.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Memory/MemoryPool.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include // memmove @@ -37,7 +38,8 @@ class MemoryPool { } void* buffer() { - return _begin; + return _begin; // NOLINT(clang-analyzer-unix.Malloc) + // movePointers() alters this pointer } // Gets the capacity of the memoryPool in bytes @@ -63,7 +65,7 @@ class MemoryPool { return 0; #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION - const char* existingCopy = findString(str.begin()); + const char* existingCopy = findString(str); if (existingCopy) return existingCopy; #endif @@ -85,7 +87,7 @@ class MemoryPool { const char* saveStringFromFreeZone(size_t len) { #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION - const char* dup = findString(_left); + const char* dup = findString(adaptString(_left)); if (dup) return dup; #endif @@ -162,16 +164,11 @@ class MemoryPool { } #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION - template - const char* findString(TIterator str) { + template + const char* findString(const TAdaptedString& str) { for (char* next = _begin; next < _left; ++next) { - char* begin = next; - - // try to match - for (TIterator it = str; *it == *next; ++it) { - if (*next++ == 0) - return begin; - } + if (str.compare(next) == 0) + return next; // jump to next terminator while (*next) ++next; diff --git a/lib/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp b/lib/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp index 8988173e3..fbeb05df2 100644 --- a/lib/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp @@ -15,468 +15,475 @@ namespace ARDUINOJSON_NAMESPACE { template class MsgPackDeserializer { - public: - MsgPackDeserializer(MemoryPool & pool, TReader reader, TStringStorage stringStorage) - : _pool(&pool) - , _reader(reader) - , _stringStorage(stringStorage) - , _error(DeserializationError::Ok) - , _foundSomething(false) { - } + public: + MsgPackDeserializer(MemoryPool &pool, TReader reader, + TStringStorage stringStorage) + : _pool(&pool), + _reader(reader), + _stringStorage(stringStorage), + _error(DeserializationError::Ok), + _foundSomething(false) {} - template - DeserializationError parse(VariantData & variant, TFilter filter, NestingLimit nestingLimit) { - parseVariant(&variant, filter, nestingLimit); - return _foundSomething ? _error : DeserializationError::EmptyInput; - } + template + DeserializationError parse(VariantData &variant, TFilter filter, + NestingLimit nestingLimit) { + parseVariant(&variant, filter, nestingLimit); + return _foundSomething ? _error : DeserializationError::EmptyInput; + } - private: - // Prevent VS warning "assignment operator could not be generated" - MsgPackDeserializer & operator=(const MsgPackDeserializer &); + private: + bool invalidInput() { + _error = DeserializationError::InvalidInput; + return false; + } - bool invalidInput() { - _error = DeserializationError::InvalidInput; - return false; - } + template + bool parseVariant(VariantData *variant, TFilter filter, + NestingLimit nestingLimit) { + uint8_t code = 0; // TODO: why do we need to initialize this variable? + if (!readByte(code)) + return false; - template - bool parseVariant(VariantData * variant, TFilter filter, NestingLimit nestingLimit) { - uint8_t code = 0; - if (!readByte(code)) - return false; + _foundSomething = true; - _foundSomething = true; + bool allowValue = filter.allowValue(); - bool allowValue = filter.allowValue(); + switch (code) { + case 0xc0: + // already null + return true; - switch (code) { - case 0xc0: - // already null - return true; - - case 0xc1: - return invalidInput(); - - case 0xc2: - if (allowValue) - variant->setBoolean(false); - return true; - - case 0xc3: - if (allowValue) - variant->setBoolean(true); - return true; - - case 0xc4: // bin 8 (not supported) - return skipString(); - - case 0xc5: // bin 16 (not supported) - return skipString(); - - case 0xc6: // bin 32 (not supported) - return skipString(); - - case 0xc7: // ext 8 (not supported) - return skipExt(); - - case 0xc8: // ext 16 (not supported) - return skipExt(); - - case 0xc9: // ext 32 (not supported) - return skipExt(); - - case 0xca: - if (allowValue) - return readFloat(variant); - else - return skipBytes(4); - - case 0xcb: - if (allowValue) - return readDouble(variant); - else - return skipBytes(8); - - case 0xcc: - if (allowValue) - return readInteger(variant); - else - return skipBytes(1); - - case 0xcd: - if (allowValue) - return readInteger(variant); - else - return skipBytes(2); - - case 0xce: - if (allowValue) - return readInteger(variant); - else - return skipBytes(4); - - case 0xcf: -#if ARDUINOJSON_USE_LONG_LONG - if (allowValue) - return readInteger(variant); - else - return skipBytes(8); -#else - return skipBytes(8); // not supported -#endif - - case 0xd0: - if (allowValue) - return readInteger(variant); - else - return skipBytes(1); - - case 0xd1: - if (allowValue) - return readInteger(variant); - else - return skipBytes(2); - - case 0xd2: - if (allowValue) - return readInteger(variant); - else - return skipBytes(4); - - case 0xd3: -#if ARDUINOJSON_USE_LONG_LONG - if (allowValue) - return readInteger(variant); - else - return skipBytes(8); // not supported -#else - return skipBytes(8); -#endif - - case 0xd4: // fixext 1 (not supported) - return skipBytes(2); - - case 0xd5: // fixext 2 (not supported) - return skipBytes(3); - - case 0xd6: // fixext 4 (not supported) - return skipBytes(5); - - case 0xd7: // fixext 8 (not supported) - return skipBytes(9); - - case 0xd8: // fixext 16 (not supported) - return skipBytes(17); - - case 0xd9: - if (allowValue) - return readString(variant); - else - return skipString(); - - case 0xda: - if (allowValue) - return readString(variant); - else - return skipString(); - - case 0xdb: - if (allowValue) - return readString(variant); - else - return skipString(); - - case 0xdc: - return readArray(variant, filter, nestingLimit); - - case 0xdd: - return readArray(variant, filter, nestingLimit); - - case 0xde: - return readObject(variant, filter, nestingLimit); - - case 0xdf: - return readObject(variant, filter, nestingLimit); - } - - switch (code & 0xf0) { - case 0x80: - return readObject(variant, code & 0x0F, filter, nestingLimit); - - case 0x90: - return readArray(variant, code & 0x0F, filter, nestingLimit); - } - - if ((code & 0xe0) == 0xa0) { - if (allowValue) - return readString(variant, code & 0x1f); - else - return skipBytes(code & 0x1f); - } + case 0xc1: + return invalidInput(); + case 0xc2: if (allowValue) - variant->setInteger(static_cast(code)); - + variant->setBoolean(false); return true; + + case 0xc3: + if (allowValue) + variant->setBoolean(true); + return true; + + case 0xc4: // bin 8 (not supported) + return skipString(); + + case 0xc5: // bin 16 (not supported) + return skipString(); + + case 0xc6: // bin 32 (not supported) + return skipString(); + + case 0xc7: // ext 8 (not supported) + return skipExt(); + + case 0xc8: // ext 16 (not supported) + return skipExt(); + + case 0xc9: // ext 32 (not supported) + return skipExt(); + + case 0xca: + if (allowValue) + return readFloat(variant); + else + return skipBytes(4); + + case 0xcb: + if (allowValue) + return readDouble(variant); + else + return skipBytes(8); + + case 0xcc: + if (allowValue) + return readInteger(variant); + else + return skipBytes(1); + + case 0xcd: + if (allowValue) + return readInteger(variant); + else + return skipBytes(2); + + case 0xce: + if (allowValue) + return readInteger(variant); + else + return skipBytes(4); + + case 0xcf: +#if ARDUINOJSON_USE_LONG_LONG + if (allowValue) + return readInteger(variant); + else + return skipBytes(8); +#else + return skipBytes(8); // not supported +#endif + + case 0xd0: + if (allowValue) + return readInteger(variant); + else + return skipBytes(1); + + case 0xd1: + if (allowValue) + return readInteger(variant); + else + return skipBytes(2); + + case 0xd2: + if (allowValue) + return readInteger(variant); + else + return skipBytes(4); + + case 0xd3: +#if ARDUINOJSON_USE_LONG_LONG + if (allowValue) + return readInteger(variant); + else + return skipBytes(8); // not supported +#else + return skipBytes(8); +#endif + + case 0xd4: // fixext 1 (not supported) + return skipBytes(2); + + case 0xd5: // fixext 2 (not supported) + return skipBytes(3); + + case 0xd6: // fixext 4 (not supported) + return skipBytes(5); + + case 0xd7: // fixext 8 (not supported) + return skipBytes(9); + + case 0xd8: // fixext 16 (not supported) + return skipBytes(17); + + case 0xd9: + if (allowValue) + return readString(variant); + else + return skipString(); + + case 0xda: + if (allowValue) + return readString(variant); + else + return skipString(); + + case 0xdb: + if (allowValue) + return readString(variant); + else + return skipString(); + + case 0xdc: + return readArray(variant, filter, nestingLimit); + + case 0xdd: + return readArray(variant, filter, nestingLimit); + + case 0xde: + return readObject(variant, filter, nestingLimit); + + case 0xdf: + return readObject(variant, filter, nestingLimit); } - bool readByte(uint8_t & value) { - int c = _reader.read(); - if (c < 0) { - _error = DeserializationError::IncompleteInput; - return false; - } - value = static_cast(c); - return true; + switch (code & 0xf0) { + case 0x80: + return readObject(variant, code & 0x0F, filter, nestingLimit); + + case 0x90: + return readArray(variant, code & 0x0F, filter, nestingLimit); } - bool readBytes(uint8_t * p, size_t n) { - if (_reader.readBytes(reinterpret_cast(p), n) == n) - return true; + if ((code & 0xe0) == 0xa0) { + if (allowValue) + return readString(variant, code & 0x1f); + else + return skipBytes(code & 0x1f); + } + + if (allowValue) + variant->setInteger(static_cast(code)); + + return true; + } + + bool readByte(uint8_t &value) { + int c = _reader.read(); + if (c < 0) { + _error = DeserializationError::IncompleteInput; + return false; + } + value = static_cast(c); + return true; + } + + bool readBytes(uint8_t *p, size_t n) { + if (_reader.readBytes(reinterpret_cast(p), n) == n) + return true; + _error = DeserializationError::IncompleteInput; + return false; + } + + template + bool readBytes(T &value) { + return readBytes(reinterpret_cast(&value), sizeof(value)); + } + + bool skipBytes(size_t n) { + for (; n; --n) { + if (_reader.read() < 0) { _error = DeserializationError::IncompleteInput; return false; + } + } + return true; + } + + template + bool readInteger(T &value) { + if (!readBytes(value)) + return false; + fixEndianess(value); + return true; + } + + template + bool readInteger(VariantData *variant) { + T value; + if (!readInteger(value)) + return false; + variant->setInteger(value); + return true; + } + + template + typename enable_if::type readFloat( + VariantData *variant) { + T value; + if (!readBytes(value)) + return false; + fixEndianess(value); + variant->setFloat(value); + return true; + } + + template + typename enable_if::type readDouble( + VariantData *variant) { + T value; + if (!readBytes(value)) + return false; + fixEndianess(value); + variant->setFloat(value); + return true; + } + + template + typename enable_if::type readDouble( + VariantData *variant) { + uint8_t i[8]; // input is 8 bytes + T value; // output is 4 bytes + uint8_t *o = reinterpret_cast(&value); + if (!readBytes(i, 8)) + return false; + doubleToFloat(i, o); + fixEndianess(value); + variant->setFloat(value); + return true; + } + + template + bool readString(VariantData *variant) { + T size; + if (!readInteger(size)) + return false; + return readString(variant, size); + } + + template + bool readString() { + T size; + if (!readInteger(size)) + return false; + return readString(size); + } + + template + bool skipString() { + T size; + if (!readInteger(size)) + return false; + return skipBytes(size); + } + + bool readString(VariantData *variant, size_t n) { + if (!readString(n)) + return false; + variant->setStringPointer(_stringStorage.save(), + typename TStringStorage::storage_policy()); + return true; + } + + bool readString(size_t n) { + _stringStorage.startString(); + for (; n; --n) { + uint8_t c; + if (!readBytes(c)) + return false; + _stringStorage.append(static_cast(c)); + } + _stringStorage.append('\0'); + if (!_stringStorage.isValid()) { + _error = DeserializationError::NoMemory; + return false; } - template - bool readBytes(T & value) { - return readBytes(reinterpret_cast(&value), sizeof(value)); + return true; + } + + template + bool readArray(VariantData *variant, TFilter filter, + NestingLimit nestingLimit) { + TSize size; + if (!readInteger(size)) + return false; + return readArray(variant, size, filter, nestingLimit); + } + + template + bool readArray(VariantData *variant, size_t n, TFilter filter, + NestingLimit nestingLimit) { + if (nestingLimit.reached()) { + _error = DeserializationError::TooDeep; + return false; } - bool skipBytes(size_t n) { - for (; n; --n) { - if (_reader.read() < 0) { - _error = DeserializationError::IncompleteInput; - return false; - } + bool allowArray = filter.allowArray(); + + CollectionData *array = allowArray ? &variant->toArray() : 0; + + TFilter memberFilter = filter[0U]; + + for (; n; --n) { + VariantData *value; + + if (memberFilter.allow()) { + value = array->addElement(_pool); + if (!value) { + _error = DeserializationError::NoMemory; + return false; } - return true; + } else { + value = 0; + } + + if (!parseVariant(value, memberFilter, nestingLimit.decrement())) + return false; } - template - bool readInteger(T & value) { - if (!readBytes(value)) - return false; - fixEndianess(value); - return true; + return true; + } + + template + bool readObject(VariantData *variant, TFilter filter, + NestingLimit nestingLimit) { + TSize size; + if (!readInteger(size)) + return false; + return readObject(variant, size, filter, nestingLimit); + } + + template + bool readObject(VariantData *variant, size_t n, TFilter filter, + NestingLimit nestingLimit) { + if (nestingLimit.reached()) { + _error = DeserializationError::TooDeep; + return false; } - template - bool readInteger(VariantData * variant) { - T value; - if (!readInteger(value)) - return false; - variant->setInteger(value); - return true; - } + CollectionData *object = filter.allowObject() ? &variant->toObject() : 0; - template - typename enable_if::type readFloat(VariantData * variant) { - T value; - if (!readBytes(value)) - return false; - fixEndianess(value); - variant->setFloat(value); - return true; - } + for (; n; --n) { + if (!readKey()) + return false; - template - typename enable_if::type readDouble(VariantData * variant) { - T value; - if (!readBytes(value)) - return false; - fixEndianess(value); - variant->setFloat(value); - return true; - } + const char *key = _stringStorage.c_str(); + TFilter memberFilter = filter[key]; + VariantData *member; - template - typename enable_if::type readDouble(VariantData * variant) { - uint8_t i[8]; // input is 8 bytes - T value; // output is 4 bytes - uint8_t * o = reinterpret_cast(&value); - if (!readBytes(i, 8)) - return false; - doubleToFloat(i, o); - fixEndianess(value); - variant->setFloat(value); - return true; - } + if (memberFilter.allow()) { + // Save key in memory pool. + // This MUST be done before adding the slot. + key = _stringStorage.save(); - template - bool readString(VariantData * variant) { - T size; - if (!readInteger(size)) - return false; - return readString(variant, size); - } - - template - bool readString() { - T size; - if (!readInteger(size)) - return false; - return readString(size); - } - - template - bool skipString() { - T size; - if (!readInteger(size)) - return false; - return skipBytes(size); - } - - bool readString(VariantData * variant, size_t n) { - if (!readString(n)) - return false; - variant->setStringPointer(_stringStorage.save(), typename TStringStorage::storage_policy()); - return true; - } - - bool readString(size_t n) { - _stringStorage.startString(); - for (; n; --n) { - uint8_t c; - if (!readBytes(c)) - return false; - _stringStorage.append(static_cast(c)); - } - _stringStorage.append('\0'); - if (!_stringStorage.isValid()) { - _error = DeserializationError::NoMemory; - return false; + VariantSlot *slot = object->addSlot(_pool); + if (!slot) { + _error = DeserializationError::NoMemory; + return false; } - return true; + slot->setKey(key, typename TStringStorage::storage_policy()); + + member = slot->data(); + } else { + member = 0; + } + + if (!parseVariant(member, memberFilter, nestingLimit.decrement())) + return false; } - template - bool readArray(VariantData * variant, TFilter filter, NestingLimit nestingLimit) { - TSize size; - if (!readInteger(size)) - return false; - return readArray(variant, size, filter, nestingLimit); + return true; + } + + bool readKey() { + uint8_t code; + if (!readByte(code)) + return false; + + if ((code & 0xe0) == 0xa0) + return readString(code & 0x1f); + + switch (code) { + case 0xd9: + return readString(); + + case 0xda: + return readString(); + + case 0xdb: + return readString(); + + default: + return invalidInput(); } + } - template - bool readArray(VariantData * variant, size_t n, TFilter filter, NestingLimit nestingLimit) { - if (nestingLimit.reached()) { - _error = DeserializationError::TooDeep; - return false; - } + template + bool skipExt() { + T size; + if (!readInteger(size)) + return false; + return skipBytes(size + 1); + } - bool allowArray = filter.allowArray(); - - CollectionData * array = allowArray ? &variant->toArray() : 0; - - TFilter memberFilter = filter[0U]; - - for (; n; --n) { - VariantData * value; - - if (memberFilter.allow()) { - value = array->addElement(_pool); - if (!value) { - _error = DeserializationError::NoMemory; - return false; - } - } else { - value = 0; - } - - if (!parseVariant(value, memberFilter, nestingLimit.decrement())) - return false; - } - - return true; - } - - template - bool readObject(VariantData * variant, TFilter filter, NestingLimit nestingLimit) { - TSize size; - if (!readInteger(size)) - return false; - return readObject(variant, size, filter, nestingLimit); - } - - template - bool readObject(VariantData * variant, size_t n, TFilter filter, NestingLimit nestingLimit) { - if (nestingLimit.reached()) { - _error = DeserializationError::TooDeep; - return false; - } - - CollectionData * object = filter.allowObject() ? &variant->toObject() : 0; - - for (; n; --n) { - if (!readKey()) - return false; - - const char * key = _stringStorage.c_str(); - TFilter memberFilter = filter[key]; - VariantData * member; - - if (memberFilter.allow()) { - // Save key in memory pool. - // This MUST be done before adding the slot. - key = _stringStorage.save(); - - VariantSlot * slot = object->addSlot(_pool); - if (!slot) { - _error = DeserializationError::NoMemory; - return false; - } - - slot->setKey(key, typename TStringStorage::storage_policy()); - - member = slot->data(); - } else { - member = 0; - } - - if (!parseVariant(member, memberFilter, nestingLimit.decrement())) - return false; - } - - return true; - } - - bool readKey() { - uint8_t code; - if (!readByte(code)) - return false; - - if ((code & 0xe0) == 0xa0) - return readString(code & 0x1f); - - switch (code) { - case 0xd9: - return readString(); - - case 0xda: - return readString(); - - case 0xdb: - return readString(); - - default: - return invalidInput(); - } - } - - template - bool skipExt() { - T size; - if (!readInteger(size)) - return false; - return skipBytes(size + 1); - } - - MemoryPool * _pool; - TReader _reader; - TStringStorage _stringStorage; - DeserializationError _error; - bool _foundSomething; + MemoryPool *_pool; + TReader _reader; + TStringStorage _stringStorage; + DeserializationError _error; + bool _foundSomething; }; // @@ -484,18 +491,25 @@ class MsgPackDeserializer { // // ... = NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & input, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, nestingLimit, AllowAllFilter()); +DeserializationError deserializeMsgPack( + JsonDocument &doc, const TString &input, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, nestingLimit, + AllowAllFilter()); } // ... = Filter, NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & input, Filter filter, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, nestingLimit, filter); +DeserializationError deserializeMsgPack( + JsonDocument &doc, const TString &input, Filter filter, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, nestingLimit, filter); } // ... = NestingLimit, Filter template -DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & input, NestingLimit nestingLimit, Filter filter) { - return deserialize(doc, input, nestingLimit, filter); +DeserializationError deserializeMsgPack(JsonDocument &doc, const TString &input, + NestingLimit nestingLimit, + Filter filter) { + return deserialize(doc, input, nestingLimit, filter); } // @@ -503,18 +517,25 @@ DeserializationError deserializeMsgPack(JsonDocument & doc, const TString & inpu // // ... = NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, nestingLimit, AllowAllFilter()); +DeserializationError deserializeMsgPack( + JsonDocument &doc, TStream &input, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, nestingLimit, + AllowAllFilter()); } // ... = Filter, NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, Filter filter, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, nestingLimit, filter); +DeserializationError deserializeMsgPack( + JsonDocument &doc, TStream &input, Filter filter, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, nestingLimit, filter); } // ... = NestingLimit, Filter template -DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, NestingLimit nestingLimit, Filter filter) { - return deserialize(doc, input, nestingLimit, filter); +DeserializationError deserializeMsgPack(JsonDocument &doc, TStream &input, + NestingLimit nestingLimit, + Filter filter) { + return deserialize(doc, input, nestingLimit, filter); } // @@ -522,18 +543,25 @@ DeserializationError deserializeMsgPack(JsonDocument & doc, TStream & input, Nes // // ... = NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, nestingLimit, AllowAllFilter()); +DeserializationError deserializeMsgPack( + JsonDocument &doc, TChar *input, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, nestingLimit, + AllowAllFilter()); } // ... = Filter, NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, Filter filter, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, nestingLimit, filter); +DeserializationError deserializeMsgPack( + JsonDocument &doc, TChar *input, Filter filter, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, nestingLimit, filter); } // ... = NestingLimit, Filter template -DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, NestingLimit nestingLimit, Filter filter) { - return deserialize(doc, input, nestingLimit, filter); +DeserializationError deserializeMsgPack(JsonDocument &doc, TChar *input, + NestingLimit nestingLimit, + Filter filter) { + return deserialize(doc, input, nestingLimit, filter); } // @@ -541,18 +569,28 @@ DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, Nesti // // ... = NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, size_t inputSize, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, inputSize, nestingLimit, AllowAllFilter()); +DeserializationError deserializeMsgPack( + JsonDocument &doc, TChar *input, size_t inputSize, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, inputSize, nestingLimit, + AllowAllFilter()); } // ... = Filter, NestingLimit template -DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, size_t inputSize, Filter filter, NestingLimit nestingLimit = NestingLimit()) { - return deserialize(doc, input, inputSize, nestingLimit, filter); +DeserializationError deserializeMsgPack( + JsonDocument &doc, TChar *input, size_t inputSize, Filter filter, + NestingLimit nestingLimit = NestingLimit()) { + return deserialize(doc, input, inputSize, nestingLimit, + filter); } // ... = NestingLimit, Filter template -DeserializationError deserializeMsgPack(JsonDocument & doc, TChar * input, size_t inputSize, NestingLimit nestingLimit, Filter filter) { - return deserialize(doc, input, inputSize, nestingLimit, filter); +DeserializationError deserializeMsgPack(JsonDocument &doc, TChar *input, + size_t inputSize, + NestingLimit nestingLimit, + Filter filter) { + return deserialize(doc, input, inputSize, nestingLimit, + filter); } -} // namespace ARDUINOJSON_NAMESPACE +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Namespace.hpp b/lib/ArduinoJson/src/ArduinoJson/Namespace.hpp index 2d85440aa..26def8ab0 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Namespace.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Namespace.hpp @@ -10,17 +10,17 @@ #ifndef ARDUINOJSON_NAMESPACE -#define ARDUINOJSON_NAMESPACE \ - ARDUINOJSON_CONCAT4( \ - ARDUINOJSON_CONCAT4(ArduinoJson, ARDUINOJSON_VERSION_MAJOR, \ - ARDUINOJSON_VERSION_MINOR, \ - ARDUINOJSON_VERSION_REVISION), \ - _, \ - ARDUINOJSON_HEX_DIGIT(ARDUINOJSON_ENABLE_PROGMEM, \ - ARDUINOJSON_USE_LONG_LONG, ARDUINOJSON_USE_DOUBLE, \ - ARDUINOJSON_ENABLE_STRING_DEDUPLICATION), \ - ARDUINOJSON_HEX_DIGIT( \ - ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \ - ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE)) +# define ARDUINOJSON_NAMESPACE \ + ARDUINOJSON_CONCAT4( \ + ARDUINOJSON_CONCAT4(ArduinoJson, ARDUINOJSON_VERSION_MAJOR, \ + ARDUINOJSON_VERSION_MINOR, \ + ARDUINOJSON_VERSION_REVISION), \ + _, \ + ARDUINOJSON_HEX_DIGIT( \ + ARDUINOJSON_ENABLE_PROGMEM, ARDUINOJSON_USE_LONG_LONG, \ + ARDUINOJSON_USE_DOUBLE, ARDUINOJSON_ENABLE_STRING_DEDUPLICATION), \ + ARDUINOJSON_HEX_DIGIT( \ + ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \ + ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE)) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Numbers/Integer.hpp b/lib/ArduinoJson/src/ArduinoJson/Numbers/Integer.hpp index fb656a7d9..e0ed519a1 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Numbers/Integer.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Numbers/Integer.hpp @@ -22,11 +22,11 @@ typedef unsigned long UInt; } // namespace ARDUINOJSON_NAMESPACE #if ARDUINOJSON_HAS_LONG_LONG && !ARDUINOJSON_USE_LONG_LONG -#define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) \ - static_assert(sizeof(T) <= sizeof(ARDUINOJSON_NAMESPACE::Integer), \ - "To use 64-bit integers with ArduinoJson, you must set " \ - "ARDUINOJSON_USE_LONG_LONG to 1. See " \ - "https://arduinojson.org/v6/api/config/use_long_long/"); +# define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) \ + static_assert(sizeof(T) <= sizeof(ARDUINOJSON_NAMESPACE::Integer), \ + "To use 64-bit integers with ArduinoJson, you must set " \ + "ARDUINOJSON_USE_LONG_LONG to 1. See " \ + "https://arduinojson.org/v6/api/config/use_long_long/"); #else -#define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) +# define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Numbers/convertNumber.hpp b/lib/ArduinoJson/src/ArduinoJson/Numbers/convertNumber.hpp index 02bbefa50..3087459f4 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Numbers/convertNumber.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Numbers/convertNumber.hpp @@ -5,13 +5,13 @@ #pragma once #if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wconversion" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wconversion" #elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wconversion" +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic push +# endif +# pragma GCC diagnostic ignored "-Wconversion" #endif #include @@ -71,9 +71,23 @@ canConvertNumber(TIn) { } // int32 -> uint32 +// int32 -> uint64 template typename enable_if::value && is_signed::value && - is_integral::value && is_unsigned::value, + is_integral::value && is_unsigned::value && + sizeof(TOut) >= sizeof(TIn), + bool>::type +canConvertNumber(TIn value) { + if (value < 0) + return false; + return TOut(value) <= numeric_limits::highest(); +} + +// int32 -> uint16 +template +typename enable_if::value && is_signed::value && + is_integral::value && is_unsigned::value && + sizeof(TOut) < sizeof(TIn), bool>::type canConvertNumber(TIn value) { if (value < 0) @@ -99,9 +113,9 @@ TOut convertNumber(TIn value) { } // namespace ARDUINOJSON_NAMESPACE #if defined(__clang__) -#pragma clang diagnostic pop +# pragma clang diagnostic pop #elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +# pragma GCC diagnostic pop +# endif #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Object/MemberProxy.hpp b/lib/ArduinoJson/src/ArduinoJson/Object/MemberProxy.hpp index 0bee84bf2..f1463a3dd 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Object/MemberProxy.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Object/MemberProxy.hpp @@ -12,8 +12,8 @@ #include #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) +# pragma warning(push) +# pragma warning(disable : 4522) #endif namespace ARDUINOJSON_NAMESPACE { @@ -187,8 +187,8 @@ class MemberProxy : public VariantOperators >, 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; @@ -198,5 +198,5 @@ class MemberProxy : public VariantOperators >, } // namespace ARDUINOJSON_NAMESPACE #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Object/ObjectRef.hpp b/lib/ArduinoJson/src/ArduinoJson/Object/ObjectRef.hpp index c945fb6ca..047d9b1b5 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Object/ObjectRef.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Object/ObjectRef.hpp @@ -239,8 +239,8 @@ class ObjectRef : public ObjectRefBase, template <> struct Converter { - 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 { template <> struct Converter { - 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) { @@ -265,6 +265,9 @@ struct Converter { return ObjectRef(pool, data != 0 ? data->asObject() : 0); } + static InvalidConversion fromJson( + VariantConstRef); + static bool checkJson(VariantConstRef) { return false; } diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/assert.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/assert.hpp index 1030ec60e..f5fa94673 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/assert.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/assert.hpp @@ -7,8 +7,8 @@ #include #if ARDUINOJSON_DEBUG -#include -#define ARDUINOJSON_ASSERT(X) assert(X) +# include +# define ARDUINOJSON_ASSERT(X) assert(X) #else -#define ARDUINOJSON_ASSERT(X) ((void)0) +# define ARDUINOJSON_ASSERT(X) ((void)0) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/attributes.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/attributes.hpp index f04c9acce..8ef33afef 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/attributes.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/attributes.hpp @@ -6,49 +6,49 @@ #ifdef _MSC_VER // Visual Studio -#define FORCE_INLINE // __forceinline causes C4714 when returning std::string -#define NO_INLINE __declspec(noinline) +# define FORCE_INLINE // __forceinline causes C4714 when returning std::string +# define NO_INLINE __declspec(noinline) -#ifndef ARDUINOJSON_DEPRECATED -#define ARDUINOJSON_DEPRECATED(msg) __declspec(deprecated(msg)) -#endif +# ifndef ARDUINOJSON_DEPRECATED +# define ARDUINOJSON_DEPRECATED(msg) __declspec(deprecated(msg)) +# endif #elif defined(__GNUC__) // GCC or Clang -#define FORCE_INLINE __attribute__((always_inline)) -#define NO_INLINE __attribute__((noinline)) +# define FORCE_INLINE __attribute__((always_inline)) +# define NO_INLINE __attribute__((noinline)) -#ifndef ARDUINOJSON_DEPRECATED -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated(msg))) -#else -#define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated)) -#endif -#endif +# ifndef ARDUINOJSON_DEPRECATED +# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +# define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated(msg))) +# else +# define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated)) +# endif +# endif #else // Other compilers -#define FORCE_INLINE -#define NO_INLINE +# define FORCE_INLINE +# define NO_INLINE -#ifndef ARDUINOJSON_DEPRECATED -#define ARDUINOJSON_DEPRECATED(msg) -#endif +# ifndef ARDUINOJSON_DEPRECATED +# define ARDUINOJSON_DEPRECATED(msg) +# endif #endif #if __cplusplus >= 201103L -#define NOEXCEPT noexcept +# define NOEXCEPT noexcept #else -#define NOEXCEPT throw() +# define NOEXCEPT throw() #endif #if defined(__has_attribute) -#if __has_attribute(no_sanitize) -#define ARDUINOJSON_NO_SANITIZE(check) __attribute__((no_sanitize(check))) +# if __has_attribute(no_sanitize) +# define ARDUINOJSON_NO_SANITIZE(check) __attribute__((no_sanitize(check))) +# else +# define ARDUINOJSON_NO_SANITIZE(check) +# endif #else -#define ARDUINOJSON_NO_SANITIZE(check) -#endif -#else -#define ARDUINOJSON_NO_SANITIZE(check) +# define ARDUINOJSON_NO_SANITIZE(check) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/limits.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/limits.hpp index 80048284b..68a2bf8a6 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/limits.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/limits.hpp @@ -7,8 +7,8 @@ #include "type_traits.hpp" #ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4310) +# pragma warning(push) +# pragma warning(disable : 4310) #endif namespace ARDUINOJSON_NAMESPACE { @@ -41,5 +41,5 @@ struct numeric_limits< } // namespace ARDUINOJSON_NAMESPACE #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/static_array.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/static_array.hpp index a877b4caa..b070628cc 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/static_array.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/static_array.hpp @@ -8,27 +8,27 @@ #if ARDUINOJSON_ENABLE_PROGMEM -#include +# include -#ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY -#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \ - static type const name[] PROGMEM = value; -#endif +# ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY +# define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \ + static type const name[] PROGMEM = value; +# endif -#ifndef ARDUINOJSON_READ_STATIC_ARRAY -#define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) \ - pgm_read(name + index) -#endif +# ifndef ARDUINOJSON_READ_STATIC_ARRAY +# define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) \ + pgm_read(name + index) +# endif #else // i.e. ARDUINOJSON_ENABLE_PROGMEM == 0 -#ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY -#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \ - static type const name[] = value; -#endif +# ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY +# define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \ + static type const name[] = value; +# endif -#ifndef ARDUINOJSON_READ_STATIC_ARRAY -#define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) name[index] -#endif +# ifndef ARDUINOJSON_READ_STATIC_ARRAY +# define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) name[index] +# endif #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits.hpp index 4a8ff4b94..24440b196 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits.hpp @@ -20,5 +20,6 @@ #include "type_traits/is_signed.hpp" #include "type_traits/is_unsigned.hpp" #include "type_traits/make_unsigned.hpp" +#include "type_traits/make_void.hpp" #include "type_traits/remove_const.hpp" #include "type_traits/remove_reference.hpp" diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_convertible.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_convertible.hpp index 847525a93..b3a073b83 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_convertible.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_convertible.hpp @@ -7,9 +7,9 @@ #include "declval.hpp" #ifdef _MSC_VER -#pragma warning(push) +# pragma warning(push) // conversion from 'T' to 'To', possible loss of data -#pragma warning(disable : 4244) +# pragma warning(disable : 4244) #endif // clang-format off @@ -37,7 +37,7 @@ struct is_convertible { } // namespace ARDUINOJSON_NAMESPACE #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif // clang-format off diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp index b7e9d3d24..fb42f0598 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_floating_point.hpp @@ -5,15 +5,16 @@ #pragma once #include "integral_constant.hpp" +#include "is_same.hpp" +#include "remove_cv.hpp" namespace ARDUINOJSON_NAMESPACE { -template -struct is_floating_point : false_type {}; +template +struct is_floating_point + : integral_constant< + bool, // + is_same::type>::value || + is_same::type>::value> {}; -template <> -struct is_floating_point : true_type {}; - -template <> -struct is_floating_point : true_type {}; } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp index 26e895c8a..65918cf9c 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_integral.hpp @@ -5,29 +5,33 @@ #pragma once #include + +#include "integral_constant.hpp" #include "is_same.hpp" +#include "remove_cv.hpp" namespace ARDUINOJSON_NAMESPACE { -// A meta-function that returns true if T is an integral type. +// clang-format off template -struct is_integral { - static const bool value = - is_same::value || is_same::value || - is_same::value || is_same::value || - is_same::value || is_same::value || - is_same::value || is_same::value || +struct is_integral : integral_constant::type, signed char>::value || + is_same::type, unsigned char>::value || + is_same::type, signed short>::value || + is_same::type, unsigned short>::value || + is_same::type, signed int>::value || + is_same::type, unsigned int>::value || + is_same::type, signed long>::value || + is_same::type, unsigned long>::value || #if ARDUINOJSON_HAS_LONG_LONG - is_same::value || - is_same::value || + is_same::type, signed long long>::value || + is_same::type, unsigned long long>::value || #endif #if ARDUINOJSON_HAS_INT64 - is_same::value || - is_same::value || + is_same::type, signed __int64>::value || + is_same::type, unsigned __int64>::value || #endif - is_same::value || is_same::value; -}; - -template -struct is_integral : is_integral {}; + is_same::type, char>::value || + is_same::type, bool>::value> {}; +// clang-format on } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp index fbb701cf7..3e064e315 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_signed.hpp @@ -5,39 +5,26 @@ #pragma once #include "integral_constant.hpp" +#include "is_same.hpp" +#include "remove_cv.hpp" + namespace ARDUINOJSON_NAMESPACE { -template -struct is_signed : false_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - -template <> -struct is_signed : true_type {}; - +// clang-format off +template +struct is_signed : integral_constant::type, char>::value || + is_same::type, signed char>::value || + is_same::type, signed short>::value || + is_same::type, signed int>::value || + is_same::type, signed long>::value || #if ARDUINOJSON_HAS_LONG_LONG -template <> -struct is_signed : true_type {}; + is_same::type, signed long long>::value || #endif - #if ARDUINOJSON_HAS_INT64 -template <> -struct is_signed : true_type {}; + is_same::type, signed __int64>::value || #endif + is_same::type, float>::value || + is_same::type, double>::value> {}; +// clang-format on } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp index be2649829..57acff232 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/is_unsigned.hpp @@ -5,33 +5,24 @@ #pragma once #include "integral_constant.hpp" +#include "is_same.hpp" +#include "remove_cv.hpp" + namespace ARDUINOJSON_NAMESPACE { -template -struct is_unsigned : false_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - -template <> -struct is_unsigned : true_type {}; - +// clang-format off +template +struct is_unsigned : integral_constant::type, unsigned char>::value || + is_same::type, unsigned short>::value || + is_same::type, unsigned int>::value || + is_same::type, unsigned long>::value || #if ARDUINOJSON_HAS_INT64 -template <> -struct is_unsigned : true_type {}; + is_same::type, unsigned __int64>::value || #endif - #if ARDUINOJSON_HAS_LONG_LONG -template <> -struct is_unsigned : true_type {}; + is_same::type, unsigned long long>::value || #endif + is_same::type, bool>::value> {}; +// clang-format on } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/make_void.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/make_void.hpp new file mode 100644 index 000000000..cb2ebde52 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/make_void.hpp @@ -0,0 +1,14 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +struct make_void { + typedef void type; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/remove_cv.hpp b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/remove_cv.hpp new file mode 100644 index 000000000..021e0ec5c --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Polyfills/type_traits/remove_cv.hpp @@ -0,0 +1,27 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct remove_cv { + typedef T type; +}; +template +struct remove_cv { + typedef T type; +}; +template +struct remove_cv { + typedef T type; +}; +template +struct remove_cv { + typedef T type; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp b/lib/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp index 52bd1175d..f9a979855 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp @@ -31,17 +31,17 @@ class Writer { #include #if ARDUINOJSON_ENABLE_STD_STRING -#include +# include #endif #if ARDUINOJSON_ENABLE_ARDUINO_STRING -#include +# include #endif #if ARDUINOJSON_ENABLE_STD_STREAM -#include +# include #endif #if ARDUINOJSON_ENABLE_ARDUINO_PRINT -#include +# include #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp b/lib/ArduinoJson/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp index 5efa6e492..5bb1ebd78 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp @@ -22,10 +22,10 @@ class Writer< ::String, void> { } size_t write(uint8_t c) { - ARDUINOJSON_ASSERT(_size < bufferCapacity); - _buffer[_size++] = static_cast(c); if (_size + 1 >= bufferCapacity) - flush(); + if (flush() != 0) + return 0; + _buffer[_size++] = static_cast(c); return 1; } @@ -36,14 +36,15 @@ class Writer< ::String, void> { return n; } - private: - void flush() { + size_t flush() { ARDUINOJSON_ASSERT(_size < bufferCapacity); _buffer[_size] = 0; - *_destination += _buffer; - _size = 0; + if (_destination->concat(_buffer)) + _size = 0; + return _size; } + private: ::String *_destination; char _buffer[bufferCapacity]; size_t _size; diff --git a/lib/ArduinoJson/src/ArduinoJson/StringStorage/StringCopier.hpp b/lib/ArduinoJson/src/ArduinoJson/StringStorage/StringCopier.hpp index 8b1104b4c..80670aad3 100644 --- a/lib/ArduinoJson/src/ArduinoJson/StringStorage/StringCopier.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/StringStorage/StringCopier.hpp @@ -55,8 +55,12 @@ class StringCopier { private: MemoryPool* _pool; + + // These fields aren't initialized by the constructor but startString() + // + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) char* _ptr; - size_t _size; - size_t _capacity; + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) + size_t _size, _capacity; }; } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp similarity index 63% rename from lib/ArduinoJson/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp rename to lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp index 24646ccda..5e4b62403 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/ArduinoStringAdapter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp @@ -7,14 +7,15 @@ #include #include -#include #include +#include namespace ARDUINOJSON_NAMESPACE { -class ArduinoStringAdapter { +template <> +class StringAdapter< ::String> { public: - ArduinoStringAdapter(const ::String& str) : _str(&str) {} + StringAdapter(const ::String& str) : _str(&str) {} void copyTo(char* p, size_t n) const { memcpy(p, _str->c_str(), n); @@ -31,18 +32,10 @@ class ArduinoStringAdapter { return safe_strcmp(me, other); } - bool equals(const char* expected) const { - return compare(expected) == 0; - } - size_t size() const { return _str->length(); } - const char* begin() const { - return _str->c_str(); - } - typedef storage_policies::store_by_copy storage_policy; private: @@ -50,13 +43,10 @@ class ArduinoStringAdapter { }; template <> -struct IsString< ::String> : true_type {}; - -template <> -struct IsString< ::StringSumHelper> : true_type {}; - -inline ArduinoStringAdapter adaptString(const ::String& str) { - return ArduinoStringAdapter(str); -} +class StringAdapter< ::StringSumHelper> : public StringAdapter< ::String> { + public: + StringAdapter< ::StringSumHelper>(const ::String& s) + : StringAdapter< ::String>(s) {} +}; } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp similarity index 61% rename from lib/ArduinoJson/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp rename to lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp index ec7d53a6d..1ca7c02cc 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/ConstRamStringAdapter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp @@ -8,23 +8,20 @@ #include // strcmp #include -#include #include +#include namespace ARDUINOJSON_NAMESPACE { -class ConstRamStringAdapter { +template <> +class StringAdapter { public: - ConstRamStringAdapter(const char* str = 0) : _str(str) {} + StringAdapter(const char* str = 0) : _str(str) {} int compare(const char* other) const { return safe_strcmp(_str, other); } - bool equals(const char* expected) const { - return compare(expected) == 0; - } - bool isNull() const { return !_str; } @@ -39,24 +36,16 @@ class ConstRamStringAdapter { return _str; } - const char* begin() const { - return _str; - } - typedef storage_policies::store_by_address storage_policy; protected: const char* _str; }; -template <> -struct IsString : true_type {}; - template -struct IsString : true_type {}; - -inline ConstRamStringAdapter adaptString(const char* str) { - return ConstRamStringAdapter(str); -} +class StringAdapter : public StringAdapter { + public: + StringAdapter(const char* s) : StringAdapter(s) {} +}; } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/FlashStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp similarity index 62% rename from lib/ArduinoJson/src/ArduinoJson/Strings/FlashStringAdapter.hpp rename to lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp index 292e348b4..3a958181d 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/FlashStringAdapter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp @@ -5,15 +5,15 @@ #pragma once #include -#include -#include #include +#include namespace ARDUINOJSON_NAMESPACE { -class FlashStringAdapter { +template <> +class StringAdapter { public: - FlashStringAdapter(const __FlashStringHelper* str) : _str(str) {} + StringAdapter(const __FlashStringHelper* str) : _str(str) {} int compare(const char* other) const { if (!other && !_str) @@ -25,10 +25,6 @@ class FlashStringAdapter { return -strcmp_P(other, reinterpret_cast(_str)); } - bool equals(const char* expected) const { - return compare(expected) == 0; - } - bool isNull() const { return !_str; } @@ -43,20 +39,10 @@ class FlashStringAdapter { return strlen_P(reinterpret_cast(_str)); } - FlashStringIterator begin() const { - return FlashStringIterator(_str); - } - typedef storage_policies::store_by_copy storage_policy; private: const __FlashStringHelper* _str; }; -inline FlashStringAdapter adaptString(const __FlashStringHelper* str) { - return FlashStringAdapter(str); -} - -template <> -struct IsString : true_type {}; } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp new file mode 100644 index 000000000..c34abce5e --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp @@ -0,0 +1,27 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template <> +class StringAdapter : public StringAdapter { + public: + StringAdapter(const String& str) + : StringAdapter(str.c_str()), _isStatic(str.isStatic()) {} + + bool isStatic() const { + return _isStatic; + } + + typedef storage_policies::decide_at_runtime storage_policy; + + private: + bool _isStatic; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp new file mode 100644 index 000000000..f2b01d171 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/RamStringAdapter.hpp @@ -0,0 +1,29 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +class StringAdapter::value>::type> + : public StringAdapter { + public: + StringAdapter(const TChar* str) + : StringAdapter(reinterpret_cast(str)) {} + + void copyTo(char* p, size_t n) const { + memcpy(p, _str, n); + } + + typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp similarity index 61% rename from lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp rename to lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp index b9cc0bff8..b2d012fce 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/SizedFlashStringAdapter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp @@ -5,15 +5,15 @@ #pragma once #include -#include -#include #include +#include namespace ARDUINOJSON_NAMESPACE { -class SizedFlashStringAdapter { +template <> +class StringAdapter { public: - SizedFlashStringAdapter(const __FlashStringHelper* str, size_t sz) + StringAdapter(const __FlashStringHelper* str, size_t sz) : _str(str), _size(sz) {} int compare(const char* other) const { @@ -26,10 +26,6 @@ class SizedFlashStringAdapter { return -strncmp_P(other, reinterpret_cast(_str), _size); } - bool equals(const char* expected) const { - return compare(expected) == 0; - } - bool isNull() const { return !_str; } @@ -42,10 +38,6 @@ class SizedFlashStringAdapter { return _size; } - FlashStringIterator begin() const { - return FlashStringIterator(_str); - } - typedef storage_policies::store_by_copy storage_policy; private: @@ -53,8 +45,4 @@ class SizedFlashStringAdapter { size_t _size; }; -inline SizedFlashStringAdapter adaptString(const __FlashStringHelper* str, - size_t sz) { - return SizedFlashStringAdapter(str, sz); -} } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp similarity index 61% rename from lib/ArduinoJson/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp rename to lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp index fe23408f8..a18d5ab92 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/SizedRamStringAdapter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp @@ -5,25 +5,22 @@ #pragma once #include -#include #include +#include #include // strcmp namespace ARDUINOJSON_NAMESPACE { -class SizedRamStringAdapter { +template +class StringAdapter { public: - SizedRamStringAdapter(const char* str, size_t n) : _str(str), _size(n) {} + StringAdapter(const char* str, size_t n) : _str(str), _size(n) {} int compare(const char* other) const { return safe_strncmp(_str, other, _size); } - bool equals(const char* expected) const { - return compare(expected) == 0; - } - bool isNull() const { return !_str; } @@ -36,10 +33,6 @@ class SizedRamStringAdapter { return _size; } - const char* begin() const { - return _str; - } - typedef storage_policies::store_by_copy storage_policy; private: @@ -47,9 +40,4 @@ class SizedRamStringAdapter { size_t _size; }; -template -inline SizedRamStringAdapter adaptString(const TChar* str, size_t size) { - return SizedRamStringAdapter(reinterpret_cast(str), size); -} - } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/StdStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/StdStringAdapter.hpp new file mode 100644 index 000000000..4d2d32c52 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/StdStringAdapter.hpp @@ -0,0 +1,46 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +class StringAdapter > { + public: + typedef std::basic_string string_type; + + StringAdapter(const string_type& str) : _str(&str) {} + + void copyTo(char* p, size_t n) const { + memcpy(p, _str->c_str(), n); + } + + bool isNull() const { + return false; + } + + int compare(const char* other) const { + if (!other) + return 1; + return _str->compare(other); + } + + size_t size() const { + return _str->size(); + } + + typedef storage_policies::store_by_copy storage_policy; + + private: + const string_type* _str; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/StringViewAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/StringViewAdapter.hpp new file mode 100644 index 000000000..787f7c21f --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/Adapters/StringViewAdapter.hpp @@ -0,0 +1,44 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include +#include +#include + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template <> +class StringAdapter { + public: + StringAdapter(std::string_view str) : _str(str) {} + + void copyTo(char* p, size_t n) const { + memcpy(p, _str.data(), n); + } + + bool isNull() const { + return false; + } + + int compare(const char* other) const { + if (!other) + return 1; + return _str.compare(other); + } + + size_t size() const { + return _str.size(); + } + + typedef storage_policies::store_by_copy storage_policy; + + private: + std::string_view _str; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/FlashStringIterator.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/FlashStringIterator.hpp deleted file mode 100644 index 9a97f3247..000000000 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/FlashStringIterator.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright Benoit Blanchon 2014-2021 -// MIT License - -#pragma once - -namespace ARDUINOJSON_NAMESPACE { - -class FlashStringIterator { - public: - explicit FlashStringIterator(const __FlashStringHelper* ptr) - : _ptr(reinterpret_cast(ptr)) {} - - explicit FlashStringIterator(const char* ptr) : _ptr(ptr) {} - - FlashStringIterator operator+(ptrdiff_t d) const { - return FlashStringIterator(_ptr + d); - } - - ptrdiff_t operator-(FlashStringIterator other) const { - return _ptr - other._ptr; - } - - FlashStringIterator operator++(int) { - return FlashStringIterator(_ptr++); - } - - FlashStringIterator operator++() { - return FlashStringIterator(++_ptr); - } - - bool operator!=(FlashStringIterator other) const { - return _ptr != other._ptr; - } - - char operator*() const { - return char(pgm_read_byte(_ptr)); - } - - private: - const char* _ptr; -}; - -} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/IsString.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/IsString.hpp deleted file mode 100644 index af5a91a22..000000000 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/IsString.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright Benoit Blanchon 2014-2021 -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { -template -struct IsString : false_type {}; - -template -struct IsString : IsString {}; - -template -struct IsString : IsString {}; -} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/IsWriteableString.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/IsWriteableString.hpp index 32039e3dd..556c4765a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/IsWriteableString.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/IsWriteableString.hpp @@ -8,11 +8,11 @@ #include #if ARDUINOJSON_ENABLE_ARDUINO_STRING -#include +# include #endif #if ARDUINOJSON_ENABLE_STD_STRING -#include +# include #endif namespace ARDUINOJSON_NAMESPACE { diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/RamStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/RamStringAdapter.hpp deleted file mode 100644 index eded6c97d..000000000 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/RamStringAdapter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright Benoit Blanchon 2014-2021 -// MIT License - -#pragma once - -#include -#include -#include - -namespace ARDUINOJSON_NAMESPACE { - -class RamStringAdapter : public ConstRamStringAdapter { - public: - RamStringAdapter(const char* str) : ConstRamStringAdapter(str) {} - - void copyTo(char* p, size_t n) const { - memcpy(p, _str, n); - } - - typedef ARDUINOJSON_NAMESPACE::storage_policies::store_by_copy storage_policy; -}; - -template -inline RamStringAdapter adaptString(const TChar* str) { - return RamStringAdapter(reinterpret_cast(str)); -} - -inline RamStringAdapter adaptString(char* str) { - return RamStringAdapter(str); -} - -template -struct IsString { - static const bool value = sizeof(TChar) == 1; -}; - -template <> -struct IsString { - static const bool value = false; -}; - -} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/StdStringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/StdStringAdapter.hpp deleted file mode 100644 index ebf4c3969..000000000 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/StdStringAdapter.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright Benoit Blanchon 2014-2021 -// MIT License - -#pragma once - -#include -#include -#include - -#include - -namespace ARDUINOJSON_NAMESPACE { - -template -class StdStringAdapter { - public: - StdStringAdapter(const TString& str) : _str(&str) {} - - void copyTo(char* p, size_t n) const { - memcpy(p, _str->c_str(), n); - } - - bool isNull() const { - return false; - } - - int compare(const char* other) const { - if (!other) - return 1; - return _str->compare(other); - } - - bool equals(const char* expected) const { - if (!expected) - return false; - return *_str == expected; - } - - size_t size() const { - return _str->size(); - } - - const char* begin() const { - return _str->c_str(); - } - - typedef storage_policies::store_by_copy storage_policy; - - private: - const TString* _str; -}; - -template -struct IsString > : true_type { -}; - -template -inline StdStringAdapter > -adaptString(const std::basic_string& str) { - return StdStringAdapter >( - str); -} - -} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/String.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/String.hpp index 4f2abdea4..fff4077d9 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/String.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/String.hpp @@ -4,10 +4,6 @@ #pragma once -#include -#include -#include - namespace ARDUINOJSON_NAMESPACE { class String { @@ -53,25 +49,4 @@ class String { bool _isStatic; }; -class StringAdapter : public RamStringAdapter { - public: - StringAdapter(const String& str) - : RamStringAdapter(str.c_str()), _isStatic(str.isStatic()) {} - - bool isStatic() const { - return _isStatic; - } - - typedef storage_policies::decide_at_runtime storage_policy; - - private: - bool _isStatic; -}; - -template <> -struct IsString : true_type {}; - -inline StringAdapter adaptString(const String& str) { - return StringAdapter(str); -} } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapter.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapter.hpp new file mode 100644 index 000000000..1d55b2123 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapter.hpp @@ -0,0 +1,32 @@ +// ArduinoJson - https://arduinojson.org +// Copyright Benoit Blanchon 2014-2021 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +class StringAdapter; + +template +inline StringAdapter adaptString(const T& str) { + return StringAdapter(str); +} + +template +inline StringAdapter adaptString(const T& str, size_t sz) { + return StringAdapter(str, sz); +} + +template +struct IsString : false_type {}; + +template +struct IsString< + T, typename make_void::storage_policy>::type> + : true_type {}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapters.hpp b/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapters.hpp index 3d294d29c..ba763a67f 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapters.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Strings/StringAdapters.hpp @@ -4,19 +4,24 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include #if ARDUINOJSON_ENABLE_STD_STRING -#include +# include +#endif + +#if ARDUINOJSON_ENABLE_STRING_VIEW +# include #endif #if ARDUINOJSON_ENABLE_ARDUINO_STRING -#include +# include #endif #if ARDUINOJSON_ENABLE_PROGMEM -#include -#include +# include +# include #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Variant/Converter.hpp b/lib/ArduinoJson/src/ArduinoJson/Variant/Converter.hpp index 476ca8fdf..88afa526d 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Variant/Converter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Variant/Converter.hpp @@ -9,4 +9,9 @@ namespace ARDUINOJSON_NAMESPACE { template struct Converter; +// clang-format off +template +class InvalidConversion; // Error here? See https://arduinojson.org/v6/invalid-conversion/ +// clang-format on + } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp index 34e12bbb7..33f8c6509 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Variant/ConverterImpl.hpp @@ -12,9 +12,9 @@ namespace ARDUINOJSON_NAMESPACE { template 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 struct Converter< T, typename enable_if::value && !is_same::value && !is_same::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 struct Converter::value>::type> { - static bool toJson(T src, VariantRef dst) { - return dst.set(static_cast(src)); + static void toJson(T src, VariantRef dst) { + dst.set(static_cast(src)); } static T fromJson(VariantConstRef src) { @@ -78,12 +76,10 @@ struct Converter::value>::type> { template <> struct Converter { - 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 { template struct Converter::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(src)); - return true; + if (data) + data->setFloat(static_cast(src)); } static T fromJson(VariantConstRef src) { @@ -120,8 +114,8 @@ struct Converter::value>::type> { template <> struct Converter { - 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 > { - static bool toJson(SerializedValue src, VariantRef dst) { + static void toJson(SerializedValue 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 > { template struct Converter, typename enable_if::value>::type> { - static bool toJson(SerializedValue src, VariantRef dst) { + static void toJson(SerializedValue 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, template <> struct Converter { - 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,33 @@ 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 + +#if ARDUINOJSON_ENABLE_STRING_VIEW + +inline void convertFromJson(VariantConstRef src, std::string_view& dst) { + const char* str = src.as(); + if (str) // the standard doesn't allow passing null to the constructor + dst = std::string_view(str); +} + +inline bool canConvertFromJson(VariantConstRef src, const std::string_view&) { + return src.is(); } #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantCompare.hpp b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantCompare.hpp index 025ef90a2..4e0471a60 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantCompare.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantCompare.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include namespace ARDUINOJSON_NAMESPACE { diff --git a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp index 82ae745d4..388b7e251 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp @@ -7,17 +7,17 @@ #include #include #include -#include +#include #include // VariantData can't have a constructor (to be a POD), so we have no way to fix // this warning #if defined(__GNUC__) -#if __GNUC__ >= 7 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#pragma GCC diagnostic ignored "-Wuninitialized" -#endif +# if __GNUC__ >= 7 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +# pragma GCC diagnostic ignored "-Wuninitialized" +# endif #endif namespace ARDUINOJSON_NAMESPACE { @@ -33,7 +33,7 @@ class VariantData { // - no virtual // - no inheritance void init() { - _flags = 0; + _flags = VALUE_IS_NULL; } template @@ -103,7 +103,8 @@ class VariantData { case VALUE_IS_OBJECT: return toObject().copyFrom(src._content.asCollection, pool); case VALUE_IS_OWNED_STRING: - return setString(RamStringAdapter(src._content.asString), pool); + return setString(adaptString(const_cast(src._content.asString)), + pool); case VALUE_IS_OWNED_RAW: return setOwnedRaw( serialized(src._content.asRaw.data, src._content.asRaw.size), pool); @@ -362,7 +363,7 @@ class VariantData { } // namespace ARDUINOJSON_NAMESPACE #if defined(__GNUC__) -#if __GNUC__ >= 8 -#pragma GCC diagnostic pop -#endif +# if __GNUC__ >= 8 +# pragma GCC diagnostic pop +# endif #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantImpl.hpp index b91e58450..ea49a92f6 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantImpl.hpp @@ -140,4 +140,9 @@ inline VariantConstRef operator|(VariantConstRef preferedValue, VariantConstRef defaultValue) { return preferedValue ? preferedValue : defaultValue; } + +// Out of class definition to avoid #1560 +inline bool VariantRef::set(char value) const { + return set(value); +} } // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp index 8d4c41088..b05ed90ca 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp @@ -85,18 +85,18 @@ class VariantRef : public VariantRefBase, template FORCE_INLINE bool set(const T &value) const { - return Converter::toJson(value, *this); + Converter::toJson(value, *this); + return _pool && !_pool->overflowed(); } - FORCE_INLINE bool ARDUINOJSON_DEPRECATED( + bool ARDUINOJSON_DEPRECATED( "Support for char is deprecated, use int8_t or uint8_t instead") - set(char value) const { - return set(value); - } + set(char value) const; template FORCE_INLINE bool set(T *value) const { - return Converter::toJson(value, *this); + Converter::toJson(value, *this); + return _pool && !_pool->overflowed(); } template @@ -341,16 +341,22 @@ class VariantConstRef : public VariantRefBase, template <> struct Converter { - 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) { return src; } + + static InvalidConversion fromJson( + VariantConstRef); + static bool checkJson(VariantRef src) { VariantData *data = getData(src); return !!data; } + static bool checkJson(VariantConstRef) { return false; } @@ -358,8 +364,8 @@ struct Converter { template <> struct Converter { - 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) { diff --git a/lib/ArduinoJson/src/ArduinoJson/version.hpp b/lib/ArduinoJson/src/ArduinoJson/version.hpp index d8aaf77d1..6ddc84486 100644 --- a/lib/ArduinoJson/src/ArduinoJson/version.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/version.hpp @@ -4,7 +4,7 @@ #pragma once -#define ARDUINOJSON_VERSION "6.18.0" +#define ARDUINOJSON_VERSION "6.18.3" #define ARDUINOJSON_VERSION_MAJOR 6 #define ARDUINOJSON_VERSION_MINOR 18 -#define ARDUINOJSON_VERSION_REVISION 0 +#define ARDUINOJSON_VERSION_REVISION 3 diff --git a/lib_standalone/WString.h b/lib_standalone/WString.h index 5914fd141..04cb3d2e5 100644 --- a/lib_standalone/WString.h +++ b/lib_standalone/WString.h @@ -45,6 +45,13 @@ class String { return _str == s; } + bool concat(const char * rhs) { + if (!rhs) { + return 0; + } + _str += rhs; + return 1; + } private: std::string _str; @@ -60,7 +67,6 @@ inline bool operator!=(const ::String & lhs, const ::String & rhs) { return lhs.c_str() != rhs.c_str(); } - size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize); size_t strlcat(char * dst, const char * src, size_t siz);