Update ArduinoJson to 6.18.3

This commit is contained in:
proddy
2021-07-28 10:06:51 +02:00
parent 362fead7e8
commit 39fef48915
61 changed files with 1259 additions and 1164 deletions

View File

@@ -28,4 +28,5 @@
- maintenance settings for time/date as extra setting - maintenance settings for time/date as extra setting
- move api/mqtt formats to `settings`, add `enum format` - move api/mqtt formats to `settings`, add `enum format`
- UI improvements for editing Dallas Sensor details - 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

View File

@@ -1,6 +1,31 @@
ArduinoJson: change log ArduinoJson: change log
======================= =======================
v6.18.3 (2021-07-27)
-------
* Changed return type of `convertToJson()` and `Converter<T>::toJson()` to `void`
* Added `as<std::string_view>()` and `is<std::string_view>()`
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<T1,T2>` 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<unsigned>()` (issue #1601)
* Added support for ESP-IDF component build (PR #1562 by @qt1, PR #1599 by @andreaskuster)
v6.18.0 (2021-05-05) v6.18.0 (2021-05-05)
------- -------

View File

@@ -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://github.com/bblanchon/ArduinoJson/workflows/Continuous%20Integration/badge.svg?branch=6.x)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) [![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
@@ -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) * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme)
* Deduplicates strings * Deduplicates strings
* Versatile * Versatile
* [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme) * Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme)
* Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/?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 [`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 [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 [`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 [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme)
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer) * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer)
* Supports custom converters * Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/?utm_source=github&utm_medium=readme)
* Portable * Portable
* Usable on any C++ project (not limited to Arduino) * Usable on any C++ project (not limited to Arduino)
* Compatible with C++98 * Compatible with C++98, C++11, C++14 and C++17
* Zero warnings with `-Wall -Wextra -pedantic` and `/W4` * Zero warnings with `-Wall -Wextra -pedantic` and `/W4`
* [Header-only library](https://en.wikipedia.org/wiki/Header-only) * [Header-only library](https://en.wikipedia.org/wiki/Header-only)
* Works with virtually any board * 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) * [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) * [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) * [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 * Well documented
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) * [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) * [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) * [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme)
* [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme) * [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme)
* [Troubleshooter](https://arduinojson.org/v6/troubleshooter/?utm_source=github&utm_medium=readme)
* [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme) * [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme)
* [Changelog](CHANGELOG.md) * [Changelog](CHANGELOG.md)
* Vibrant user community * Vibrant user community
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search) * Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories)
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson) * [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)
* [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed) * [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) 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? 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).

View File

@@ -7,11 +7,11 @@
#include "ArduinoJson/Configuration.hpp" #include "ArduinoJson/Configuration.hpp"
#if !ARDUINOJSON_DEBUG #if !ARDUINOJSON_DEBUG
#ifdef __clang__ # ifdef __clang__
#pragma clang system_header # pragma clang system_header
#elif defined __GNUC__ # elif defined __GNUC__
#pragma GCC system_header # pragma GCC system_header
#endif # endif
#endif #endif
#include "ArduinoJson/Array/ArrayRef.hpp" #include "ArduinoJson/Array/ArrayRef.hpp"

View File

