Merge remote-tracking branch 'origin/v3.4' into dev

This commit is contained in:
proddy
2022-01-23 17:56:52 +01:00
parent 02e2b51814
commit 77e1898512
538 changed files with 32282 additions and 38655 deletions

View File

@@ -1,12 +1,12 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#ifdef __cplusplus
#include "ArduinoJson.hpp"
# include "ArduinoJson.hpp"
using namespace ArduinoJson;

View File

@@ -1,11 +1,18 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include "ArduinoJson/Configuration.hpp"
// Include Arduino.h before stdlib.h to avoid conflict with atexit()
// https://github.com/bblanchon/ArduinoJson/pull/1693#issuecomment-1001060240
#if ARDUINOJSON_ENABLE_ARDUINO_STRING || ARDUINOJSON_ENABLE_ARDUINO_STREAM || \
ARDUINOJSON_ENABLE_ARDUINO_PRINT || ARDUINOJSON_ENABLE_PROGMEM
# include <Arduino.h>
#endif
#if !ARDUINOJSON_DEBUG
# ifdef __clang__
# pragma clang system_header

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,133 +1,103 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Array/ArrayRef.hpp>
#include <ArduinoJson/Document/JsonDocument.hpp>
#include <ArduinoJson/Variant/Visitor.hpp>
namespace ARDUINOJSON_NAMESPACE {
// Copy a 1D array to a JsonArray
// Trivial form to stop the recursion
template <typename T>
inline typename enable_if<!is_array<T>::value, bool>::type copyArray(
const T& src, VariantRef dst) {
return dst.set(src);
}
// Copy array to a JsonArray/JsonVariant/MemberProxy/ElementProxy
template <typename T, size_t N, typename TDestination>
inline typename enable_if<!is_array<T>::value &&
!is_base_of<JsonDocument, TDestination>::value,
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
bool>::type
copyArray(T (&src)[N], const TDestination& dst) {
return copyArray(src, N, dst);
}
// Copy a 1D array to a JsonDocument
template <typename T, size_t N>
inline bool copyArray(T (&src)[N], JsonDocument& dst) {
return copyArray(src, dst.to<ArrayRef>());
}
// Copy a 1D array to a JsonArray
// Copy ptr+size to a JsonArray/JsonVariant/MemberProxy/ElementProxy
template <typename T, typename TDestination>
inline typename enable_if<!is_array<T>::value &&
!is_base_of<JsonDocument, TDestination>::value,
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
bool>::type
copyArray(T* src, size_t len, const TDestination& dst) {
copyArray(const T* src, size_t len, const TDestination& dst) {
bool ok = true;
for (size_t i = 0; i < len; i++) {
ok &= dst.add(src[i]);
ok &= copyArray(src[i], dst.addElement());
}
return ok;
}
// Copy a 1D array to a JsonDocument
// Special case for char[] which much be treated as const char*
template <typename TDestination>
inline bool copyArray(const char* src, size_t, const TDestination& dst) {
return dst.set(src);
}
// Copy array to a JsonDocument
template <typename T>
inline bool copyArray(T* src, size_t len, JsonDocument& dst) {
inline bool copyArray(const T& src, JsonDocument& dst) {
return copyArray(src, dst.to<ArrayRef>());
}
// Copy a ptr+size array to a JsonDocument
template <typename T>
inline bool copyArray(const T* src, size_t len, JsonDocument& dst) {
return copyArray(src, len, dst.to<ArrayRef>());
}
// Copy a 2D array to a JsonArray
template <typename T, size_t N1, size_t N2, typename TDestination>
inline typename enable_if<!is_base_of<JsonDocument, TDestination>::value,
bool>::type
copyArray(T (&src)[N1][N2], const TDestination& dst) {
bool ok = true;
for (size_t i = 0; i < N1; i++) {
ArrayRef nestedArray = dst.createNestedArray();
for (size_t j = 0; j < N2; j++) {
ok &= nestedArray.add(src[i][j]);
}
}
return ok;
}
// Copy a 2D array to a JsonDocument
template <typename T, size_t N1, size_t N2>
inline bool copyArray(T (&src)[N1][N2], JsonDocument& dst) {
return copyArray(src, dst.to<ArrayRef>());
}
// Trivial case form to stop the recursion
template <typename T>
class ArrayCopier1D : public Visitor<size_t> {
public:
ArrayCopier1D(T* destination, size_t capacity)
: _destination(destination), _capacity(capacity) {}
size_t visitArray(const CollectionData& array) {
size_t size = 0;
VariantSlot* slot = array.head();
while (slot != 0 && size < _capacity) {
_destination[size++] =
Converter<T>::fromJson(VariantConstRef(slot->data()));
slot = slot->next();
}
return size;
}
private:
T* _destination;
size_t _capacity;
};
template <typename T, size_t N1, size_t N2>
class ArrayCopier2D : public Visitor<void> {
public:
ArrayCopier2D(T (*destination)[N1][N2]) : _destination(destination) {}
void visitArray(const CollectionData& array) {
VariantSlot* slot = array.head();
size_t n = 0;
while (slot != 0 && n < N1) {
ArrayCopier1D<T> copier((*_destination)[n++], N2);
variantAccept(slot->data(), copier);
slot = slot->next();
}
}
private:
T (*_destination)[N1][N2];
size_t _capacity1, _capacity2;
};
// Copy a JsonArray to a 1D array
template <typename TSource, typename T, size_t N>
inline typename enable_if<!is_array<T>::value, size_t>::type copyArray(
const TSource& src, T (&dst)[N]) {
VariantConstRef src, T& dst) {
dst = src.as<T>();
return 1;
}
// Copy a JsonArray to array
template <typename T, size_t N>
inline size_t copyArray(ArrayConstRef src, T (&dst)[N]) {
return copyArray(src, dst, N);
}
// Copy a JsonArray to a 1D array
template <typename TSource, typename T>
inline size_t copyArray(const TSource& src, T* dst, size_t len) {
ArrayCopier1D<T> copier(dst, len);
return src.accept(copier);
// Copy a JsonArray to ptr+size
template <typename T>
inline size_t copyArray(ArrayConstRef src, T* dst, size_t len) {
size_t i = 0;
for (ArrayConstRef::iterator it = src.begin(); it != src.end() && i < len;
++it)
copyArray(*it, dst[i++]);
return i;
}
// Copy a JsonArray to a 2D array
template <typename TSource, typename T, size_t N1, size_t N2>
inline void copyArray(const TSource& src, T (&dst)[N1][N2]) {
ArrayCopier2D<T, N1, N2> copier(&dst);
src.accept(copier);
// Special case for char[] which must be treated as a string
template <size_t N>
inline size_t copyArray(VariantConstRef src, char (&dst)[N]) {
String s = src;
size_t len = N - 1;
if (len > s.size())
len = s.size();
memcpy(dst, s.c_str(), len);
dst[len] = 0;
return 1;
}
// Copy a JsonDocument to an array
// (JsonDocument doesn't implicitly convert to JsonArrayConst)
template <typename TSource, typename T>
inline typename enable_if<is_array<T>::value &&
is_base_of<JsonDocument, TSource>::value,
size_t>::type
copyArray(const TSource& src, T& dst) {
return copyArray(src.template as<ArrayConstRef>(), dst);
}
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -40,14 +40,15 @@ class CollectionData {
// Object only
template <typename TAdaptedString>
VariantData *addMember(TAdaptedString key, MemoryPool *pool);
template <typename TAdaptedString, typename TStoragePolicy>
VariantData *addMember(TAdaptedString key, MemoryPool *pool, TStoragePolicy);
template <typename TAdaptedString>
VariantData *getMember(TAdaptedString key) const;
template <typename TAdaptedString>
VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool);
template <typename TAdaptedString, typename TStoragePolicy>
VariantData *getOrAddMember(TAdaptedString key, MemoryPool *pool,
TStoragePolicy);
template <typename TAdaptedString>
void removeMember(TAdaptedString key) {

View File

@@ -1,10 +1,12 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Collection/CollectionData.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Strings/StringAdapters.hpp>
#include <ArduinoJson/Variant/VariantData.hpp>
namespace ARDUINOJSON_NAMESPACE {
@@ -34,11 +36,12 @@ inline VariantData* CollectionData::addElement(MemoryPool* pool) {
return slotData(addSlot(pool));
}
template <typename TAdaptedString>
template <typename TAdaptedString, typename TStoragePolicy>
inline VariantData* CollectionData::addMember(TAdaptedString key,
MemoryPool* pool) {
MemoryPool* pool,
TStoragePolicy storage) {
VariantSlot* slot = addSlot(pool);
if (!slotSetKey(slot, key, pool)) {
if (!slotSetKey(slot, key, pool, storage)) {
removeSlot(slot);
return 0;
}
@@ -61,10 +64,8 @@ inline bool CollectionData::copyFrom(const CollectionData& src,
for (VariantSlot* s = src._head; s; s = s->next()) {
VariantData* var;
if (s->key() != 0) {
if (s->ownsKey())
var = addMember(adaptString(const_cast<char*>(s->key())), pool);
else
var = addMember(adaptString(s->key()), pool);
String key(s->key(), !s->ownsKey());
var = addMember(adaptString(key), pool, getStringStoragePolicy(key));
} else {
var = addElement(pool);
}
@@ -105,9 +106,11 @@ inline bool CollectionData::equalsArray(const CollectionData& other) const {
template <typename TAdaptedString>
inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const {
if (key.isNull())
return 0;
VariantSlot* slot = _head;
while (slot) {
if (key.compare(slot->key()) == 0)
if (stringEquals(key, adaptString(slot->key())))
break;
slot = slot->next();
}
@@ -137,9 +140,9 @@ inline VariantData* CollectionData::getMember(TAdaptedString key) const {
return slot ? slot->data() : 0;
}
template <typename TAdaptedString>
inline VariantData* CollectionData::getOrAddMember(TAdaptedString key,
MemoryPool* pool) {
template <typename TAdaptedString, typename TStoragePolicy>
inline VariantData* CollectionData::getOrAddMember(
TAdaptedString key, MemoryPool* pool, TStoragePolicy storage_policy) {
// ignore null key
if (key.isNull())
return 0;
@@ -149,7 +152,7 @@ inline VariantData* CollectionData::getOrAddMember(TAdaptedString key,
if (slot)
return slot->data();
return addMember(key, pool);
return addMember(key, pool, storage_policy);
}
inline VariantData* CollectionData::getElement(size_t index) const {

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -26,134 +26,96 @@
# 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
#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(<istream>) && \
// Support std::istream and std::ostream
#ifndef ARDUINOJSON_ENABLE_STD_STREAM
# ifdef __has_include
# if __has_include(<istream>) && \
__has_include(<ostream>) && \
!defined(min) && \
!defined(max)
# define ARDUINOJSON_ENABLE_STD_STREAM 1
# define ARDUINOJSON_ENABLE_STD_STREAM 1
# else
# define ARDUINOJSON_ENABLE_STD_STREAM 0
# endif
# else
# define ARDUINOJSON_ENABLE_STD_STREAM 0
# ifdef ARDUINO
# define ARDUINOJSON_ENABLE_STD_STREAM 0
# else
# define ARDUINOJSON_ENABLE_STD_STREAM 1
# endif
# 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(<string>) && !defined(min) && !defined(max)
# define ARDUINOJSON_ENABLE_STD_STRING 1
// Support std::string
#ifndef ARDUINOJSON_ENABLE_STD_STRING
# ifdef __has_include
# if __has_include(<string>) && !defined(min) && !defined(max)
# define ARDUINOJSON_ENABLE_STD_STRING 1
# else
# define ARDUINOJSON_ENABLE_STD_STRING 0
# endif
# else
# define ARDUINOJSON_ENABLE_STD_STRING 0
# ifdef ARDUINO
# define ARDUINOJSON_ENABLE_STD_STRING 0
# else
# define ARDUINOJSON_ENABLE_STD_STRING 1
# endif
# endif
#endif
// Support for std::string_view
#ifndef ARDUINOJSON_ENABLE_STRING_VIEW
# ifdef __has_include
# if __has_include(<string_view>) && __cplusplus >= 201703L
# define ARDUINOJSON_ENABLE_STRING_VIEW 1
# else
# define ARDUINOJSON_ENABLE_STRING_VIEW 0
# endif
# else
# define ARDUINOJSON_ENABLE_STRING_VIEW 0
# endif
#endif
#ifndef ARDUINOJSON_ENABLE_STRING_VIEW
# define ARDUINOJSON_ENABLE_STRING_VIEW 0
// Store floating-point values with float (0) or double (1)
#ifndef ARDUINOJSON_USE_DOUBLE
# define ARDUINOJSON_USE_DOUBLE 1
#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
// 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
// Embedded systems usually don't have std::string
# 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
// Store integral values with long (0) or long long (1)
#ifndef ARDUINOJSON_USE_LONG_LONG
# if ARDUINOJSON_HAS_LONG_LONG && defined(__SIZEOF_POINTER__) && \
__SIZEOF_POINTER__ >= 4 || \
defined(_MSC_VER)
# define ARDUINOJSON_USE_LONG_LONG 1
# endif
#endif
#ifndef ARDUINOJSON_USE_LONG_LONG
# define ARDUINOJSON_USE_LONG_LONG 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
// Address space > 16-bit => max 32767 values
# 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
// 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
// On a computer, we can use std::string
# 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
// 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
// Number of bits to store the pointer to next node
# ifndef ARDUINOJSON_SLOT_OFFSET_SIZE
# define ARDUINOJSON_SLOT_OFFSET_SIZE 1
# elif defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ >= 8 || \
defined(_WIN64) && _WIN64
// Address space == 64-bit => max 2147483647 values
# define ARDUINOJSON_SLOT_OFFSET_SIZE 4
# else
// Address space == 32-bit => max 32767 values
# define ARDUINOJSON_SLOT_OFFSET_SIZE 2
# endif
#endif // ARDUINOJSON_EMBEDDED_MODE
#endif
#ifdef ARDUINO
# include <Arduino.h>
// Enable support for Arduino's String class
# ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
# define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
@@ -169,6 +131,11 @@
# define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1
# endif
// Enable support for PROGMEM
# ifndef ARDUINOJSON_ENABLE_PROGMEM
# define ARDUINOJSON_ENABLE_PROGMEM 1
# endif
#else // ARDUINO
// Disable support for Arduino's String class
@@ -186,16 +153,12 @@
# 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
// Disable support for PROGMEM
# ifndef ARDUINOJSON_ENABLE_PROGMEM
# define ARDUINOJSON_ENABLE_PROGMEM 0
# endif
#endif
#endif // ARDUINO
// Convert unicode escape sequence (\u0123) to UTF-8
#ifndef ARDUINOJSON_DECODE_UNICODE

View File

@@ -1,9 +1,10 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Misc/SafeBoolIdiom.hpp>
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Polyfills/preprocessor.hpp>
#include <ArduinoJson/Polyfills/static_array.hpp>
@@ -14,11 +15,7 @@
namespace ARDUINOJSON_NAMESPACE {
class DeserializationError {
// safe bool idiom
typedef void (DeserializationError::*bool_type)() const;
void safeBoolHelper() const {}
class DeserializationError : public SafeBoolIdom<DeserializationError> {
public:
enum Code {
Ok,
@@ -58,19 +55,7 @@ class DeserializationError {
// Behaves like a bool
operator bool_type() const {
return _code != Ok ? &DeserializationError::safeBoolHelper : 0;
}
friend bool operator==(bool value, const DeserializationError& err) {
return static_cast<bool>(err) == value;
}
friend bool operator==(const DeserializationError& err, bool value) {
return static_cast<bool>(err) == value;
}
friend bool operator!=(bool value, const DeserializationError& err) {
return static_cast<bool>(err) != value;
}
friend bool operator!=(const DeserializationError& err, bool value) {
return static_cast<bool>(err) != value;
return _code != Ok ? safe_true() : safe_false();
}
// Returns internal enum, useful for switch statement

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,9 +1,11 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <Arduino.h>
namespace ARDUINOJSON_NAMESPACE {
template <typename TSource>

View File

@@ -1,9 +1,11 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <Arduino.h>
namespace ARDUINOJSON_NAMESPACE {
template <>

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -14,7 +14,6 @@ template <typename TAllocator>
class AllocatorOwner {
public:
AllocatorOwner() {}
AllocatorOwner(const AllocatorOwner& src) : _allocator(src._allocator) {}
AllocatorOwner(TAllocator a) : _allocator(a) {}
void* allocate(size_t size) {
@@ -98,7 +97,9 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
template <typename T>
BasicJsonDocument& operator=(const T& src) {
reallocPoolIfTooSmall(src.memoryUsage());
size_t requiredSize = src.memoryUsage();
if (requiredSize > capacity())
reallocPool(requiredSize);
set(src);
return *this;
}
@@ -136,8 +137,9 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
return MemoryPool(reinterpret_cast<char*>(this->allocate(capa)), capa);
}
void reallocPoolIfTooSmall(size_t requiredSize) {
if (requiredSize <= capacity())
void reallocPool(size_t requiredSize) {
size_t capa = addPadding(requiredSize);
if (capa == _pool.capacity())
return;
freePool();
replacePool(allocPool(addPadding(requiredSize)));
@@ -148,7 +150,7 @@ class BasicJsonDocument : AllocatorOwner<TAllocator>, public JsonDocument {
}
void copyAssignFrom(const JsonDocument& src) {
reallocPoolIfTooSmall(src.capacity());
reallocPool(src.capacity());
set(src);
}

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -8,6 +8,7 @@
#include <ArduinoJson/Memory/MemoryPool.hpp>
#include <ArduinoJson/Object/MemberProxy.hpp>
#include <ArduinoJson/Object/ObjectRef.hpp>
#include <ArduinoJson/Strings/StoragePolicy.hpp>
#include <ArduinoJson/Variant/VariantRef.hpp>
#include <ArduinoJson/Variant/VariantTo.hpp>
@@ -138,14 +139,14 @@ class JsonDocument : public Visitable {
// containsKey(const __FlashStringHelper*) const
template <typename TChar>
bool containsKey(TChar* key) const {
return !getMember(key).isUndefined();
return !getMember(key).isUnbound();
}
// containsKey(const std::string&) const
// containsKey(const String&) const
template <typename TString>
bool containsKey(const TString& key) const {
return !getMember(key).isUndefined();
return !getMember(key).isUnbound();
}
// operator[](const std::string&)
@@ -244,14 +245,18 @@ class JsonDocument : public Visitable {
// getOrAddMember(const __FlashStringHelper*)
template <typename TChar>
FORCE_INLINE VariantRef getOrAddMember(TChar* key) {
return VariantRef(&_pool, _data.getOrAddMember(adaptString(key), &_pool));
return VariantRef(&_pool,
_data.getOrAddMember(adaptString(key), &_pool,
getStringStoragePolicy(key)));
}
// getOrAddMember(const std::string&)
// getOrAddMember(const String&)
template <typename TString>
FORCE_INLINE VariantRef getOrAddMember(const TString& key) {
return VariantRef(&_pool, _data.getOrAddMember(adaptString(key), &_pool));
return VariantRef(&_pool,
_data.getOrAddMember(adaptString(key), &_pool,
getStringStoragePolicy(key)));
}
FORCE_INLINE VariantRef addElement() {

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -33,13 +33,13 @@ class StaticJsonDocument : public JsonDocument {
set(src);
}
StaticJsonDocument operator=(const StaticJsonDocument& src) {
StaticJsonDocument& operator=(const StaticJsonDocument& src) {
set(src);
return *this;
}
template <typename T>
StaticJsonDocument operator=(const T& src) {
StaticJsonDocument& operator=(const T& src) {
set(src);
return *this;
}

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -231,12 +231,12 @@ class JsonDeserializer {
return false;
}
const char *key = _stringStorage.c_str();
String key = _stringStorage.str();
TFilter memberFilter = filter[key];
TFilter memberFilter = filter[key.c_str()];
if (memberFilter.allow()) {
VariantData *variant = object.getMember(adaptString(key));
VariantData *variant = object.getMember(adaptString(key.c_str()));
if (!variant) {
// Save key in memory pool.
// This MUST be done before adding the slot.
@@ -249,7 +249,7 @@ class JsonDeserializer {
return false;
}
slot->setKey(key, typename TStringStorage::storage_policy());
slot->setKey(key);
variant = slot->data();
}
@@ -345,8 +345,7 @@ class JsonDeserializer {
_stringStorage.startString();
if (!parseQuotedString())
return false;
const char *value = _stringStorage.save();
variant.setStringPointer(value, typename TStringStorage::storage_policy());
variant.setString(_stringStorage.save());
return true;
}
@@ -402,8 +401,6 @@ class JsonDeserializer {
_stringStorage.append(c);
}
_stringStorage.append('\0');
if (!_stringStorage.isValid()) {
_error = DeserializationError::NoMemory;
return false;
@@ -427,8 +424,6 @@ class JsonDeserializer {
return false;
}
_stringStorage.append('\0');
if (!_stringStorage.isValid()) {
_error = DeserializationError::NoMemory;
return false;

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -8,6 +8,7 @@
#include <ArduinoJson/Misc/Visitable.hpp>
#include <ArduinoJson/Serialization/measure.hpp>
#include <ArduinoJson/Serialization/serialize.hpp>
#include <ArduinoJson/Variant/Visitor.hpp>
namespace ARDUINOJSON_NAMESPACE {
@@ -68,6 +69,11 @@ class JsonSerializer : public Visitor<size_t> {
return bytesWritten();
}
size_t visitString(const char *value, size_t n) {
_formatter.writeString(value, n);
return bytesWritten();
}
size_t visitRawJson(const char *data, size_t n) {
_formatter.writeRaw(data, n);
return bytesWritten();

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -41,13 +41,22 @@ class TextFormatter {
writeRaw('\"');
}
void writeString(const char *value, size_t n) {
ARDUINOJSON_ASSERT(value != NULL);
writeRaw('\"');
while (n--) writeChar(*value++);
writeRaw('\"');
}
void writeChar(char c) {
char specialChar = EscapeSequence::escapeChar(c);
if (specialChar) {
writeRaw('\\');
writeRaw(specialChar);
} else {
} else if (c) {
writeRaw(c);
} else {
writeRaw("\\u0000");
}
}

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -60,7 +60,7 @@ class MemoryPool {
}
template <typename TAdaptedString>
const char* saveString(const TAdaptedString& str) {
const char* saveString(TAdaptedString str) {
if (str.isNull())
return 0;
@@ -74,7 +74,7 @@ class MemoryPool {
char* newCopy = allocString(n + 1);
if (newCopy) {
str.copyTo(newCopy, n);
stringGetChars(str, newCopy, n);
newCopy[n] = 0; // force null-terminator
}
return newCopy;
@@ -87,13 +87,14 @@ class MemoryPool {
const char* saveStringFromFreeZone(size_t len) {
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
const char* dup = findString(adaptString(_left));
const char* dup = findString(adaptString(_left, len));
if (dup)
return dup;
#endif
const char* str = _left;
_left += len;
*_left++ = 0;
checkInvariants();
return str;
}
@@ -165,9 +166,10 @@ class MemoryPool {
#if ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
template <typename TAdaptedString>
const char* findString(const TAdaptedString& str) {
for (char* next = _begin; next < _left; ++next) {
if (str.compare(next) == 0)
const char* findString(const TAdaptedString& str) const {
size_t n = str.size();
for (char* next = _begin; next + n < _left; ++next) {
if (next[n] == '\0' && stringEquals(str, adaptString(next, n)))
return next;
// jump to next terminator

View File

@@ -0,0 +1,26 @@
// ArduinoJson - https://arduinojson.org
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
template <typename T>
class SafeBoolIdom {
protected:
typedef void (T::*bool_type)() const;
void safeBoolHelper() const {}
static bool_type safe_true() {
return &SafeBoolIdom::safeBoolHelper;
}
static bool_type safe_false() {
return 0;
}
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -48,6 +48,11 @@ class MsgPackDeserializer {
bool allowValue = filter.allowValue();
if (allowValue) {
// callers pass a null pointer only when value must be ignored
ARDUINOJSON_ASSERT(variant != 0);
}
switch (code) {
case 0xc0:
// already null
@@ -331,8 +336,7 @@ class MsgPackDeserializer {
bool readString(VariantData *variant, size_t n) {
if (!readString(n))
return false;
variant->setStringPointer(_stringStorage.save(),
typename TStringStorage::storage_policy());
variant->setString(_stringStorage.save());
return true;
}
@@ -344,7 +348,6 @@ class MsgPackDeserializer {
return false;
_stringStorage.append(static_cast<char>(c));
}
_stringStorage.append('\0');
if (!_stringStorage.isValid()) {
_error = DeserializationError::NoMemory;
return false;
@@ -419,11 +422,13 @@ class MsgPackDeserializer {
if (!readKey())
return false;
const char *key = _stringStorage.c_str();
TFilter memberFilter = filter[key];
String key = _stringStorage.str();
TFilter memberFilter = filter[key.c_str()];
VariantData *member;
if (memberFilter.allow()) {
ARDUINOJSON_ASSERT(object);
// Save key in memory pool.
// This MUST be done before adding the slot.
key = _stringStorage.save();
@@ -434,7 +439,7 @@ class MsgPackDeserializer {
return false;
}
slot->setKey(key, typename TStringStorage::storage_policy());
slot->setKey(key);
member = slot->data();
} else {

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -78,9 +78,11 @@ class MsgPackSerializer : public Visitor<size_t> {
}
size_t visitString(const char* value) {
ARDUINOJSON_ASSERT(value != NULL);
return visitString(value, strlen(value));
}
size_t n = strlen(value);
size_t visitString(const char* value, size_t n) {
ARDUINOJSON_ASSERT(value != NULL);
if (n < 0x20) {
writeByte(uint8_t(0xA0 + n));

View File

@@ -1,29 +1,34 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Polyfills/type_traits.hpp>
#include <ArduinoJson/Polyfills/utility.hpp>
namespace ARDUINOJSON_NAMESPACE {
#if ARDUINOJSON_LITTLE_ENDIAN
inline void swapBytes(uint8_t &a, uint8_t &b) {
uint8_t t(a);
a = b;
b = t;
}
inline void fixEndianess(uint8_t *p, integral_constant<size_t, 8>) {
swap(p[0], p[7]);
swap(p[1], p[6]);
swap(p[2], p[5]);
swap(p[3], p[4]);
swapBytes(p[0], p[7]);
swapBytes(p[1], p[6]);
swapBytes(p[2], p[5]);
swapBytes(p[3], p[4]);
}
inline void fixEndianess(uint8_t *p, integral_constant<size_t, 4>) {
swap(p[0], p[3]);
swap(p[1], p[2]);
swapBytes(p[0], p[3]);
swapBytes(p[1], p[2]);
}
inline void fixEndianess(uint8_t *p, integral_constant<size_t, 2>) {
swap(p[0], p[1]);
swapBytes(p[0], p[1]);
}
inline void fixEndianess(uint8_t *, integral_constant<size_t, 1>) {}

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -158,24 +158,42 @@ struct FloatTraits<T, 4 /*32bits*/> {
}
static T positiveBinaryPowerOfTen(int index) {
ARDUINOJSON_DEFINE_STATIC_ARRAY(
T, factors,
ARDUINOJSON_EXPAND6({1e1f, 1e2f, 1e4f, 1e8f, 1e16f, 1e32f}));
return ARDUINOJSON_READ_STATIC_ARRAY(T, factors, index);
ARDUINOJSON_DEFINE_STATIC_ARRAY(uint32_t, factors,
ARDUINOJSON_EXPAND6({
0x41200000, // 1e1f
0x42c80000, // 1e2f
0x461c4000, // 1e4f
0x4cbebc20, // 1e8f
0x5a0e1bca, // 1e16f
0x749dc5ae // 1e32f
}));
return forge(ARDUINOJSON_READ_STATIC_ARRAY(uint32_t, factors, index));
}
static T negativeBinaryPowerOfTen(int index) {
ARDUINOJSON_DEFINE_STATIC_ARRAY(
T, factors,
ARDUINOJSON_EXPAND6({1e-1f, 1e-2f, 1e-4f, 1e-8f, 1e-16f, 1e-32f}));
return ARDUINOJSON_READ_STATIC_ARRAY(T, factors, index);
ARDUINOJSON_DEFINE_STATIC_ARRAY(uint32_t, factors,
ARDUINOJSON_EXPAND6({
0x3dcccccd, // 1e-1f
0x3c23d70a, // 1e-2f
0x38d1b717, // 1e-4f
0x322bcc77, // 1e-8f
0x24e69595, // 1e-16f
0x0a4fb11f // 1e-32f
}));
return forge(ARDUINOJSON_READ_STATIC_ARRAY(uint32_t, factors, index));
}
static T negativeBinaryPowerOfTenPlusOne(int index) {
ARDUINOJSON_DEFINE_STATIC_ARRAY(
T, factors,
ARDUINOJSON_EXPAND6({1e0f, 1e-1f, 1e-3f, 1e-7f, 1e-15f, 1e-31f}));
return ARDUINOJSON_READ_STATIC_ARRAY(T, factors, index);
ARDUINOJSON_DEFINE_STATIC_ARRAY(uint32_t, factors,
ARDUINOJSON_EXPAND6({
0x3f800000, // 1e0f
0x3dcccccd, // 1e-1f
0x3a83126f, // 1e-3f
0x33d6bf95, // 1e-7f
0x26901d7d, // 1e-15f
0x0c01ceb3 // 1e-31f
}));
return forge(ARDUINOJSON_READ_STATIC_ARRAY(uint32_t, factors, index));
}
static T forge(uint32_t bits) {

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -40,12 +40,13 @@ void objectRemove(CollectionData *obj, TAdaptedString key) {
obj->removeMember(key);
}
template <typename TAdaptedString>
template <typename TAdaptedString, typename TStoragePolicy>
inline VariantData *objectGetOrAddMember(CollectionData *obj,
TAdaptedString key, MemoryPool *pool) {
TAdaptedString key, MemoryPool *pool,
TStoragePolicy storage_policy) {
if (!obj)
return 0;
return obj->getOrAddMember(key, pool);
return obj->getOrAddMember(key, pool, storage_policy);
}
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -40,14 +40,14 @@ template <typename TObject>
template <typename TString>
inline typename enable_if<IsString<TString>::value, bool>::type
ObjectShortcuts<TObject>::containsKey(const TString& key) const {
return !impl()->getMember(key).isUndefined();
return !impl()->getMember(key).isUnbound();
}
template <typename TObject>
template <typename TChar>
inline typename enable_if<IsString<TChar*>::value, bool>::type
ObjectShortcuts<TObject>::containsKey(TChar* key) const {
return !impl()->getMember(key).isUndefined();
return !impl()->getMember(key).isUnbound();
}
template <typename TObject>

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -77,7 +77,7 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
// containsKey(const String&) const
template <typename TString>
FORCE_INLINE bool containsKey(const TString& key) const {
return !getMember(key).isUndefined();
return !getMember(key).isUnbound();
}
// containsKey(char*) const
@@ -85,7 +85,7 @@ class ObjectConstRef : public ObjectRefBase<const CollectionData>,
// containsKey(const __FlashStringHelper*) const
template <typename TChar>
FORCE_INLINE bool containsKey(TChar* key) const {
return !getMember(key).isUndefined();
return !getMember(key).isUnbound();
}
// getMember(const std::string&) const
@@ -196,7 +196,8 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
template <typename TString>
FORCE_INLINE VariantRef getOrAddMember(const TString& key) const {
return VariantRef(_pool,
objectGetOrAddMember(_data, adaptString(key), _pool));
objectGetOrAddMember(_data, adaptString(key), _pool,
getStringStoragePolicy(key)));
}
// getOrAddMember(char*) const
@@ -205,7 +206,8 @@ class ObjectRef : public ObjectRefBase<CollectionData>,
template <typename TChar>
FORCE_INLINE VariantRef getOrAddMember(TChar* key) const {
return VariantRef(_pool,
objectGetOrAddMember(_data, adaptString(key), _pool));
objectGetOrAddMember(_data, adaptString(key), _pool,
getStringStoragePolicy(key)));
}
FORCE_INLINE bool operator==(ObjectRef rhs) const {

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,9 +1,11 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <Arduino.h>
#include <ArduinoJson/Configuration.hpp>
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Polyfills/assert.hpp>
@@ -12,7 +14,7 @@ namespace ARDUINOJSON_NAMESPACE {
// Wraps a const char* so that the our functions are picked only if the
// originals are missing
struct pgm_p {
pgm_p(const char* p) : address(p) {}
pgm_p(const void* p) : address(reinterpret_cast<const char*>(p)) {}
const char* address;
};
} // namespace ARDUINOJSON_NAMESPACE
@@ -65,6 +67,22 @@ inline int strcmp_P(const char* a, ARDUINOJSON_NAMESPACE::pgm_p b) {
}
#endif
#ifndef memcmp_P
inline int memcmp_P(const void* a, ARDUINOJSON_NAMESPACE::pgm_p b, size_t n) {
const uint8_t* p1 = reinterpret_cast<const uint8_t*>(a);
const char* p2 = b.address;
ARDUINOJSON_ASSERT(p1 != NULL);
ARDUINOJSON_ASSERT(p2 != NULL);
while (n-- > 0) {
uint8_t v1 = *p1++;
uint8_t v2 = pgm_read_byte(p2++);
if (v1 != v2)
return v1 - v2;
}
return 0;
}
#endif
#ifndef memcpy_P
inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) {
uint8_t* d = reinterpret_cast<uint8_t*>(dst);
@@ -77,3 +95,19 @@ inline void* memcpy_P(void* dst, ARDUINOJSON_NAMESPACE::pgm_p src, size_t n) {
return dst;
}
#endif
#ifndef pgm_read_dword
inline uint32_t pgm_read_dword(ARDUINOJSON_NAMESPACE::pgm_p p) {
uint32_t result;
memcpy_P(&result, p, 4);
return result;
}
#endif
#ifndef pgm_read_ptr
inline void* pgm_read_ptr(ARDUINOJSON_NAMESPACE::pgm_p p) {
void* result;
memcpy_P(&result, p, sizeof(result));
return result;
}
#endif

View File

@@ -1,10 +1,11 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <ArduinoJson/Polyfills/pgmspace.hpp>
#include <ArduinoJson/Polyfills/type_traits.hpp>
namespace ARDUINOJSON_NAMESPACE {
@@ -14,15 +15,6 @@ typename enable_if<is_pointer<T>::value, T>::type pgm_read(const void* p) {
return reinterpret_cast<T>(pgm_read_ptr(p));
}
template <typename T>
typename enable_if<is_floating_point<T>::value &&
sizeof(T) == sizeof(float), // on AVR sizeof(double) ==
// sizeof(float)
T>::type
pgm_read(const void* p) {
return pgm_read_float(p);
}
template <typename T>
typename enable_if<is_same<T, uint32_t>::value, T>::type pgm_read(
const void* p) {

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,32 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include <ArduinoJson/Namespace.hpp>
#include <stdint.h> // int8_t
namespace ARDUINOJSON_NAMESPACE {
inline int safe_strcmp(const char* a, const char* b) {
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
return strcmp(a, b);
}
inline int safe_strncmp(const char* a, const char* b, size_t n) {
if (a == b)
return 0;
if (!a)
return -1;
if (!b)
return 1;
return strncmp(a, b, n);
}
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@@ -10,25 +10,21 @@
# include <ArduinoJson/Polyfills/pgmspace_generic.hpp>
# ifndef ARDUINOJSON_DEFINE_STATIC_ARRAY
# define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
# ifndef ARDUINOJSON_DEFINE_PROGMEM_ARRAY
# define ARDUINOJSON_DEFINE_PROGMEM_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<type>(name + index)
# endif
# define ARDUINOJSON_DEFINE_STATIC_ARRAY ARDUINOJSON_DEFINE_PROGMEM_ARRAY
# define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) \
pgm_read<type>(name + index)
#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
# define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
static type const name[] = value;
# ifndef ARDUINOJSON_READ_STATIC_ARRAY
# define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) name[index]
# endif
# define ARDUINOJSON_READ_STATIC_ARRAY(type, name, index) name[index]
#endif

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,28 +0,0 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// MIT License
#pragma once
#include "type_traits.hpp"
namespace ARDUINOJSON_NAMESPACE {
template <typename T>
inline void swap(T& a, T& b) {
T t(a);
a = b;
b = t;
}
#if ARDUINOJSON_HAS_RVALUE_REFERENCES
template <typename T>
typename remove_reference<T>::type&& move(T&& t) {
return static_cast<typename remove_reference<T>::type&&>(t);
}
#else
template <typename T>
T& move(T& t) {
return t;
}
#endif
} // namespace ARDUINOJSON_NAMESPACE

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

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