@@ -161,14 +161,20 @@ class ArrayRef : public ArrayRefBase<CollectionData>,
_data->removeElement(index); _data->removeElement(index);
} }
void clear() const {
if (!_data)
return;
_data->clear();
}
private: private:
MemoryPool* _pool; MemoryPool* _pool;
}; };
template <> template <>
struct Converter<ArrayConstRef> { struct Converter<ArrayConstRef> {
static bool toJson(VariantConstRef src, VariantRef dst) { static void toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst)); variantCopyFrom(getData(dst), getData(src), getPool(dst));
} }
static ArrayConstRef fromJson(VariantConstRef src) { static ArrayConstRef fromJson(VariantConstRef src) {
@@ -183,8 +189,8 @@ struct Converter<ArrayConstRef> {
template <> template <>
struct Converter<ArrayRef> { struct Converter<ArrayRef> {
static bool toJson(VariantConstRef src, VariantRef dst) { static void toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst)); variantCopyFrom(getData(dst), getData(src), getPool(dst));
} }
static ArrayRef fromJson(VariantRef src) { static ArrayRef fromJson(VariantRef src) {
@@ -193,6 +199,8 @@ struct Converter<ArrayRef> {
return ArrayRef(pool, data != 0 ? data->asArray() : 0); return ArrayRef(pool, data != 0 ? data->asArray() : 0);
} }
static InvalidConversion<VariantConstRef, ArrayRef> fromJson(VariantConstRef);
static bool checkJson(VariantConstRef) { static bool checkJson(VariantConstRef) {
return false; return false;
} }

View File

@@ -10,8 +10,8 @@
#include <ArduinoJson/Variant/VariantTo.hpp> #include <ArduinoJson/Variant/VariantTo.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
#pragma warning(disable : 4522) # pragma warning(disable : 4522)
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -178,8 +178,8 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
return _array.getOrAddElement(_index); return _array.getOrAddElement(_index);
} }
friend bool convertToJson(const this_type& src, VariantRef dst) { friend void convertToJson(const this_type& src, VariantRef dst) {
return dst.set(src.getUpstreamElement()); dst.set(src.getUpstreamElement());
} }
TArray _array; TArray _array;
@@ -189,5 +189,5 @@ class ElementProxy : public VariantOperators<ElementProxy<TArray> >,
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif

View File

@@ -62,9 +62,9 @@ inline bool CollectionData::copyFrom(const CollectionData& src,
VariantData* var; VariantData* var;
if (s->key() != 0) { if (s->key() != 0) {
if (s->ownsKey()) if (s->ownsKey())
var = addMember(RamStringAdapter(s->key()), pool); var = addMember(adaptString(const_cast<char*>(s->key())), pool);
else else
var = addMember(ConstRamStringAdapter(s->key()), pool); var = addMember(adaptString(s->key()), pool);
} else { } else {
var = addElement(pool); var = addElement(pool);
} }
@@ -107,7 +107,7 @@ template <typename TAdaptedString>
inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
VariantSlot* slot = _head; VariantSlot* slot = _head;
while (slot) { while (slot) {
if (key.equals(slot->key())) if (key.compare(slot->key()) == 0)
break; break;
slot = slot->next(); slot = slot->next();
} }

View File

@@ -5,251 +5,269 @@
#pragma once #pragma once
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#define ARDUINOJSON_HAS_LONG_LONG 1 # define ARDUINOJSON_HAS_LONG_LONG 1
#define ARDUINOJSON_HAS_NULLPTR 1 # define ARDUINOJSON_HAS_RVALUE_REFERENCES 1
#define ARDUINOJSON_HAS_RVALUE_REFERENCES 1
#else #else
#define ARDUINOJSON_HAS_LONG_LONG 0 # define ARDUINOJSON_HAS_LONG_LONG 0
#define ARDUINOJSON_HAS_NULLPTR 0 # define ARDUINOJSON_HAS_RVALUE_REFERENCES 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 #endif
#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG #if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG
#define ARDUINOJSON_HAS_INT64 1 # define ARDUINOJSON_HAS_INT64 1
#else #else
#define ARDUINOJSON_HAS_INT64 0 # define ARDUINOJSON_HAS_INT64 0
#endif #endif
// Small or big machine? // Small or big machine?
#ifndef ARDUINOJSON_EMBEDDED_MODE #ifndef ARDUINOJSON_EMBEDDED_MODE
#if defined(ARDUINO) /* Arduino*/ \ # if defined(ARDUINO) /* Arduino*/ \
|| defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \
|| defined(__XC) /* MPLAB XC compiler */ \ || defined(__XC) /* MPLAB XC compiler */ \
|| defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \
|| defined(__AVR) /* Atmel AVR8/GNU C Compiler */ || defined(__AVR) /* Atmel AVR8/GNU C Compiler */
#define ARDUINOJSON_EMBEDDED_MODE 1 # define ARDUINOJSON_EMBEDDED_MODE 1
#else # else
#define ARDUINOJSON_EMBEDDED_MODE 0 # define ARDUINOJSON_EMBEDDED_MODE 0
#endif # endif
#endif #endif
// Auto enable std::stream if the right headers are here and no conflicting // Auto enable std::stream if the right headers are here and no conflicting
// macro is defined // macro is defined
#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) #if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include)
#if __has_include(<istream>) && \ # if __has_include(<istream>) && \
__has_include(<ostream>) && \ __has_include(<ostream>) && \
!defined(min) && \ !defined(min) && \
!defined(max) !defined(max)
#define ARDUINOJSON_ENABLE_STD_STREAM 1 # define ARDUINOJSON_ENABLE_STD_STREAM 1
#else # else
#define ARDUINOJSON_ENABLE_STD_STREAM 0 # define ARDUINOJSON_ENABLE_STD_STREAM 0
#endif # endif
#endif #endif
// Auto enable std::string if the right header is here and no conflicting // Auto enable std::string if the right header is here and no conflicting
// macro is defined // macro is defined
#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) #if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include)
#if __has_include(<string>) && !defined(min) && !defined(max) # if __has_include(<string>) && !defined(min) && !defined(max)
#define ARDUINOJSON_ENABLE_STD_STRING 1 # define ARDUINOJSON_ENABLE_STD_STRING 1
#else # else
#define ARDUINOJSON_ENABLE_STD_STRING 0 # define ARDUINOJSON_ENABLE_STD_STRING 0
# endif
#endif #endif
#ifndef ARDUINOJSON_ENABLE_STRING_VIEW
# ifdef __has_include
# if __has_include(<string_view>) && __cplusplus >= 201703L
# define ARDUINOJSON_ENABLE_STRING_VIEW 1
# endif
# endif
#endif
#ifndef ARDUINOJSON_ENABLE_STRING_VIEW
# define ARDUINOJSON_ENABLE_STRING_VIEW 0
#endif #endif
#if ARDUINOJSON_EMBEDDED_MODE #if ARDUINOJSON_EMBEDDED_MODE
// Store floats by default to reduce the memory usage (issue #134) // Store floats by default to reduce the memory usage (issue #134)
#ifndef ARDUINOJSON_USE_DOUBLE # ifndef ARDUINOJSON_USE_DOUBLE
#define ARDUINOJSON_USE_DOUBLE 0 # define ARDUINOJSON_USE_DOUBLE 0
#endif # endif
// Store longs by default, because they usually match the size of a float. // Store longs by default, because they usually match the size of a float.
#ifndef ARDUINOJSON_USE_LONG_LONG # ifndef ARDUINOJSON_USE_LONG_LONG
#define ARDUINOJSON_USE_LONG_LONG 0 # define ARDUINOJSON_USE_LONG_LONG 0
#endif # endif
// Embedded systems usually don't have std::string // Embedded systems usually don't have std::string
#ifndef ARDUINOJSON_ENABLE_STD_STRING # ifndef ARDUINOJSON_ENABLE_STD_STRING
#define ARDUINOJSON_ENABLE_STD_STRING 0 # define ARDUINOJSON_ENABLE_STD_STRING 0
#endif # endif
// Embedded systems usually don't have std::stream // Embedded systems usually don't have std::stream
#ifndef ARDUINOJSON_ENABLE_STD_STREAM # ifndef ARDUINOJSON_ENABLE_STD_STREAM
#define ARDUINOJSON_ENABLE_STD_STREAM 0 # define ARDUINOJSON_ENABLE_STD_STREAM 0
#endif # endif
// Limit nesting as the stack is likely to be small // Limit nesting as the stack is likely to be small
#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT # ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 # define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10
#endif # endif
// Number of bits to store the pointer to next node // Number of bits to store the pointer to next node
// (saves RAM but limits the number of values in a document) // (saves RAM but limits the number of values in a document)
#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE # ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
#if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2 # if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 2
// Address space == 16-bit => max 127 values // Address space == 16-bit => max 127 values
#define ARDUINOJSON_SLOT_OFFSET_SIZE 1 # define ARDUINOJSON_SLOT_OFFSET_SIZE 1
#else # else
// Address space > 16-bit => max 32767 values // Address space > 16-bit => max 32767 values
#define ARDUINOJSON_SLOT_OFFSET_SIZE 2 # define ARDUINOJSON_SLOT_OFFSET_SIZE 2
#endif # endif
#endif # endif
#else // ARDUINOJSON_EMBEDDED_MODE #else // ARDUINOJSON_EMBEDDED_MODE
// On a computer we have plenty of memory so we can use doubles // On a computer we have plenty of memory so we can use doubles
#ifndef ARDUINOJSON_USE_DOUBLE # ifndef ARDUINOJSON_USE_DOUBLE
#define ARDUINOJSON_USE_DOUBLE 1 # define ARDUINOJSON_USE_DOUBLE 1
#endif # endif
// Use long long when available // Use long long when available
#ifndef ARDUINOJSON_USE_LONG_LONG # ifndef ARDUINOJSON_USE_LONG_LONG
#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 # if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64
#define ARDUINOJSON_USE_LONG_LONG 1 # define ARDUINOJSON_USE_LONG_LONG 1
#else # else
#define ARDUINOJSON_USE_LONG_LONG 0 # define ARDUINOJSON_USE_LONG_LONG 0
#endif # endif
#endif # endif
// On a computer, we can use std::string // On a computer, we can use std::string
#ifndef ARDUINOJSON_ENABLE_STD_STRING # ifndef ARDUINOJSON_ENABLE_STD_STRING
#define ARDUINOJSON_ENABLE_STD_STRING 1 # define ARDUINOJSON_ENABLE_STD_STRING 1
#endif # endif
// On a computer, we can assume std::stream // On a computer, we can assume std::stream
#ifndef ARDUINOJSON_ENABLE_STD_STREAM # ifndef ARDUINOJSON_ENABLE_STD_STREAM
#define ARDUINOJSON_ENABLE_STD_STREAM 1 # define ARDUINOJSON_ENABLE_STD_STREAM 1
#endif # endif
// On a computer, the stack is large so we can increase nesting limit // On a computer, the stack is large so we can increase nesting limit
#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT # ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 # define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50
#endif # endif
// Number of bits to store the pointer to next node // Number of bits to store the pointer to next node
#ifndef ARDUINOJSON_SLOT_OFFSET_SIZE # ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
#define ARDUINOJSON_SLOT_OFFSET_SIZE 4 # define ARDUINOJSON_SLOT_OFFSET_SIZE 4
#endif # endif
#endif // ARDUINOJSON_EMBEDDED_MODE #endif // ARDUINOJSON_EMBEDDED_MODE
#ifdef ARDUINO #ifdef ARDUINO
#include <Arduino.h> # include <Arduino.h>
// Enable support for Arduino's String class // Enable support for Arduino's String class
#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING # ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 # define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
#endif # endif
// Enable support for Arduino's Stream class // Enable support for Arduino's Stream class
#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM # ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 # define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1
#endif # endif
// Enable support for Arduino's Print class // Enable support for Arduino's Print class
#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT # ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1 # define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1
#endif # endif
#else // ARDUINO #else // ARDUINO
// Disable support for Arduino's String class // Disable support for Arduino's String class
#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING # ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 # define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
#endif # endif
// Disable support for Arduino's Stream class // Disable support for Arduino's Stream class
#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM # ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 # define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0
#endif # endif
// Disable support for Arduino's Print class // Disable support for Arduino's Print class
#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT # ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT
#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 # define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0
#endif # endif
#endif // ARDUINO #endif // ARDUINO
#ifndef ARDUINOJSON_ENABLE_PROGMEM #ifndef ARDUINOJSON_ENABLE_PROGMEM
#if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \ # if defined(PROGMEM) && defined(pgm_read_byte) && defined(pgm_read_dword) && \
defined(pgm_read_ptr) && defined(pgm_read_float) defined(pgm_read_ptr) && defined(pgm_read_float)
#define ARDUINOJSON_ENABLE_PROGMEM 1 # define ARDUINOJSON_ENABLE_PROGMEM 1
#else # else
#define ARDUINOJSON_ENABLE_PROGMEM 0 # define ARDUINOJSON_ENABLE_PROGMEM 0
#endif # endif
#endif #endif
// Convert unicode escape sequence (\u0123) to UTF-8 // Convert unicode escape sequence (\u0123) to UTF-8
#ifndef ARDUINOJSON_DECODE_UNICODE #ifndef ARDUINOJSON_DECODE_UNICODE
#define ARDUINOJSON_DECODE_UNICODE 1 # define ARDUINOJSON_DECODE_UNICODE 1
#endif #endif
// Ignore comments in input // Ignore comments in input
#ifndef ARDUINOJSON_ENABLE_COMMENTS #ifndef ARDUINOJSON_ENABLE_COMMENTS
#define ARDUINOJSON_ENABLE_COMMENTS 0 # define ARDUINOJSON_ENABLE_COMMENTS 0
#endif #endif
// Support NaN in JSON // Support NaN in JSON
#ifndef ARDUINOJSON_ENABLE_NAN #ifndef ARDUINOJSON_ENABLE_NAN
#define ARDUINOJSON_ENABLE_NAN 0 # define ARDUINOJSON_ENABLE_NAN 0
#endif #endif
// Support Infinity in JSON // Support Infinity in JSON
#ifndef ARDUINOJSON_ENABLE_INFINITY #ifndef ARDUINOJSON_ENABLE_INFINITY
#define ARDUINOJSON_ENABLE_INFINITY 0 # define ARDUINOJSON_ENABLE_INFINITY 0
#endif #endif
// Control the exponentiation threshold for big numbers // Control the exponentiation threshold for big numbers
// CAUTION: cannot be more that 1e9 !!!! // CAUTION: cannot be more that 1e9 !!!!
#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD #ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD
#define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 # define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7
#endif #endif
// Control the exponentiation threshold for small numbers // Control the exponentiation threshold for small numbers
#ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD #ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD
#define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 # define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5
#endif #endif
#ifndef ARDUINOJSON_LITTLE_ENDIAN #ifndef ARDUINOJSON_LITTLE_ENDIAN
#if defined(_MSC_VER) || \ # if defined(_MSC_VER) || \
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ (defined(__BYTE_ORDER__) && \
defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64) __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
#define ARDUINOJSON_LITTLE_ENDIAN 1 defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64)
#else # define ARDUINOJSON_LITTLE_ENDIAN 1
#define ARDUINOJSON_LITTLE_ENDIAN 0 # else
#endif # define ARDUINOJSON_LITTLE_ENDIAN 0
# endif
#endif #endif
#ifndef ARDUINOJSON_ENABLE_ALIGNMENT #ifndef ARDUINOJSON_ENABLE_ALIGNMENT
#if defined(__AVR) # if defined(__AVR)
#define ARDUINOJSON_ENABLE_ALIGNMENT 0 # define ARDUINOJSON_ENABLE_ALIGNMENT 0
#else # else
#define ARDUINOJSON_ENABLE_ALIGNMENT 1 # define ARDUINOJSON_ENABLE_ALIGNMENT 1
#endif # endif
#endif #endif
#ifndef ARDUINOJSON_TAB #ifndef ARDUINOJSON_TAB
#define ARDUINOJSON_TAB " " # define ARDUINOJSON_TAB " "
#endif #endif
#ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION #ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
#define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 # define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1
#endif #endif
#ifndef ARDUINOJSON_STRING_BUFFER_SIZE #ifndef ARDUINOJSON_STRING_BUFFER_SIZE
#define ARDUINOJSON_STRING_BUFFER_SIZE 32 # define ARDUINOJSON_STRING_BUFFER_SIZE 32
#endif #endif
#ifndef ARDUINOJSON_DEBUG #ifndef ARDUINOJSON_DEBUG
#ifdef __PLATFORMIO_BUILD_DEBUG__ # ifdef __PLATFORMIO_BUILD_DEBUG__
#define ARDUINOJSON_DEBUG 1 # define ARDUINOJSON_DEBUG 1
#else # else
#define ARDUINOJSON_DEBUG 0 # define ARDUINOJSON_DEBUG 0
#endif # endif
#endif #endif
#if ARDUINOJSON_HAS_NULLPTR && defined(nullptr) #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 // See https://github.com/bblanchon/ArduinoJson/issues/1355
#endif #endif

View File

@@ -9,7 +9,7 @@
#include <ArduinoJson/Polyfills/static_array.hpp> #include <ArduinoJson/Polyfills/static_array.hpp>
#if ARDUINOJSON_ENABLE_STD_STREAM #if ARDUINOJSON_ENABLE_STD_STREAM
#include <ostream> # include <ostream>
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {

View File

@@ -40,17 +40,17 @@ struct BoundedReader {
#include <ArduinoJson/Deserialization/Readers/VariantReader.hpp> #include <ArduinoJson/Deserialization/Readers/VariantReader.hpp>
#if ARDUINOJSON_ENABLE_ARDUINO_STREAM #if ARDUINOJSON_ENABLE_ARDUINO_STREAM
#include <ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp> # include <ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_ARDUINO_STRING #if ARDUINOJSON_ENABLE_ARDUINO_STRING
#include <ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp> # include <ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_PROGMEM #if ARDUINOJSON_ENABLE_PROGMEM
#include <ArduinoJson/Deserialization/Readers/FlashReader.hpp> # include <ArduinoJson/Deserialization/Readers/FlashReader.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_STD_STREAM #if ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson/Deserialization/Readers/StdStreamReader.hpp> # include <ArduinoJson/Deserialization/Readers/StdStreamReader.hpp>
#endif #endif

View File

@@ -32,7 +32,7 @@ class JsonDocument : public Visitable {
void clear() { void clear() {
_pool.clear(); _pool.clear();
_data.setNull(); _data.init();
} }
template <typename T> template <typename T>
@@ -304,15 +304,15 @@ class JsonDocument : public Visitable {
protected: protected:
JsonDocument() : _pool(0, 0) { JsonDocument() : _pool(0, 0) {
_data.setNull(); _data.init();
} }
JsonDocument(MemoryPool pool) : _pool(pool) { JsonDocument(MemoryPool pool) : _pool(pool) {
_data.setNull(); _data.init();
} }
JsonDocument(char* buf, size_t capa) : _pool(buf, capa) { JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {
_data.setNull(); _data.init();
} }
~JsonDocument() {} ~JsonDocument() {}
@@ -337,8 +337,8 @@ class JsonDocument : public Visitable {
JsonDocument& operator=(const JsonDocument&); JsonDocument& operator=(const JsonDocument&);
}; };
inline bool convertToJson(const JsonDocument& src, VariantRef dst) { inline void convertToJson(const JsonDocument& src, VariantRef dst) {
return dst.set(src.as<VariantConstRef>()); dst.set(src.as<VariantConstRef>());
} }
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -45,7 +45,8 @@ class Latch {
} }
TReader _reader; TReader _reader;
char _current; char _current; // NOLINT(clang-analyzer-optin.cplusplus.UninitializedObject)
// Not initialized in constructor (+10 bytes on AVR)
bool _loaded; bool _loaded;
#if ARDUINOJSON_DEBUG #if ARDUINOJSON_DEBUG
bool _ended; bool _ended;

View File

@@ -155,7 +155,6 @@ class TextFormatter {
protected: protected:
CountingDecorator<TWriter> _writer; CountingDecorator<TWriter> _writer;
size_t _length;
private: private:
TextFormatter &operator=(const TextFormatter &); // cannot be assigned TextFormatter &operator=(const TextFormatter &); // cannot be assigned

View File

@@ -12,10 +12,10 @@
// we choose to ignore the problem to reduce the size of the code // we choose to ignore the problem to reduce the size of the code
// Garbage in => Garbage out // Garbage in => Garbage out
#if defined(__GNUC__) #if defined(__GNUC__)
#if __GNUC__ >= 7 # if __GNUC__ >= 7
#pragma GCC diagnostic push # pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif # endif
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -31,7 +31,7 @@ inline bool isLowSurrogate(uint16_t codeunit) {
class Codepoint { class Codepoint {
public: public:
Codepoint() : _highSurrogate(0) {} Codepoint() : _highSurrogate(0), _codepoint(0) {}
bool append(uint16_t codeunit) { bool append(uint16_t codeunit) {
if (isHighSurrogate(codeunit)) { if (isHighSurrogate(codeunit)) {
@@ -61,7 +61,7 @@ class Codepoint {
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#if defined(__GNUC__) #if defined(__GNUC__)
#if __GNUC__ >= 8 # if __GNUC__ >= 8
#pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif # endif
#endif #endif

View File

@@ -7,6 +7,7 @@
#include <ArduinoJson/Memory/Alignment.hpp> #include <ArduinoJson/Memory/Alignment.hpp>
#include <ArduinoJson/Polyfills/assert.hpp> #include <ArduinoJson/Polyfills/assert.hpp>
#include <ArduinoJson/Polyfills/mpl/max.hpp> #include <ArduinoJson/Polyfills/mpl/max.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <ArduinoJson/Variant/VariantSlot.hpp> #include <ArduinoJson/Variant/VariantSlot.hpp>
#include <string.h> // memmove #include <string.h> // memmove
@@ -37,7 +38,8 @@ class MemoryPool {
} }
void* buffer() { void* buffer() {
return _begin; return _begin; // NOLINT(clang-analyzer-unix.Malloc)
// movePointers() alters this pointer
} }
// Gets the capacity of the memoryPool in bytes // Gets the capacity of the memoryPool in bytes
@@ -63,7 +65,7 @@ class MemoryPool {
return 0; return 0;
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
const char* existingCopy = findString(str.begin()); const char* existingCopy = findString(str);
if (existingCopy) if (existingCopy)
return existingCopy; return existingCopy;
#endif #endif
@@ -85,7 +87,7 @@ class MemoryPool {
const char* saveStringFromFreeZone(size_t len) { const char* saveStringFromFreeZone(size_t len) {
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
const char* dup = findString(_left); const char* dup = findString(adaptString(_left));
if (dup) if (dup)
return dup; return dup;
#endif #endif
@@ -162,16 +164,11 @@ class MemoryPool {
} }
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION #if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
template <typename TIterator> template <typename TAdaptedString>
const char* findString(TIterator str) { const char* findString(const TAdaptedString& str) {
for (char* next = _begin; next < _left; ++next) { for (char* next = _begin; next < _left; ++next) {
char* begin = next; if (str.compare(next) == 0)
return next;
// try to match
for (TIterator it = str; *it == *next; ++it) {
if (*next++ == 0)
return begin;
}
// jump to next terminator // jump to next terminator
while (*next) ++next; while (*next) ++next;

View File

@@ -10,17 +10,17 @@
#ifndef ARDUINOJSON_NAMESPACE #ifndef ARDUINOJSON_NAMESPACE
#define ARDUINOJSON_NAMESPACE \ # define ARDUINOJSON_NAMESPACE \
ARDUINOJSON_CONCAT4( \ ARDUINOJSON_CONCAT4( \
ARDUINOJSON_CONCAT4(ArduinoJson, ARDUINOJSON_VERSION_MAJOR, \ ARDUINOJSON_CONCAT4(ArduinoJson, ARDUINOJSON_VERSION_MAJOR, \
ARDUINOJSON_VERSION_MINOR, \ ARDUINOJSON_VERSION_MINOR, \
ARDUINOJSON_VERSION_REVISION), \ ARDUINOJSON_VERSION_REVISION), \
_, \ _, \
ARDUINOJSON_HEX_DIGIT(ARDUINOJSON_ENABLE_PROGMEM, \ ARDUINOJSON_HEX_DIGIT( \
ARDUINOJSON_USE_LONG_LONG, ARDUINOJSON_USE_DOUBLE, \ ARDUINOJSON_ENABLE_PROGMEM, ARDUINOJSON_USE_LONG_LONG, \
ARDUINOJSON_ENABLE_STRING_DEDUPLICATION), \ ARDUINOJSON_USE_DOUBLE, ARDUINOJSON_ENABLE_STRING_DEDUPLICATION), \
ARDUINOJSON_HEX_DIGIT( \ ARDUINOJSON_HEX_DIGIT( \
ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \ ARDUINOJSON_ENABLE_NAN, ARDUINOJSON_ENABLE_INFINITY, \
ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE)) ARDUINOJSON_ENABLE_COMMENTS, ARDUINOJSON_DECODE_UNICODE))
#endif #endif

View File

@@ -22,11 +22,11 @@ typedef unsigned long UInt;
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#if ARDUINOJSON_HAS_LONG_LONG && !ARDUINOJSON_USE_LONG_LONG #if ARDUINOJSON_HAS_LONG_LONG && !ARDUINOJSON_USE_LONG_LONG
#define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) \ # define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) \
static_assert(sizeof(T) <= sizeof(ARDUINOJSON_NAMESPACE::Integer), \ static_assert(sizeof(T) <= sizeof(ARDUINOJSON_NAMESPACE::Integer), \
"To use 64-bit integers with ArduinoJson, you must set " \ "To use 64-bit integers with ArduinoJson, you must set " \
"ARDUINOJSON_USE_LONG_LONG to 1. See " \ "ARDUINOJSON_USE_LONG_LONG to 1. See " \
"https://arduinojson.org/v6/api/config/use_long_long/"); "https://arduinojson.org/v6/api/config/use_long_long/");
#else #else
#define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T) # define ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T)
#endif #endif

View File

@@ -5,13 +5,13 @@
#pragma once #pragma once
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push # pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion" # pragma clang diagnostic ignored "-Wconversion"
#elif defined(__GNUC__) #elif defined(__GNUC__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic push # pragma GCC diagnostic push
#endif # endif
#pragma GCC diagnostic ignored "-Wconversion" # pragma GCC diagnostic ignored "-Wconversion"
#endif #endif
#include <ArduinoJson/Numbers/Float.hpp> #include <ArduinoJson/Numbers/Float.hpp>
@@ -71,9 +71,23 @@ canConvertNumber(TIn) {
} }
// int32 -> uint32 // int32 -> uint32
// int32 -> uint64
template <typename TOut, typename TIn> template <typename TOut, typename TIn>
typename enable_if<is_integral<TIn>::value && is_signed<TIn>::value && typename enable_if<is_integral<TIn>::value && is_signed<TIn>::value &&
is_integral<TOut>::value && is_unsigned<TOut>::value, is_integral<TOut>::value && is_unsigned<TOut>::value &&
sizeof(TOut) >= sizeof(TIn),
bool>::type
canConvertNumber(TIn value) {
if (value < 0)
return false;
return TOut(value) <= numeric_limits<TOut>::highest();
}
// int32 -> uint16
template <typename TOut, typename TIn>
typename enable_if<is_integral<TIn>::value && is_signed<TIn>::value &&
is_integral<TOut>::value && is_unsigned<TOut>::value &&
sizeof(TOut) < sizeof(TIn),
bool>::type bool>::type
canConvertNumber(TIn value) { canConvertNumber(TIn value) {
if (value < 0) if (value < 0)
@@ -99,9 +113,9 @@ TOut convertNumber(TIn value) {
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic pop # pragma clang diagnostic pop
#elif defined(__GNUC__) #elif defined(__GNUC__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif # endif
#endif #endif

View File

@@ -12,8 +12,8 @@
#include <ArduinoJson/Variant/VariantTo.hpp> #include <ArduinoJson/Variant/VariantTo.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
#pragma warning(disable : 4522) # pragma warning(disable : 4522)
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -187,8 +187,8 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
return _object.getOrAddMember(_key); return _object.getOrAddMember(_key);
} }
friend bool convertToJson(const this_type &src, VariantRef dst) { friend void convertToJson(const this_type &src, VariantRef dst) {
return dst.set(src.getUpstreamMember()); dst.set(src.getUpstreamMember());
} }
TObject _object; TObject _object;
@@ -198,5 +198,5 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif

View File

@@ -239,8 +239,8 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
template <> template <>
struct Converter<ObjectConstRef> { struct Converter<ObjectConstRef> {
static bool toJson(VariantConstRef src, VariantRef dst) { static void toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst)); variantCopyFrom(getData(dst), getData(src), getPool(dst));
} }
static ObjectConstRef fromJson(VariantConstRef src) { static ObjectConstRef fromJson(VariantConstRef src) {
@@ -255,8 +255,8 @@ struct Converter<ObjectConstRef> {
template <> template <>
struct Converter<ObjectRef> { struct Converter<ObjectRef> {
static bool toJson(VariantConstRef src, VariantRef dst) { static void toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst)); variantCopyFrom(getData(dst), getData(src), getPool(dst));
} }
static ObjectRef fromJson(VariantRef src) { static ObjectRef fromJson(VariantRef src) {
@@ -265,6 +265,9 @@ struct Converter<ObjectRef> {
return ObjectRef(pool, data != 0 ? data->asObject() : 0); return ObjectRef(pool, data != 0 ? data->asObject() : 0);
} }
static InvalidConversion<VariantConstRef, ObjectRef> fromJson(
VariantConstRef);
static bool checkJson(VariantConstRef) { static bool checkJson(VariantConstRef) {
return false; return false;
} }

View File

@@ -7,8 +7,8 @@
#include <ArduinoJson/Configuration.hpp> #include <ArduinoJson/Configuration.hpp>
#if ARDUINOJSON_DEBUG #if ARDUINOJSON_DEBUG
#include <assert.h> # include <assert.h>
#define ARDUINOJSON_ASSERT(X) assert(X) # define ARDUINOJSON_ASSERT(X) assert(X)
#else #else
#define ARDUINOJSON_ASSERT(X) ((void)0) # define ARDUINOJSON_ASSERT(X) ((void)0)
#endif #endif

View File

@@ -6,49 +6,49 @@
#ifdef _MSC_VER // Visual Studio #ifdef _MSC_VER // Visual Studio
#define FORCE_INLINE // __forceinline causes C4714 when returning std::string # define FORCE_INLINE // __forceinline causes C4714 when returning std::string
#define NO_INLINE __declspec(noinline) # define NO_INLINE __declspec(noinline)
#ifndef ARDUINOJSON_DEPRECATED # ifndef ARDUINOJSON_DEPRECATED
#define ARDUINOJSON_DEPRECATED(msg) __declspec(deprecated(msg)) # define ARDUINOJSON_DEPRECATED(msg) __declspec(deprecated(msg))
#endif # endif
#elif defined(__GNUC__) // GCC or Clang #elif defined(__GNUC__) // GCC or Clang
#define FORCE_INLINE __attribute__((always_inline)) # define FORCE_INLINE __attribute__((always_inline))
#define NO_INLINE __attribute__((noinline)) # define NO_INLINE __attribute__((noinline))
#ifndef ARDUINOJSON_DEPRECATED # ifndef ARDUINOJSON_DEPRECATED
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated(msg))) # define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated(msg)))
#else # else
#define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated)) # define ARDUINOJSON_DEPRECATED(msg) __attribute__((deprecated))
#endif # endif
#endif # endif
#else // Other compilers #else // Other compilers
#define FORCE_INLINE # define FORCE_INLINE
#define NO_INLINE # define NO_INLINE
#ifndef ARDUINOJSON_DEPRECATED # ifndef ARDUINOJSON_DEPRECATED
#define ARDUINOJSON_DEPRECATED(msg) # define ARDUINOJSON_DEPRECATED(msg)
#endif # endif
#endif #endif
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#define NOEXCEPT noexcept # define NOEXCEPT noexcept
#else #else
#define NOEXCEPT throw() # define NOEXCEPT throw()
#endif #endif
#if defined(__has_attribute) #if defined(__has_attribute)
#if __has_attribute(no_sanitize) # if __has_attribute(no_sanitize)
#define ARDUINOJSON_NO_SANITIZE(check) __attribute__((no_sanitize(check))) # define ARDUINOJSON_NO_SANITIZE(check) __attribute__((no_sanitize(check)))
# else
# define ARDUINOJSON_NO_SANITIZE(check)
# endif
#else #else
#define ARDUINOJSON_NO_SANITIZE(check) # define ARDUINOJSON_NO_SANITIZE(check)
#endif
#else
#define ARDUINOJSON_NO_SANITIZE(check)
#endif #endif

View File

@@ -7,8 +7,8 @@
#include "type_traits.hpp" #include "type_traits.hpp"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
#pragma warning(disable : 4310) # pragma warning(disable : 4310)
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -41,5 +41,5 @@ struct numeric_limits<
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif

View File

@@ -8,27 +8,27 @@
#if ARDUINOJSON_ENABLE_PROGMEM #if ARDUINOJSON_ENABLE_PROGMEM
#include <ArduinoJson/Polyfills/pgmspace_generic.hpp> # include <ArduinoJson/Polyfills/pgmspace_generic.hpp>
#ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY # ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY
#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \ # define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
static type const name[] PROGMEM = value; static type const name[] PROGMEM = value;
#endif # endif
#ifndef ARDUINOJSON_READ_STATIC_ARRAY # ifndef ARDUINOJSON_READ_STATIC_ARRAY
#define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) \ # define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) \
pgm_read<type>(name + index) pgm_read<type>(name + index)
#endif # endif
#else // i.e. ARDUINOJSON_ENABLE_PROGMEM == 0 #else // i.e. ARDUINOJSON_ENABLE_PROGMEM == 0
#ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY # ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY
#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \ # define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
static type const name[] = value; static type const name[] = value;
#endif # endif
#ifndef ARDUINOJSON_READ_STATIC_ARRAY # ifndef ARDUINOJSON_READ_STATIC_ARRAY
#define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) name[index] # define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) name[index]
#endif # endif
#endif #endif

View File

@@ -20,5 +20,6 @@
#include "type_traits/is_signed.hpp" #include "type_traits/is_signed.hpp"
#include "type_traits/is_unsigned.hpp" #include "type_traits/is_unsigned.hpp"
#include "type_traits/make_unsigned.hpp" #include "type_traits/make_unsigned.hpp"
#include "type_traits/make_void.hpp"
#include "type_traits/remove_const.hpp" #include "type_traits/remove_const.hpp"
#include "type_traits/remove_reference.hpp" #include "type_traits/remove_reference.hpp"

View File

@@ -7,9 +7,9 @@
#include "declval.hpp" #include "declval.hpp"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
// conversion from 'T' to 'To', possible loss of data // conversion from 'T' to 'To', possible loss of data
#pragma warning(disable : 4244) # pragma warning(disable : 4244)
#endif #endif
// clang-format off // clang-format off
@@ -37,7 +37,7 @@ struct is_convertible {
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif
// clang-format off // clang-format off

View File

@@ -5,15 +5,16 @@
#pragma once #pragma once
#include "integral_constant.hpp" #include "integral_constant.hpp"
#include "is_same.hpp"
#include "remove_cv.hpp"
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
template <typename> template <class T>
struct is_floating_point : false_type {}; struct is_floating_point
: integral_constant<
bool, //
is_same<float, typename remove_cv<T>::type>::value ||
is_same<double, typename remove_cv<T>::type>::value> {};
template <>
struct is_floating_point<float> : true_type {};
template <>
struct is_floating_point<double> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -5,29 +5,33 @@
#pragma once #pragma once
#include <ArduinoJson/Configuration.hpp> #include <ArduinoJson/Configuration.hpp>
#include "integral_constant.hpp"
#include "is_same.hpp" #include "is_same.hpp"
#include "remove_cv.hpp"
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
// A meta-function that returns true if T is an integral type. // clang-format off
template <typename T> template <typename T>
struct is_integral { struct is_integral : integral_constant<bool,
static const bool value = is_same<typename remove_cv<T>::type, signed char>::value ||
is_same<T, signed char>::value || is_same<T, unsigned char>::value || is_same<typename remove_cv<T>::type, unsigned char>::value ||
is_same<T, signed short>::value || is_same<T, unsigned short>::value || is_same<typename remove_cv<T>::type, signed short>::value ||
is_same<T, signed int>::value || is_same<T, unsigned int>::value || is_same<typename remove_cv<T>::type, unsigned short>::value ||
is_same<T, signed long>::value || is_same<T, unsigned long>::value || is_same<typename remove_cv<T>::type, signed int>::value ||
is_same<typename remove_cv<T>::type, unsigned int>::value ||
is_same<typename remove_cv<T>::type, signed long>::value ||
is_same<typename remove_cv<T>::type, unsigned long>::value ||
#if ARDUINOJSON_HAS_LONG_LONG #if ARDUINOJSON_HAS_LONG_LONG
is_same<T, signed long long>::value || is_same<typename remove_cv<T>::type, signed long long>::value ||
is_same<T, unsigned long long>::value || is_same<typename remove_cv<T>::type, unsigned long long>::value ||
#endif #endif
#if ARDUINOJSON_HAS_INT64 #if ARDUINOJSON_HAS_INT64
is_same<T, signed __int64>::value || is_same<typename remove_cv<T>::type, signed __int64>::value ||
is_same<T, unsigned __int64>::value || is_same<typename remove_cv<T>::type, unsigned __int64>::value ||
#endif #endif
is_same<T, char>::value || is_same<T, bool>::value; is_same<typename remove_cv<T>::type, char>::value ||
}; is_same<typename remove_cv<T>::type, bool>::value> {};
// clang-format on
template <typename T>
struct is_integral<const T> : is_integral<T> {};
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -5,39 +5,26 @@
#pragma once #pragma once
#include "integral_constant.hpp" #include "integral_constant.hpp"
#include "is_same.hpp"
#include "remove_cv.hpp"
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
template <typename> // clang-format off
struct is_signed : false_type {}; template <typename T>
struct is_signed : integral_constant<bool,
template <> is_same<typename remove_cv<T>::type, char>::value ||
struct is_signed<char> : true_type {}; is_same<typename remove_cv<T>::type, signed char>::value ||
is_same<typename remove_cv<T>::type, signed short>::value ||
template <> is_same<typename remove_cv<T>::type, signed int>::value ||
struct is_signed<signed char> : true_type {}; is_same<typename remove_cv<T>::type, signed long>::value ||
template <>
struct is_signed<signed short> : true_type {};
template <>
struct is_signed<signed int> : true_type {};
template <>
struct is_signed<signed long> : true_type {};
template <>
struct is_signed<float> : true_type {};
template <>
struct is_signed<double> : true_type {};
#if ARDUINOJSON_HAS_LONG_LONG #if ARDUINOJSON_HAS_LONG_LONG
template <> is_same<typename remove_cv<T>::type, signed long long>::value ||
struct is_signed<signed long long> : true_type {};
#endif #endif
#if ARDUINOJSON_HAS_INT64 #if ARDUINOJSON_HAS_INT64
template <> is_same<typename remove_cv<T>::type, signed __int64>::value ||
struct is_signed<signed __int64> : true_type {};
#endif #endif
is_same<typename remove_cv<T>::type, float>::value ||
is_same<typename remove_cv<T>::type, double>::value> {};
// clang-format on
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -5,33 +5,24 @@
#pragma once #pragma once
#include "integral_constant.hpp" #include "integral_constant.hpp"
#include "is_same.hpp"
#include "remove_cv.hpp"
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
template <typename> // clang-format off
struct is_unsigned : false_type {}; template <typename T>
struct is_unsigned : integral_constant<bool,
template <> is_same<typename remove_cv<T>::type, unsigned char>::value ||
struct is_unsigned<bool> : true_type {}; is_same<typename remove_cv<T>::type, unsigned short>::value ||
is_same<typename remove_cv<T>::type, unsigned int>::value ||
template <> is_same<typename remove_cv<T>::type, unsigned long>::value ||
struct is_unsigned<unsigned char> : true_type {};
template <>
struct is_unsigned<unsigned short> : true_type {};
template <>
struct is_unsigned<unsigned int> : true_type {};
template <>
struct is_unsigned<unsigned long> : true_type {};
#if ARDUINOJSON_HAS_INT64 #if ARDUINOJSON_HAS_INT64
template <> is_same<typename remove_cv<T>::type, unsigned __int64>::value ||
struct is_unsigned<unsigned __int64> : true_type {};
#endif #endif
#if ARDUINOJSON_HAS_LONG_LONG #if ARDUINOJSON_HAS_LONG_LONG
template <> is_same<typename remove_cv<T>::type, unsigned long long>::value ||
struct is_unsigned<unsigned long long> : true_type {};
#endif #endif
is_same<typename remove_cv<T>::type, bool>::value> {};
// clang-format on
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -0,0 +1,14 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
namespace ARDUINOJSON_NAMESPACE {
template <class = void>
struct make_void {
typedef void type;
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -0,0 +1,27 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename T>
struct remove_cv {
typedef T type;
};
template <typename T>
struct remove_cv<const T> {
typedef T type;
};
template <typename T>
struct remove_cv<volatile T> {
typedef T type;
};
template <typename T>
struct remove_cv<const volatile T> {
typedef T type;
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -31,17 +31,17 @@ class Writer {
#include <ArduinoJson/Serialization/Writers/StaticStringWriter.hpp> #include <ArduinoJson/Serialization/Writers/StaticStringWriter.hpp>
#if ARDUINOJSON_ENABLE_STD_STRING #if ARDUINOJSON_ENABLE_STD_STRING
#include <ArduinoJson/Serialization/Writers/StdStringWriter.hpp> # include <ArduinoJson/Serialization/Writers/StdStringWriter.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_ARDUINO_STRING #if ARDUINOJSON_ENABLE_ARDUINO_STRING
#include <ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp> # include <ArduinoJson/Serialization/Writers/ArduinoStringWriter.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_STD_STREAM #if ARDUINOJSON_ENABLE_STD_STREAM
#include <ArduinoJson/Serialization/Writers/StdStreamWriter.hpp> # include <ArduinoJson/Serialization/Writers/StdStreamWriter.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_ARDUINO_PRINT #if ARDUINOJSON_ENABLE_ARDUINO_PRINT
#include <ArduinoJson/Serialization/Writers/PrintWriter.hpp> # include <ArduinoJson/Serialization/Writers/PrintWriter.hpp>
#endif #endif

View File

@@ -22,10 +22,10 @@ class Writer< ::String, void> {
} }
size_t write(uint8_t c) { size_t write(uint8_t c) {
ARDUINOJSON_ASSERT(_size < bufferCapacity);
_buffer[_size++] = static_cast<char>(c);
if (_size + 1 >= bufferCapacity) if (_size + 1 >= bufferCapacity)
flush(); if (flush() != 0)
return 0;
_buffer[_size++] = static_cast<char>(c);
return 1; return 1;
} }
@@ -36,14 +36,15 @@ class Writer< ::String, void> {
return n; return n;
} }
private: size_t flush() {
void flush() {
ARDUINOJSON_ASSERT(_size < bufferCapacity); ARDUINOJSON_ASSERT(_size < bufferCapacity);
_buffer[_size] = 0; _buffer[_size] = 0;
*_destination += _buffer; if (_destination->concat(_buffer))
_size = 0; _size = 0;
return _size;
} }
private:
::String *_destination; ::String *_destination;
char _buffer[bufferCapacity]; char _buffer[bufferCapacity];
size_t _size; size_t _size;

View File

@@ -55,8 +55,12 @@ class StringCopier {
private: private:
MemoryPool* _pool; MemoryPool* _pool;
// These fields aren't initialized by the constructor but startString()
//
// NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
char* _ptr; char* _ptr;
size_t _size; // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject)
size_t _capacity; size_t _size, _capacity;
}; };
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -7,14 +7,15 @@
#include <Arduino.h> #include <Arduino.h>
#include <ArduinoJson/Polyfills/safe_strcmp.hpp> #include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp> #include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
class ArduinoStringAdapter { template <>
class StringAdapter< ::String> {
public: public:
ArduinoStringAdapter(const ::String& str) : _str(&str) {} StringAdapter(const ::String& str) : _str(&str) {}
void copyTo(char* p, size_t n) const { void copyTo(char* p, size_t n) const {
memcpy(p, _str->c_str(), n); memcpy(p, _str->c_str(), n);
@@ -31,18 +32,10 @@ class ArduinoStringAdapter {
return safe_strcmp(me, other); return safe_strcmp(me, other);
} }
bool equals(const char* expected) const {
return compare(expected) == 0;
}
size_t size() const { size_t size() const {
return _str->length(); return _str->length();
} }
const char* begin() const {
return _str->c_str();
}
typedef storage_policies::store_by_copy storage_policy; typedef storage_policies::store_by_copy storage_policy;
private: private:
@@ -50,13 +43,10 @@ class ArduinoStringAdapter {
}; };
template <> template <>
struct IsString< ::String> : true_type {}; class StringAdapter< ::StringSumHelper> : public StringAdapter< ::String> {
public:
template <> StringAdapter< ::StringSumHelper>(const ::String& s)
struct IsString< ::StringSumHelper> : true_type {}; : StringAdapter< ::String>(s) {}
};
inline ArduinoStringAdapter adaptString(const ::String& str) {
return ArduinoStringAdapter(str);
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -8,23 +8,20 @@
#include <string.h> // strcmp #include <string.h> // strcmp
#include <ArduinoJson/Polyfills/safe_strcmp.hpp> #include <ArduinoJson/Polyfills/safe_strcmp.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp> #include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
class ConstRamStringAdapter { template <>
class StringAdapter<const char*> {
public: public:
ConstRamStringAdapter(const char* str = 0) : _str(str) {} StringAdapter(const char* str = 0) : _str(str) {}
int compare(const char* other) const { int compare(const char* other) const {
return safe_strcmp(_str, other); return safe_strcmp(_str, other);
} }
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const { bool isNull() const {
return !_str; return !_str;
} }
@@ -39,24 +36,16 @@ class ConstRamStringAdapter {
return _str; return _str;
} }
const char* begin() const {
return _str;
}
typedef storage_policies::store_by_address storage_policy; typedef storage_policies::store_by_address storage_policy;
protected: protected:
const char* _str; const char* _str;
}; };
template <>
struct IsString<const char*> : true_type {};
template <int N> template <int N>
struct IsString<const char[N]> : true_type {}; class StringAdapter<const char[N]> : public StringAdapter<const char*> {
public:
inline ConstRamStringAdapter adaptString(const char* str) { StringAdapter<const char[N]>(const char* s) : StringAdapter<const char*>(s) {}
return ConstRamStringAdapter(str); };
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -5,15 +5,15 @@
#pragma once #pragma once
#include <ArduinoJson/Polyfills/pgmspace.hpp> #include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Strings/FlashStringIterator.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp> #include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
class FlashStringAdapter { template <>
class StringAdapter<const __FlashStringHelper*> {
public: public:
FlashStringAdapter(const __FlashStringHelper* str) : _str(str) {} StringAdapter(const __FlashStringHelper* str) : _str(str) {}
int compare(const char* other) const { int compare(const char* other) const {
if (!other && !_str) if (!other && !_str)
@@ -25,10 +25,6 @@ class FlashStringAdapter {
return -strcmp_P(other, reinterpret_cast<const char*>(_str)); return -strcmp_P(other, reinterpret_cast<const char*>(_str));
} }
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const { bool isNull() const {
return !_str; return !_str;
} }
@@ -43,20 +39,10 @@ class FlashStringAdapter {
return strlen_P(reinterpret_cast<const char*>(_str)); return strlen_P(reinterpret_cast<const char*>(_str));
} }
FlashStringIterator begin() const {
return FlashStringIterator(_str);
}
typedef storage_policies::store_by_copy storage_policy; typedef storage_policies::store_by_copy storage_policy;
private: private:
const __FlashStringHelper* _str; const __FlashStringHelper* _str;
}; };
inline FlashStringAdapter adaptString(const __FlashStringHelper* str) {
return FlashStringAdapter(str);
}
template <>
struct IsString<const __FlashStringHelper*> : true_type {};
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -0,0 +1,27 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
#include <ArduinoJson/Strings/String.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<String> : public StringAdapter<char*> {
public:
StringAdapter(const String& str)
: StringAdapter<char*>(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

View File

@@ -0,0 +1,29 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename TChar>
class StringAdapter<TChar*, false,
typename enable_if<sizeof(TChar) == 1 &&
!is_same<TChar, void>::value>::type>
: public StringAdapter<const char*> {
public:
StringAdapter(const TChar* str)
: StringAdapter<const char*>(reinterpret_cast<const char*>(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

View File

@@ -5,15 +5,15 @@
#pragma once #pragma once
#include <ArduinoJson/Namespace.hpp> #include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/FlashStringIterator.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp> #include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
class SizedFlashStringAdapter { template <>
class StringAdapter<const __FlashStringHelper*, true> {
public: public:
SizedFlashStringAdapter(const __FlashStringHelper* str, size_t sz) StringAdapter(const __FlashStringHelper* str, size_t sz)
: _str(str), _size(sz) {} : _str(str), _size(sz) {}
int compare(const char* other) const { int compare(const char* other) const {
@@ -26,10 +26,6 @@ class SizedFlashStringAdapter {
return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size); return -strncmp_P(other, reinterpret_cast<const char*>(_str), _size);
} }
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const { bool isNull() const {
return !_str; return !_str;
} }
@@ -42,10 +38,6 @@ class SizedFlashStringAdapter {
return _size; return _size;
} }
FlashStringIterator begin() const {
return FlashStringIterator(_str);
}
typedef storage_policies::store_by_copy storage_policy; typedef storage_policies::store_by_copy storage_policy;
private: private:
@@ -53,8 +45,4 @@ class SizedFlashStringAdapter {
size_t _size; size_t _size;
}; };
inline SizedFlashStringAdapter adaptString(const __FlashStringHelper* str,
size_t sz) {
return SizedFlashStringAdapter(str, sz);
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -5,25 +5,22 @@
#pragma once #pragma once
#include <ArduinoJson/Namespace.hpp> #include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp> #include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
#include <string.h> // strcmp #include <string.h> // strcmp
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
class SizedRamStringAdapter { template <typename TChar>
class StringAdapter<TChar*, true> {
public: 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 { int compare(const char* other) const {
return safe_strncmp(_str, other, _size); return safe_strncmp(_str, other, _size);
} }
bool equals(const char* expected) const {
return compare(expected) == 0;
}
bool isNull() const { bool isNull() const {
return !_str; return !_str;
} }
@@ -36,10 +33,6 @@ class SizedRamStringAdapter {
return _size; return _size;
} }
const char* begin() const {
return _str;
}
typedef storage_policies::store_by_copy storage_policy; typedef storage_policies::store_by_copy storage_policy;
private: private:
@@ -47,9 +40,4 @@ class SizedRamStringAdapter {
size_t _size; size_t _size;
}; };
template <typename TChar>
inline SizedRamStringAdapter adaptString(const TChar* str, size_t size) {
return SizedRamStringAdapter(reinterpret_cast<const char*>(str), size);
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -0,0 +1,46 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
#include <string>
namespace ARDUINOJSON_NAMESPACE {
template <typename TCharTraits, typename TAllocator>
class StringAdapter<std::basic_string<char, TCharTraits, TAllocator> > {
public:
typedef std::basic_string<char, TCharTraits, TAllocator> 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

View File

@@ -0,0 +1,44 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapter.hpp>
#include <string_view>
namespace ARDUINOJSON_NAMESPACE {
template <>
class StringAdapter<std::string_view> {
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

View File

@@ -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<const char*>(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

View File

@@ -1,18 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename>
struct IsString : false_type {};
template <typename T>
struct IsString<const T> : IsString<T> {};
template <typename T>
struct IsString<T&> : IsString<T> {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -8,11 +8,11 @@
#include <ArduinoJson/Polyfills/type_traits.hpp> #include <ArduinoJson/Polyfills/type_traits.hpp>
#if ARDUINOJSON_ENABLE_ARDUINO_STRING #if ARDUINOJSON_ENABLE_ARDUINO_STRING
#include <Arduino.h> # include <Arduino.h>
#endif #endif
#if ARDUINOJSON_ENABLE_STD_STRING #if ARDUINOJSON_ENABLE_STD_STRING
#include <string> # include <string>
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {

View File

@@ -1,43 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
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 <typename TChar>
inline RamStringAdapter adaptString(const TChar* str) {
return RamStringAdapter(reinterpret_cast<const char*>(str));
}
inline RamStringAdapter adaptString(char* str) {
return RamStringAdapter(str);
}
template <typename TChar>
struct IsString<TChar*> {
static const bool value = sizeof(TChar) == 1;
};
template <>
struct IsString<void*> {
static const bool value = false;
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,65 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <string>
namespace ARDUINOJSON_NAMESPACE {
template <typename TString>
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 <typename TCharTraits, typename TAllocator>
struct IsString<std::basic_string<char, TCharTraits, TAllocator> > : true_type {
};
template <typename TCharTraits, typename TAllocator>
inline StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >
adaptString(const std::basic_string<char, TCharTraits, TAllocator>& str) {
return StdStringAdapter<std::basic_string<char, TCharTraits, TAllocator> >(
str);
}
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -4,10 +4,6 @@
#pragma once #pragma once
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/IsString.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
class String { class String {
@@ -53,25 +49,4 @@ class String {
bool _isStatic; 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<String> : true_type {};
inline StringAdapter adaptString(const String& str) {
return StringAdapter(str);
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -0,0 +1,32 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename T, bool bounded = false, typename Enable = void>
class StringAdapter;
template <typename T>
inline StringAdapter<T, false> adaptString(const T& str) {
return StringAdapter<T, false>(str);
}
template <typename T>
inline StringAdapter<T, true> adaptString(const T& str, size_t sz) {
return StringAdapter<T, true>(str, sz);
}
template <typename T, typename Enable = void>
struct IsString : false_type {};
template <typename T>
struct IsString<
T, typename make_void<typename StringAdapter<T>::storage_policy>::type>
: true_type {};
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -4,19 +4,24 @@
#pragma once #pragma once
#include <ArduinoJson/Strings/ConstRamStringAdapter.hpp> #include <ArduinoJson/Strings/Adapters/ConstRamStringAdapter.hpp>
#include <ArduinoJson/Strings/RamStringAdapter.hpp> #include <ArduinoJson/Strings/Adapters/JsonStringAdapter.hpp>
#include <ArduinoJson/Strings/SizedRamStringAdapter.hpp> #include <ArduinoJson/Strings/Adapters/RamStringAdapter.hpp>
#include <ArduinoJson/Strings/Adapters/SizedRamStringAdapter.hpp>
#if ARDUINOJSON_ENABLE_STD_STRING #if ARDUINOJSON_ENABLE_STD_STRING
#include <ArduinoJson/Strings/StdStringAdapter.hpp> # include <ArduinoJson/Strings/Adapters/StdStringAdapter.hpp>
#endif
#if ARDUINOJSON_ENABLE_STRING_VIEW
# include <ArduinoJson/Strings/Adapters/StringViewAdapter.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_ARDUINO_STRING #if ARDUINOJSON_ENABLE_ARDUINO_STRING
#include <ArduinoJson/Strings/ArduinoStringAdapter.hpp> # include <ArduinoJson/Strings/Adapters/ArduinoStringAdapter.hpp>
#endif #endif
#if ARDUINOJSON_ENABLE_PROGMEM #if ARDUINOJSON_ENABLE_PROGMEM
#include <ArduinoJson/Strings/FlashStringAdapter.hpp> # include <ArduinoJson/Strings/Adapters/FlashStringAdapter.hpp>
#include <ArduinoJson/Strings/SizedFlashStringAdapter.hpp> # include <ArduinoJson/Strings/Adapters/SizedFlashStringAdapter.hpp>
#endif #endif

View File

@@ -9,4 +9,9 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename T, typename Enable = void> template <typename T, typename Enable = void>
struct Converter; struct Converter;
// clang-format off
template <typename T1, typename T2>
class InvalidConversion; // Error here? See https://arduinojson.org/v6/invalid-conversion/
// clang-format on
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -12,9 +12,9 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename T, typename Enable> template <typename T, typename Enable>
struct Converter { struct Converter {
static bool toJson(const T& src, VariantRef dst) { static void toJson(const T& src, VariantRef dst) {
// clang-format off // 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 // clang-format on
} }
@@ -38,13 +38,11 @@ template <typename T>
struct Converter< struct Converter<
T, typename enable_if<is_integral<T>::value && !is_same<bool, T>::value && T, typename enable_if<is_integral<T>::value && !is_same<bool, T>::value &&
!is_same<char, T>::value>::type> { !is_same<char, T>::value>::type> {
static bool toJson(T src, VariantRef dst) { static void toJson(T src, VariantRef dst) {
VariantData* data = getData(dst); VariantData* data = getData(dst);
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T); ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(T);
if (!data) if (data)
return false; data->setInteger(src);
data->setInteger(src);
return true;
} }
static T fromJson(VariantConstRef src) { static T fromJson(VariantConstRef src) {
@@ -61,8 +59,8 @@ struct Converter<
template <typename T> template <typename T>
struct Converter<T, typename enable_if<is_enum<T>::value>::type> { struct Converter<T, typename enable_if<is_enum<T>::value>::type> {
static bool toJson(T src, VariantRef dst) { static void toJson(T src, VariantRef dst) {
return dst.set(static_cast<Integer>(src)); dst.set(static_cast<Integer>(src));
} }
static T fromJson(VariantConstRef src) { static T fromJson(VariantConstRef src) {
@@ -78,12 +76,10 @@ struct Converter<T, typename enable_if<is_enum<T>::value>::type> {
template <> template <>
struct Converter<bool> { struct Converter<bool> {
static bool toJson(bool src, VariantRef dst) { static void toJson(bool src, VariantRef dst) {
VariantData* data = getData(dst); VariantData* data = getData(dst);
if (!data) if (data)
return false; data->setBoolean(src);
data->setBoolean(src);
return true;
} }
static bool fromJson(VariantConstRef src) { static bool fromJson(VariantConstRef src) {
@@ -99,12 +95,10 @@ struct Converter<bool> {
template <typename T> template <typename T>
struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> { struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> {
static bool toJson(T src, VariantRef dst) { static void toJson(T src, VariantRef dst) {
VariantData* data = getData(dst); VariantData* data = getData(dst);
if (!data) if (data)
return false; data->setFloat(static_cast<Float>(src));
data->setFloat(static_cast<Float>(src));
return true;
} }
static T fromJson(VariantConstRef src) { static T fromJson(VariantConstRef src) {
@@ -120,8 +114,8 @@ struct Converter<T, typename enable_if<is_floating_point<T>::value>::type> {
template <> template <>
struct Converter<const char*> { struct Converter<const char*> {
static bool toJson(const char* src, VariantRef dst) { static void toJson(const char* src, VariantRef dst) {
return variantSetString(getData(dst), adaptString(src), getPool(dst)); variantSetString(getData(dst), adaptString(src), getPool(dst));
} }
static const char* fromJson(VariantConstRef src) { static const char* fromJson(VariantConstRef src) {
@@ -163,12 +157,10 @@ canConvertFromJson(VariantConstRef src, const T&) {
template <> template <>
struct Converter<SerializedValue<const char*> > { struct Converter<SerializedValue<const char*> > {
static bool toJson(SerializedValue<const char*> src, VariantRef dst) { static void toJson(SerializedValue<const char*> src, VariantRef dst) {
VariantData* data = getData(dst); VariantData* data = getData(dst);
if (!data) if (data)
return false; data->setLinkedRaw(src);
data->setLinkedRaw(src);
return true;
} }
}; };
@@ -178,10 +170,11 @@ struct Converter<SerializedValue<const char*> > {
template <typename T> template <typename T>
struct Converter<SerializedValue<T>, struct Converter<SerializedValue<T>,
typename enable_if<!is_same<const char*, T>::value>::type> { typename enable_if<!is_same<const char*, T>::value>::type> {
static bool toJson(SerializedValue<T> src, VariantRef dst) { static void toJson(SerializedValue<T> src, VariantRef dst) {
VariantData* data = getData(dst); VariantData* data = getData(dst);
MemoryPool* pool = getPool(dst); MemoryPool* pool = getPool(dst);
return data != 0 && data->setOwnedRaw(src, pool); if (data)
data->setOwnedRaw(src, pool);
} }
}; };
@@ -189,9 +182,8 @@ struct Converter<SerializedValue<T>,
template <> template <>
struct Converter<decltype(nullptr)> { struct Converter<decltype(nullptr)> {
static bool toJson(decltype(nullptr), VariantRef dst) { static void toJson(decltype(nullptr), VariantRef dst) {
variantSetNull(getData(dst)); variantSetNull(getData(dst));
return true;
} }
static decltype(nullptr) fromJson(VariantConstRef) { static decltype(nullptr) fromJson(VariantConstRef) {
return nullptr; return nullptr;
@@ -247,20 +239,33 @@ class MemoryPoolPrint : public Print {
size_t _capacity; size_t _capacity;
}; };
inline bool convertToJson(const ::Printable& src, VariantRef dst) { inline void convertToJson(const ::Printable& src, VariantRef dst) {
MemoryPool* pool = getPool(dst); MemoryPool* pool = getPool(dst);
VariantData* data = getData(dst); VariantData* data = getData(dst);
if (!pool || !data) if (!pool || !data)
return false; return;
MemoryPoolPrint print(pool); MemoryPoolPrint print(pool);
src.printTo(print); src.printTo(print);
if (print.overflowed()) { if (print.overflowed()) {
pool->markAsOverflowed(); pool->markAsOverflowed();
data->setNull(); data->setNull();
return false; return;
} }
data->setStringPointer(print.c_str(), storage_policies::store_by_copy()); 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<const char*>();
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<const char*>();
} }
#endif #endif

View File

@@ -8,7 +8,7 @@
#include <ArduinoJson/Misc/Visitable.hpp> #include <ArduinoJson/Misc/Visitable.hpp>
#include <ArduinoJson/Numbers/arithmeticCompare.hpp> #include <ArduinoJson/Numbers/arithmeticCompare.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp> #include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Strings/IsString.hpp> #include <ArduinoJson/Strings/StringAdapter.hpp>
#include <ArduinoJson/Variant/Visitor.hpp> #include <ArduinoJson/Variant/Visitor.hpp>
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {

View File

@@ -7,17 +7,17 @@
#include <ArduinoJson/Memory/MemoryPool.hpp> #include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Misc/SerializedValue.hpp> #include <ArduinoJson/Misc/SerializedValue.hpp>
#include <ArduinoJson/Numbers/convertNumber.hpp> #include <ArduinoJson/Numbers/convertNumber.hpp>
#include <ArduinoJson/Strings/RamStringAdapter.hpp> #include <ArduinoJson/Strings/StringAdapters.hpp>
#include <ArduinoJson/Variant/VariantContent.hpp> #include <ArduinoJson/Variant/VariantContent.hpp>
// VariantData can't have a constructor (to be a POD), so we have no way to fix // VariantData can't have a constructor (to be a POD), so we have no way to fix
// this warning // this warning
#if defined(__GNUC__) #if defined(__GNUC__)
#if __GNUC__ >= 7 # if __GNUC__ >= 7
#pragma GCC diagnostic push # pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wuninitialized" # pragma GCC diagnostic ignored "-Wuninitialized"
#endif # endif
#endif #endif
namespace ARDUINOJSON_NAMESPACE { namespace ARDUINOJSON_NAMESPACE {
@@ -33,7 +33,7 @@ class VariantData {
// - no virtual // - no virtual
// - no inheritance // - no inheritance
void init() { void init() {
_flags = 0; _flags = VALUE_IS_NULL;
} }
template <typename TVisitor> template <typename TVisitor>
@@ -103,7 +103,8 @@ class VariantData {
case VALUE_IS_OBJECT: case VALUE_IS_OBJECT:
return toObject().copyFrom(src._content.asCollection, pool); return toObject().copyFrom(src._content.asCollection, pool);
case VALUE_IS_OWNED_STRING: case VALUE_IS_OWNED_STRING:
return setString(RamStringAdapter(src._content.asString), pool); return setString(adaptString(const_cast<char *>(src._content.asString)),
pool);
case VALUE_IS_OWNED_RAW: case VALUE_IS_OWNED_RAW:
return setOwnedRaw( return setOwnedRaw(
serialized(src._content.asRaw.data, src._content.asRaw.size), pool); serialized(src._content.asRaw.data, src._content.asRaw.size), pool);
@@ -362,7 +363,7 @@ class VariantData {
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE
#if defined(__GNUC__) #if defined(__GNUC__)
#if __GNUC__ >= 8 # if __GNUC__ >= 8
#pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif # endif
#endif #endif

View File

@@ -140,4 +140,9 @@ inline VariantConstRef operator|(VariantConstRef preferedValue,
VariantConstRef defaultValue) { VariantConstRef defaultValue) {
return preferedValue ? preferedValue : defaultValue; return preferedValue ? preferedValue : defaultValue;
} }
// Out of class definition to avoid #1560
inline bool VariantRef::set(char value) const {
return set<signed char>(value);
}
} // namespace ARDUINOJSON_NAMESPACE } // namespace ARDUINOJSON_NAMESPACE

View File

@@ -85,18 +85,18 @@ class VariantRef : public VariantRefBase<VariantData>,
template <typename T> template <typename T>
FORCE_INLINE bool set(const T &value) const { FORCE_INLINE bool set(const T &value) const {
return Converter<T>::toJson(value, *this); Converter<T>::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") "Support for char is deprecated, use int8_t or uint8_t instead")
set(char value) const { set(char value) const;
return set<signed char>(value);
}
template <typename T> template <typename T>
FORCE_INLINE bool set(T *value) const { FORCE_INLINE bool set(T *value) const {
return Converter<T *>::toJson(value, *this); Converter<T *>::toJson(value, *this);
return _pool && !_pool->overflowed();
} }
template <typename T> template <typename T>
@@ -341,16 +341,22 @@ class VariantConstRef : public VariantRefBase<const VariantData>,
template <> template <>
struct Converter<VariantRef> { struct Converter<VariantRef> {
static bool toJson(VariantRef src, VariantRef dst) { static void toJson(VariantRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst)); variantCopyFrom(getData(dst), getData(src), getPool(dst));
} }
static VariantRef fromJson(VariantRef src) { static VariantRef fromJson(VariantRef src) {
return src; return src;
} }
static InvalidConversion<VariantConstRef, VariantRef> fromJson(
VariantConstRef);
static bool checkJson(VariantRef src) { static bool checkJson(VariantRef src) {
VariantData *data = getData(src); VariantData *data = getData(src);
return !!data; return !!data;
} }
static bool checkJson(VariantConstRef) { static bool checkJson(VariantConstRef) {
return false; return false;
} }
@@ -358,8 +364,8 @@ struct Converter<VariantRef> {
template <> template <>
struct Converter<VariantConstRef> { struct Converter<VariantConstRef> {
static bool toJson(VariantConstRef src, VariantRef dst) { static void toJson(VariantConstRef src, VariantRef dst) {
return variantCopyFrom(getData(dst), getData(src), getPool(dst)); variantCopyFrom(getData(dst), getData(src), getPool(dst));
} }
static VariantConstRef fromJson(VariantConstRef src) { static VariantConstRef fromJson(VariantConstRef src) {

View File

@@ -4,7 +4,7 @@
#pragma once #pragma once
#define ARDUINOJSON_VERSION "6.18.0" #define ARDUINOJSON_VERSION "6.18.3"
#define ARDUINOJSON_VERSION_MAJOR 6 #define ARDUINOJSON_VERSION_MAJOR 6
#define ARDUINOJSON_VERSION_MINOR 18 #define ARDUINOJSON_VERSION_MINOR 18
#define ARDUINOJSON_VERSION_REVISION 0 #define ARDUINOJSON_VERSION_REVISION 3

View File

@@ -45,6 +45,13 @@ class String {
return _str == s; return _str == s;
} }
bool concat(const char * rhs) {
if (!rhs) {
return 0;
}
_str += rhs;
return 1;
}
private: private:
std::string _str; std::string _str;
@@ -60,7 +67,6 @@ inline bool operator!=(const ::String & lhs, const ::String & rhs) {
return lhs.c_str() != rhs.c_str(); return lhs.c_str() != rhs.c_str();
} }
size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize); size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize);
size_t strlcat(char * dst, const char * src, size_t siz); size_t strlcat(char * dst, const char * src, size_t siz);