diff --git a/lib/ArduinoJson/.clang-format b/lib/ArduinoJson/.clang-format new file mode 100644 index 000000000..0853a7826 --- /dev/null +++ b/lib/ArduinoJson/.clang-format @@ -0,0 +1,12 @@ +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html + +BasedOnStyle: Google +Standard: c++11 +AllowShortFunctionsOnASingleLine: Empty +IncludeBlocks: Preserve +IndentPPDirectives: AfterHash +DerivePointerAlignment: false + +# Always break after if to get accurate coverage +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/lib/ArduinoJson/.prettierignore b/lib/ArduinoJson/.prettierignore new file mode 100644 index 000000000..dd449725e --- /dev/null +++ b/lib/ArduinoJson/.prettierignore @@ -0,0 +1 @@ +*.md diff --git a/lib/ArduinoJson/ArduinoJson.h b/lib/ArduinoJson/ArduinoJson.h index 15c218f48..993959949 100644 --- a/lib/ArduinoJson/ArduinoJson.h +++ b/lib/ArduinoJson/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #include "src/ArduinoJson.h" diff --git a/lib/ArduinoJson/CHANGELOG.md b/lib/ArduinoJson/CHANGELOG.md index 28c506ab2..796e21bc6 100644 --- a/lib/ArduinoJson/CHANGELOG.md +++ b/lib/ArduinoJson/CHANGELOG.md @@ -1,854 +1,111 @@ ArduinoJson: change log ======================= -v6.21.3 (2023-07-23) -------- +v7.0.0 (2024-01-03) +------ -* Fix compatibility with the Blynk libary (issue #1914) +* Remove `BasicJsonDocument` +* Remove `StaticJsonDocument` +* Add abstract `Allocator` class +* Merge `DynamicJsonDocument` with `JsonDocument` +* Remove `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()` +* Remove `ARDUINOJSON_ENABLE_STRING_DEDUPLICATION` (string deduplication cannot be disabled anymore) +* Remove `JsonDocument::capacity()` +* Store the strings in the heap +* Reference-count shared strings +* Always store `serialized("string")` by copy (#1915) +* Remove the zero-copy mode of `deserializeJson()` and `deserializeMsgPack()` * Fix double lookup in `to()` * Fix double call to `size()` in `serializeMsgPack()` * Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name +* Remove `JsonVariant::shallowCopy()` +* `JsonDocument`'s capacity grows as needed, no need to pass it to the constructor anymore +* `JsonDocument`'s allocator is not monotonic anymore, removed values get recycled * Show a link to the documentation when user passes an unsupported input type - -v6.21.2 (2023-04-12) -------- - -* Fix compatibility with the Zephyr Project (issue #1905) -* Allow using PROGMEM outside of Arduino (issue #1903) -* Set default for `ARDUINOJSON_ENABLE_PROGMEM` to `1` on AVR - -v6.21.1 (2023-03-27) -------- - -* Double speed of `DynamicJsonDocument::garbageCollect()` -* Fix compatibility with GCC 5.2 (issue #1897) - -v6.21.0 (2023-03-14) -------- - -* Drop support for C++98/C++03. Minimum required is C++11. -* Remove `ARDUINOJSON_NAMESPACE`; use `ArduinoJson` instead. -* Make string support generic (issue #1807) - -v6.20.1 (2023-02-08) -------- - -* Remove explicit exclusion of `as()` and `as()` (issue #1860) - If you try to call them, you'll now get the same error message as any unsupported type. - You could also add a custom converter for `char*` and `char`. - -v6.20.0 (2022-12-26) -------- - -* Add `JsonVariant::shallowCopy()` (issue #1343) -* Fix `9.22337e+18 is outside the range of representable values of type 'long'` -* Fix comparison operators for `JsonArray`, `JsonArrayConst`, `JsonObject`, and `JsonObjectConst` -* Fix lax parsing of `true`, `false`, and `null` (issue #1781) -* Remove undocumented `accept()` functions -* Rename `addElement()` to `add()` -* Remove `getElement()`, `getOrAddElement()`, `getMember()`, and `getOrAddMember()` -* Remove undocumented `JsonDocument::data()` and `JsonDocument::memoryPool()` -* Remove undocumented `JsonArrayIterator::internal()` and `JsonObjectIterator::internal()` -* Rename things in `ARDUINOJSON_NAMESPACE` to match the public names -* Add documentation to most public symbols -* Remove support for naked `char` (was deprecated since 6.18.0) +* Remove `JsonDocument::memoryUsage()` +* Remove `JsonDocument::garbageCollect()` +* Add `deserializeJson(JsonVariant, ...)` and `deserializeMsgPack(JsonVariant, ...)` (#1226) +* Call `shrinkToFit()` in `deserializeJson()` and `deserializeMsgPack()` +* `serializeJson()` and `serializeMsgPack()` replace the content of `std::string` and `String` instead of appending to it +* Replace `add()` with `add()` (`add(T)` is still supported) +* Remove `createNestedArray()` and `createNestedObject()` (use `to()` and `to()` instead) > ### BREAKING CHANGES > -> This release hides `JsonVariant`'s functions that were only intended for internal use. -> If you were using them in your programs, you must replace with `operator[]` and `to()`, like so: +> As every major release, ArduinoJson 7 introduces several breaking changes. +> I added some stubs so that most existing programs should compile, but I highty recommend you upgrade your code. +> +> #### `JsonDocument` +> +> In ArduinoJson 6, you could allocate the memory pool on the stack (with `StaticJsonDocument`) or in the heap (with `DynamicJsonDocument`). +> In ArduinoJson 7, the memory pool is always allocated in the heap, so `StaticJsonDocument` and `DynamicJsonDocument` have been merged into `JsonDocument`. +> +> In ArduinoJson 6, `JsonDocument` had a fixed capacity; in ArduinoJson 7, it has an elastic capacity that grows as needed. +> Therefore, you don't need to specify the capacity anymore, so the macros `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()` have been removed. > > ```c++ -> // before -> JsonVariant a = variant.getElement(idx); -> JsonVariant b = variant.getOrAddElement(idx); -> JsonVariant c = variant.getMember(key); -> JsonVariant d = variant.getOrAddMember(key); -> -> // after -> JsonVariant a = variant[idx]; -> JsonVariant b = idx < variant.size() ? variant[idx] : variant[idx].to(); -> JsonVariant c = variant[key]; -> JsonVariant d = variant.containsKey(key) ? variant[key] : variant[key].to(); -> ``` - -v6.19.4 (2022-04-05) -------- - -* Add `ElementProxy::memoryUsage()` -* Add `MemberProxy::memoryUsage()` (issue #1730) -* Add implicit conversion from `JsonDocument` to `JsonVariant` -* Fix comparisons operators with `const JsonDocument&` - -v6.19.3 (2022-03-08) -------- - -* Fix `call of overloaded 'String(const char*, int)' is ambiguous` -* Fix `JsonString` operator `==` and `!=` for non-zero-terminated string -* Fix `-Wsign-conversion` on GCC 8 (issue #1715) -* MessagePack: serialize round floats as integers (issue #1718) - -v6.19.2 (2022-02-14) -------- - -* Fix `cannot convert 'pgm_p' to 'const void*'` (issue #1707) - -v6.19.1 (2022-01-14) -------- - -* Fix crash when adding an object member in a too small `JsonDocument` -* Fix filter not working in zero-copy mode (issue #1697) - -v6.19.0 (2022-01-08) -------- - -* Remove `ARDUINOJSON_EMBEDDED_MODE` and assume we run on an embedded platform. - Dependent settings (like `ARDUINOJSON_DEFAULT_NESTING_LIMIT`) must be set individually. -* Change the default of `ARDUINOJSON_USE_DOUBLE` to `1` -* Change the default of `ARDUINOJSON_USE_LONG_LONG` to `1` on 32-bit platforms -* Add `as()` and `is()` -* Add safe bool idiom in `JsonString` -* Add support for NUL in string values (issue #1646) -* Add support for arbitrary array rank in `copyArray()` -* Add support for `char[][]` in `copyArray()` -* Remove `DeserializationError == bool` and `DeserializationError != bool` -* Renamed undocumented function `isUndefined()` to `isUnbound()` -* Fix `JsonVariant::memoryUsage()` for raw strings -* Fix `call of overloaded 'swap(BasicJsonDocument&, BasicJsonDocument&)' is ambiguous` (issue #1678) -* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move constructors -* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move assignments -* Fix return type of `StaticJsonDocument::operator=` -* Avoid pool reallocation in `BasicJsonDocument`'s copy assignment if capacity is the same -* Avoid including `Arduino.h` when all its features are disabled (issue #1692, PR #1693 by @paulocsanz) -* Assume `PROGMEM` is available as soon as `ARDUINO` is defined (consequence of #1693) - -v6.18.5 (2021-09-28) -------- - -* Set `ARDUINOJSON_EMBEDDED_MODE` to `1` on Nios II (issue #1657) - -v6.18.4 (2021-09-06) -------- - -* Fixed error `'dummy' may be used uninitialized` on GCC 11 -* Fixed error `expected unqualified-id before 'const'` on GCC 11 (issue #1622) -* Filter: exact match takes precedence over wildcard (issue #1628) -* Fixed deserialization of `\u0000` (issue #1646) - -v6.18.3 (2021-07-27) -------- - -* Changed return type of `convertToJson()` and `Converter::toJson()` to `void` -* Added `as()` and `is()` - -v6.18.2 (2021-07-19) -------- - -* Removed a symlink because the Arduino Library Specification forbids it - -v6.18.1 (2021-07-03) -------- - -* Fixed support for `volatile float` and `volatile double` (issue #1557) -* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560) -* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572) -* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas) -* Added fake class `InvalidConversion` to easily identify invalid conversions (issue #1585) -* Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64) -* Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator` -* Added `JsonArray::clear()` (issue #1597) -* Fixed `JsonVariant::as()` (issue #1601) -* Added support for ESP-IDF component build (PR #1562 by @qt1, PR #1599 by @andreaskuster) - -v6.18.0 (2021-05-05) -------- - -* Added support for custom converters (issue #687) -* Added support for `Printable` (issue #1444) -* Removed support for `char` values, see below (issue #1498) -* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported` -* `deserializeMsgPack()` inserts `null` instead of returning `NotSupported` -* Removed `DeserializationError::NotSupported` -* Added `JsonVariant::is()` (issue #1412) -* Added `JsonVariant::is()` (issue #1412) -* Changed `JsonVariantConst::is()` to return `false` (issue #1412) -* Simplified `JsonVariant::as()` to always return `T` (see below) -* Updated folders list in `.mbedignore` (PR #1515 by @AGlass0fMilk) -* Fixed member-call-on-null-pointer in `getMember()` when array is empty -* `serializeMsgPack(doc, buffer, size)` doesn't add null-terminator anymore (issue #1545) -* `serializeJson(doc, buffer, size)` adds null-terminator only if there is enough room -* PlatformIO: set `build.libArchive` to `false` (PR #1550 by @askreet) - -> ### BREAKING CHANGES -> -> #### Support for `char` removed -> -> We cannot cast a `JsonVariant` to a `char` anymore, so the following will break: -> ```c++ -> char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)' -> ``` -> Instead, you must use another integral type, such as `int8_t`: -> ```c++ -> int8_t age = doc["age"]; // OK +> // ArduinoJson 6 +> StaticJsonDocument<256> doc; +> // or +> DynamicJsonDocument doc(256); +> +> // ArduinoJson 7 +> JsonDocument doc; > ``` > -> Similarly, we cannot assign from a `char` anymore, so the following will break: -> ```c++ -> char age; -> doc["age"] = age; // error: no matching function for call to 'VariantRef::set(const char&)' -> ``` -> Instead, you must use another integral type, such as `int8_t`: -> ```c++ -> int8_t age; -> doc["age"] = age; // OK -> ``` -> A deprecation warning with the message "Support for `char` is deprecated, use `int8_t` or `uint8_t` instead" was added to allow a smooth transition. +> In ArduinoJson 7, `JsonDocument` reuses released memory, so `garbageCollect()` has been removed. +> `shrinkToFit()` is still available and releases the over-allocated memory. > -> #### `as()` always returns `T` +> Due to a change in the implementation, it's not possible to store a pointer to a variant from another `JsonDocument`, so `shallowCopy()` has been removed. +> +> In ArduinoJson 6, the meaning of `memoryUsage()` was clear: it returned the number of bytes used in the memory pool. +> In ArduinoJson 7, the meaning of `memoryUsage()` would be ambiguous, so it has been removed. > -> Previously, `JsonVariant::as()` could return a type different from `T`. -> The most common example is `as()` that returned a `const char*`. -> While this feature simplified a few use cases, it was confusing and complicated the -> implementation of custom converters. +> #### Custom allocators > -> Starting from this version, `as` doesn't try to auto-correct the return type and always return `T`, -> which means that you cannot write this anymore: +> In ArduinoJson 6, you could specify a custom allocator class as a template parameter of `BasicJsonDocument`. +> In ArduinoJson 7, you must inherit from `ArduinoJson::Allocator` and pass a pointer to an instance of your class to the constructor of `JsonDocument`. > > ```c++ -> Serial.println(doc["sensor"].as()); // error: invalid conversion from 'const char*' to 'char*' [-fpermissive] +> // ArduinoJson 6 +> class MyAllocator { +> // ... +> }; +> BasicJsonDocument doc(256); +> +> // ArduinoJson 7 +> class MyAllocator : public ArduinoJson::Allocator { +> // ... +> }; +> MyAllocator myAllocator; +> JsonDocument doc(&myAllocator); > ``` -> -> Instead, you must write: +> +> #### `createNestedArray()` and `createNestedObject()` +> +> In ArduinoJson 6, you could create a nested array or object with `createNestedArray()` and `createNestedObject()`. +> In ArduinoJson 7, you must use `add()` or `to()` instead. +> +> For example, to create `[[],{}]`, you would write: > > ```c++ -> Serial.println(doc["sensor"].as()); // OK +> // ArduinoJson 6 +> arr.createNestedArray(); +> arr.createNestedObject(); +> +> // ArduinoJson 7 +> arr.add(); +> arr.add(); > ``` > -> A deprecation warning with the message "Replace `as()` with `as()`" was added to allow a smooth transition. -> -> #### `DeserializationError::NotSupported` removed -> -> On a different topic, `DeserializationError::NotSupported` has been removed. -> Instead of returning this error: -> -> * `deserializeJson()` leaves `\uXXXX` unchanged (only when `ARDUINOJSON_DECODE_UNICODE` is `0`) -> * `deserializeMsgPack()` replaces unsupported values with `null`s -> -> #### Const-aware `is()` -> -> Lastly, a very minor change concerns `JsonVariantConst::is()`. -> It used to return `true` for `JsonArray` and `JsonOject`, but now it returns `false`. -> Instead, you must use `JsonArrayConst` and `JsonObjectConst`. - -v6.17.3 (2021-02-15) -------- - -* Made `JsonDocument`'s destructor protected (issue #1480) -* Added missing calls to `client.stop()` in `JsonHttpClient.ino` (issue #1485) -* Fixed error `expected ')' before 'char'` when `isdigit()` is a macro (issue #1487) -* Fixed error `definition of implicit copy constructor is deprecated` on Clang 10 -* PlatformIO: set framework compatibility to `*` (PR #1490 by @maxgerhardt) - -v6.17.2 (2020-11-14) -------- - -* Fixed invalid conversion error in `operator|(JsonVariant, char*)` (issue #1432) -* Changed the default value of `ARDUINOJSON_ENABLE_PROGMEM` (issue #1433). - It now checks that the `pgm_read_XXX` macros are defined before enabling `PROGMEM`. - -v6.17.1 (2020-11-07) -------- - -* Fixed error `ambiguous overload for 'operator|'` (issue #1411) -* Fixed `operator|(MemberProxy, JsonObject)` (issue #1415) -* Allowed more than 32767 values in non-embedded mode (issue #1414) - -v6.17.0 (2020-10-19) -------- - -* Added a build failure when nullptr is defined as a macro (issue #1355) -* Added `JsonDocument::overflowed()` which tells if the memory pool was too small (issue #1358) -* Added `DeserializationError::EmptyInput` which tells if the input was empty -* Added `DeserializationError::f_str()` which returns a `const __FlashStringHelper*` (issue #846) -* Added `operator|(JsonVariantConst, JsonVariantConst)` -* Added filtering for MessagePack (issue #1298, PR #1394 by Luca Passarella) -* Moved float convertion tables to PROGMEM -* Fixed `JsonVariant::set((char*)0)` which returned false instead of true (issue #1368) -* Fixed error `No such file or directory #include ` (issue #1381) - -v6.16.1 (2020-08-04) -------- - -* Fixed `deserializeJson()` that stopped reading after `{}` (issue #1335) - -v6.16.0 (2020-08-01) -------- - -* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s -* Added string deduplication (issue #1303) -* Added `JsonString::operator!=` -* Added wildcard key (`*`) for filters (issue #1309) -* Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default -* Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy` -* Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311) -* Fixed excessive stack usage when compiled with `-Og` (issues #1210 and #1314) -* Fixed `Warning[Pa093]: implicit conversion from floating point to integer` on IAR compiler (PR #1328 by @stawiski) - -v6.15.2 (2020-05-15) -------- - -* CMake: don't build tests when imported in another project -* CMake: made project arch-independent -* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250) -* Added support for `JsonDocument` to `copyArray()` (issue #1255) -* Added support for `enum`s in `as()` and `is()` (issue #1256) -* Added `JsonVariant` as an input type for `deserializeXxx()` - For example, you can do: `deserializeJson(doc2, doc1["payload"])` -* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0 - -v6.15.1 (2020-04-08) -------- - -* Fixed "maybe-uninitialized" warning (issue #1217) -* Fixed "statement is unreachable" warning on IAR (issue #1233) -* Fixed "pointless integer comparison" warning on IAR (issue #1233) -* Added CMake "install" target (issue #1209) -* Disabled alignment on AVR (issue #1231) - -v6.15.0 (2020-03-22) -------- - -* Added `DeserializationOption::Filter` (issue #959) -* Added example `JsonFilterExample.ino` -* Changed the array subscript operator to automatically add missing elements -* Fixed "deprecated-copy" warning on GCC 9 (fixes #1184) -* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191) -* Fixed enums serialized as booleans (issue #1197) -* Fixed incorrect string comparison on some platforms (issue #1198) -* Added move-constructor and move-assignment to `BasicJsonDocument` -* Added `BasicJsonDocument::garbageCollect()` (issue #1195) -* Added `StaticJsonDocument::garbageCollect()` -* Changed copy-constructor of `BasicJsonDocument` to preserve the capacity of the source. -* Removed copy-constructor of `JsonDocument` (issue #1189) - -> ### BREAKING CHANGES -> -> #### Copy-constructor of `BasicJsonDocument` -> -> In previous versions, the copy constructor of `BasicJsonDocument` looked at the source's `memoryUsage()` to choose its capacity. -> Now, the copy constructor of `BasicJsonDocument` uses the same capacity as the source. -> -> Example: +> And to create `{"array":[],"object":{}}`, you would write: > > ```c++ -> DynamicJsonDocument doc1(64); -> doc1.set(String("example")); +> // ArduinoJson 6 +> obj.createNestedArray("array"); +> obj.createNestedObject("object"); > -> DynamicJsonDocument doc2 = doc1; -> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14 -> // 64 with ArduinoJson 6.15 -> ``` -> -> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not. -> -> If you use the copy-constructor to optimize your documents, you can use `garbageCollect()` or `shrinkToFit()` instead. -> -> #### Copy-constructor of `JsonDocument` -> -> In previous versions, it was possible to create a function that take a `JsonDocument` by value. -> -> ```c++ -> void myFunction(JsonDocument doc) {} -> ``` -> -> This function gives the wrong clues because it doesn't receive a copy of the `JsonDocument`, only a sliced version. -> It worked because the copy constructor copied the internal pointers, but it was an accident. -> -> From now, if you need to pass a `JsonDocument` to a function, you must use a reference: -> -> ```c++ -> void myFunction(JsonDocument& doc) {} -> ``` - -v6.14.1 (2020-01-27) -------- - -* Fixed regression in UTF16 decoding (issue #1173) -* Fixed `containsKey()` on `JsonVariantConst` -* Added `getElement()` and `getMember()` to `JsonVariantConst` - -v6.14.0 (2020-01-16) -------- - -* Added `BasicJsonDocument::shrinkToFit()` -* Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142) -* Added `ARDUINOJSON_ENABLE_COMMENTS` to enable support for comments (defaults to 0) -* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156) - (No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore) -* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers) - (ArduinoJson now produces standard UTF-8 instead of CESU-8) -* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt` - (This file is used for syntax highlighting in the Arduino IDE) -* Fixed `variant.is()` -* Fixed value returned by `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String` -* Improved speed of `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String` - -> ### BREAKING CHANGES -> -> #### Comments -> -> Support for comments in input is now optional and disabled by default. -> -> If you need support for comments, you must defined `ARDUINOJSON_ENABLE_COMMENTS` to `1`; otherwise, you'll receive `InvalidInput` errors. -> -> ```c++ -> #define ARDUINOJSON_ENABLE_COMMENTS 1 -> #include -> ``` - -v6.13.0 (2019-11-01) -------- - -* Added support for custom writer/reader classes (issue #1088) -* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant` -* Fixed `deserializeJson()` when input contains duplicate keys (issue #1095) -* Improved `deserializeMsgPack()` speed by reading several bytes at once -* Added detection of Atmel AVR8/GNU C Compiler (issue #1112) -* Fixed deserializer that stopped reading at the first `0xFF` (PR #1118 by @mikee47) -* Fixed dangling reference in copies of `MemberProxy` and `ElementProxy` (issue #1120) - -v6.12.0 (2019-09-05) -------- - -* Use absolute instead of relative includes (issue #1072) -* Changed `JsonVariant::as()` to return `true` for any non-null value (issue #1005) -* Moved ancillary files to `extras/` (issue #1011) - -v6.11.5 (2019-08-23) -------- - -* Added fallback implementations of `strlen_P()`, `strncmp_P()`, `strcmp_P()`, and `memcpy_P()` (issue #1073) - -v6.11.4 (2019-08-12) -------- - -* Added `measureJson()` to the `ArduinoJson` namespace (PR #1069 by @nomis) -* Added support for `basic_string` (issue #1045) -* Fixed example `JsonConfigFile.ino` for ESP8266 -* Include `Arduino.h` if `ARDUINO` is defined (PR #1071 by @nomis) - -v6.11.3 (2019-07-22) -------- - -* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy` -* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051) - -v6.11.2 (2019-07-08) -------- - -* Fixed assignment of `JsonDocument` to `JsonVariant` (issue #1023) -* Fix invalid conversion error on Particle Argon (issue #1035) - -v6.11.1 (2019-06-21) -------- - -* Fixed `serialized()` not working with Flash strings (issue #1030) - -v6.11.0 (2019-05-26) -------- - -* Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978) -* Fixed invalid result from `operator|` (issue #981) -* Made `deserializeJson()` more picky about trailing characters (issue #980) -* Added `ARDUINOJSON_ENABLE_NAN` (default=0) to enable NaN in JSON (issue #973) -* Added `ARDUINOJSON_ENABLE_INFINITY` (default=0) to enable Infinity in JSON -* Removed implicit conversion in comparison operators (issue #998) -* Added lexicographical comparison for `JsonVariant` -* Added support for `nullptr` (issue #998) - -> ### BREAKING CHANGES -> -> #### NaN and Infinity -> -> The JSON specification allows neither NaN not Infinity, but previous -> versions of ArduinoJson supported it. Now, ArduinoJson behaves like most -> other libraries: a NaN or and Infinity in the `JsonDocument`, becomes -> a `null` in the output JSON. Also, `deserializeJson()` returns -> `InvalidInput` if the JSON document contains NaN or Infinity. -> -> This version still supports NaN and Infinity in JSON documents, but -> it's disabled by default to be compatible with other JSON parsers. -> If you need the old behavior back, define `ARDUINOJSON_ENABLE_NAN` and -> `ARDUINOJSON_ENABLE_INFINITY` to `1`;: -> -> ```c++ -> #define ARDUINOJSON_ENABLE_NAN 1 -> #define ARDUINOJSON_ENABLE_INFINITY 1 -> #include -> ``` -> -> #### The "or" operator -> -> This version slightly changes the behavior of the | operator when the -> variant contains a float and the user requests an integer. -> -> Older versions returned the floating point value truncated. -> Now, it returns the default value. -> -> ```c++ -> // suppose variant contains 1.2 -> int value = variant | 3; -> -> // old behavior: -> value == 1 -> -> // new behavior -> value == 3 -> ``` -> -> If you need the old behavior, you must add `if (variant.is())`. - -v6.10.1 (2019-04-23) -------- - -* Fixed error "attributes are not allowed on a function-definition" -* Fixed `deserializeJson()` not being picky enough (issue #969) -* Fixed error "no matching function for call to write(uint8_t)" (issue #972) - -v6.10.0 (2019-03-22) -------- - -* Fixed an integer overflow in the JSON deserializer -* Added overflow handling in `JsonVariant::as()` and `JsonVariant::is()`. - - `as()` returns `0` if the integer `T` overflows - - `is()` returns `false` if the integer `T` overflows -* Added `BasicJsonDocument` to support custom allocator (issue #876) -* Added `JsonDocument::containsKey()` (issue #938) -* Added `JsonVariant::containsKey()` - -v6.9.1 (2019-03-01) ------- - -* Fixed warning "unused variable" with GCC 4.4 (issue #912) -* Fixed warning "cast increases required alignment" (issue #914) -* Fixed warning "conversion may alter value" (issue #914) -* Fixed naming conflict with "CAPACITY" (issue #839) -* Muted warning "will change in GCC 7.1" (issue #914) -* Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer` -* Marked ArduinoJson.h as a "system header" - -v6.9.0 (2019-02-26) ------- - -* Decode escaped Unicode characters like \u00DE (issue #304, PR #791) - Many thanks to Daniel Schulte (aka @trilader) who implemented this feature. -* Added option ARDUINOJSON_DECODE_UNICODE to enable it -* Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()` -* Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()` -* Renamed `JsonArray::get()` to `getElement()` -* Renamed `JsonArray::add()` (without arg) to `addElement()` -* Renamed `JsonObject::get()` to `getMember()` -* Renamed `JsonObject::getOrCreate()` to `getOrAddMember()` -* Fixed `JsonVariant::isNull()` not returning `true` after `set((char*)0)` -* Fixed segfault after `variant.set(serialized((char*)0))` -* Detect `IncompleteInput` in `false`, `true`, and `null` -* Added `JsonDocument::size()` -* Added `JsonDocument::remove()` -* Added `JsonVariant::clear()` -* Added `JsonVariant::remove()` - -v6.8.0-beta (2019-01-30) ------------ - -* Import functions in the ArduinoJson namespace to get clearer errors -* Improved syntax highlighting in Arduino IDE -* Removed default capacity of `DynamicJsonDocument` -* `JsonArray::copyFrom()` accepts `JsonArrayConst` -* `JsonVariant::set()` accepts `JsonArrayConst` and `JsonObjectConst` -* `JsonDocument` was missing in the ArduinoJson namespace -* Added `memoryUsage()` to `JsonArray`, `JsonObject`, and `JsonVariant` -* Added `nesting()` to `JsonArray`, `JsonDocument`, `JsonObject`, and `JsonVariant` -* Replaced `JsonDocument::nestingLimit` with an additional parameter - to `deserializeJson()` and `deserializeMsgPack()` -* Fixed uninitialized variant in `JsonDocument` -* Fixed `StaticJsonDocument` copy constructor and copy assignment -* The copy constructor of `DynamicJsonDocument` chooses the capacity according to the memory usage of the source, not from the capacity of the source. -* Added the ability to create/assign a `StaticJsonDocument`/`DynamicJsonDocument` from a `JsonArray`/`JsonObject`/`JsonVariant` -* Added `JsonDocument::isNull()` -* Added `JsonDocument::operator[]` -* Added `ARDUINOJSON_TAB` to configure the indentation character -* Reduced the size of the pretty JSON serializer -* Added `add()`, `createNestedArray()` and `createNestedObject()` to `JsonVariant` -* `JsonVariant` automatically promotes to `JsonObject` or `JsonArray` on write. - Calling `JsonVariant::to()` is not required anymore. -* `JsonDocument` now support the same operations as `JsonVariant`. - Calling `JsonDocument::as()` is not required anymore. -* Fixed example `JsonHttpClient.ino` -* User can now use a `JsonString` as a key or a value - -> ### BREAKING CHANGES -> -> #### `DynamicJsonDocument`'s constructor -> -> The parameter to the constructor of `DynamicJsonDocument` is now mandatory -> -> Old code: -> -> ```c++ -> DynamicJsonDocument doc; -> ``` -> -> New code: -> -> ```c++ -> DynamicJsonDocument doc(1024); -> ``` -> -> #### Nesting limit -> -> `JsonDocument::nestingLimit` was replaced with a new parameter to `deserializeJson()` and `deserializeMsgPack()`. -> -> Old code: -> -> ```c++ -> doc.nestingLimit = 15; -> deserializeJson(doc, input); -> ``` -> -> New code: -> -> ```c++ -> deserializeJson(doc, input, DeserializationOption::NestingLimit(15)); -> ``` - -v6.7.0-beta (2018-12-07) ------------ - -* Removed the automatic expansion of `DynamicJsonDocument`, it now has a fixed capacity. -* Restored the monotonic allocator because the code was getting too big -* Reduced the memory usage -* Reduced the code size -* Renamed `JsonKey` to `JsonString` -* Removed spurious files in the Particle library - -v6.6.0-beta (2018-11-13) ------------ - -* Removed `JsonArray::is(i)` and `JsonArray::set(i,v)` -* Removed `JsonObject::is(k)` and `JsonObject::set(k,v)` -* Replaced `T JsonArray::get(i)` with `JsonVariant JsonArray::get(i)` -* Replaced `T JsonObject::get(k)` with `JsonVariant JsonObject::get(k)` -* Added `JSON_STRING_SIZE()` -* ~~Replacing or removing a value now releases the memory~~ -* Added `DeserializationError::code()` to be used in switch statements (issue #846) - -v6.5.0-beta (2018-10-13) ------------ - -* Added implicit conversion from `JsonArray` and `JsonObject` to `JsonVariant` -* Allow mixed configuration in compilation units (issue #809) -* Fixed object keys not being duplicated -* `JsonPair::key()` now returns a `JsonKey` -* Increased the default capacity of `DynamicJsonDocument` -* Fixed `JsonVariant::is()` (closes #763) -* Added `JsonArrayConst`, `JsonObjectConst`, and `JsonVariantConst` -* Added copy-constructor and copy-assignment-operator for `JsonDocument` (issue #827) - -v6.4.0-beta (2018-09-11) ------------ - -* Copy `JsonArray` and `JsonObject`, instead of storing pointers (issue #780) -* Added `JsonVariant::to()` and `JsonVariant::to()` - -v6.3.0-beta (2018-08-31) ------------ - -* Implemented reference semantics for `JsonVariant` -* Replaced `JsonPair`'s `key` and `value` with `key()` and `value()` -* Fixed `serializeJson(obj[key], dst)` (issue #794) - -> ### BREAKING CHANGES -> -> #### JsonVariant -> -> `JsonVariant` now has a semantic similar to `JsonObject` and `JsonArray`. -> It's a reference to a value stored in the `JsonDocument`. -> As a consequence, a `JsonVariant` cannot be used as a standalone variable anymore. -> -> Old code: -> -> ```c++ -> JsonVariant myValue = 42; -> ``` -> -> New code: -> -> ```c++ -> DynamicJsonDocument doc; -> JsonVariant myValue = doc.to(); -> myValue.set(42); -> ``` -> -> #### JsonPair -> -> Old code: -> -> ```c++ -> for(JsonPair p : myObject) { -> Serial.println(p.key); -> Serial.println(p.value.as()); -> } -> ``` -> -> New code: -> -> ```c++ -> for(JsonPair p : myObject) { -> Serial.println(p.key()); -> Serial.println(p.value().as()); -> } -> ``` -> -> CAUTION: the key is now read only! - -v6.2.3-beta (2018-07-19) ------------ - -* Fixed exception when using Flash strings as object keys (issue #784) - -v6.2.2-beta (2018-07-18) ------------ - -* Fixed `invalid application of 'sizeof' to incomplete type '__FlashStringHelper'` (issue #783) -* Fixed `char[]` not duplicated when passed to `JsonVariant::operator[]` - -v6.2.1-beta (2018-07-17) ------------ - -* Fixed `JsonObject` not inserting keys of type `String` (issue #782) - -v6.2.0-beta (2018-07-12) ------------ - -* Disabled lazy number deserialization (issue #772) -* Fixed `JsonVariant::is()` that returned true for empty strings -* Improved float serialization when `-fsingle-precision-constant` is used -* Renamed function `RawJson()` to `serialized()` -* `serializeMsgPack()` now supports values marked with `serialized()` - -> ### BREAKING CHANGES -> -> #### Non quoted strings -> -> Non quoted strings are now forbidden in values, but they are still allowed in keys. -> For example, `{key:"value"}` is accepted, but `{key:value}` is not. -> -> #### Preformatted values -> -> Old code: -> -> ```c++ -> object["values"] = RawJson("[1,2,3,4]"); -> ``` -> -> New code: -> -> ```c++ -> object["values"] = serialized("[1,2,3,4]"); -> ``` - -v6.1.0-beta (2018-07-02) ------------ - -* Return `JsonArray` and `JsonObject` by value instead of reference (issue #309) -* Replaced `success()` with `isNull()` - -> ### BREAKING CHANGES -> -> Old code: -> -> ```c++ -> JsonObject& obj = doc.to(); -> JsonArray& arr = obj.createNestedArray("key"); -> if (!arr.success()) { -> Serial.println("Not enough memory"); -> return; -> } -> ``` -> -> New code: -> -> ```c++ -> JsonObject obj = doc.to(); -> JsonArray arr = obj.createNestedArray("key"); -> if (arr.isNull()) { -> Serial.println("Not enough memory"); -> return; -> } -> ``` - -v6.0.1-beta (2018-06-11) ------------ - -* Fixed conflicts with `isnan()` and `isinf()` macros (issue #752) - -v6.0.0-beta (2018-06-07) ------------ - -* Added `DynamicJsonDocument` and `StaticJsonDocument` -* Added `deserializeJson()` -* Added `serializeJson()` and `serializeJsonPretty()` -* Added `measureJson()` and `measureJsonPretty()` -* Added `serializeMsgPack()`, `deserializeMsgPack()` and `measureMsgPack()` (issue #358) -* Added example `MsgPackParser.ino` (issue #358) -* Added support for non zero-terminated strings (issue #704) -* Removed `JsonBuffer::parseArray()`, `parseObject()` and `parse()` -* Removed `JsonBuffer::createArray()` and `createObject()` -* Removed `printTo()` and `prettyPrintTo()` -* Removed `measureLength()` and `measurePrettyLength()` -* Removed all deprecated features - -> ### BREAKING CHANGES -> -> #### Deserialization -> -> Old code: -> -> ```c++ -> DynamicJsonBuffer jb; -> JsonObject& obj = jb.parseObject(json); -> if (obj.success()) { -> -> } -> ``` -> -> New code: -> -> ```c++ -> DynamicJsonDocument doc; -> DeserializationError error = deserializeJson(doc, json); -> if (error) { -> -> } -> JsonObject& obj = doc.as(); -> ``` -> -> #### Serialization -> -> Old code: -> -> ```c++ -> DynamicJsonBuffer jb; -> JsonObject& obj = jb.createObject(); -> obj["key"] = "value"; -> obj.printTo(Serial); -> ``` -> -> New code: -> -> ```c++ -> DynamicJsonDocument obj; -> JsonObject& obj = doc.to(); -> obj["key"] = "value"; -> serializeJson(doc, Serial); +> // ArduinoJson 7 +> obj["array"].to(); +> obj["object"].to(); > ``` diff --git a/lib/ArduinoJson/CONTRIBUTING.md b/lib/ArduinoJson/CONTRIBUTING.md new file mode 100644 index 000000000..d32a04ff1 --- /dev/null +++ b/lib/ArduinoJson/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# Contribution to ArduinoJson + +First, thank you for taking the time to contribute to this project. + +You can submit changes via GitHub Pull Requests. + +Please: + +1. Update the test suite for any change of behavior +2. Use clang-format in "file" mode to format the code diff --git a/lib/ArduinoJson/LICENSE.txt b/lib/ArduinoJson/LICENSE.txt index 15f1b9fbb..56bb92b7f 100644 --- a/lib/ArduinoJson/LICENSE.txt +++ b/lib/ArduinoJson/LICENSE.txt @@ -1,7 +1,7 @@ The MIT License (MIT) --------------------- -Copyright © 2014-2023, Benoit BLANCHON +Copyright © 2014-2024, Benoit BLANCHON Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/lib/ArduinoJson/README.md b/lib/ArduinoJson/README.md index 16d93a3a6..a490af33f 100644 --- a/lib/ArduinoJson/README.md +++ b/lib/ArduinoJson/README.md @@ -4,13 +4,10 @@ --- -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bblanchon/ArduinoJson/ci.yml?branch=6.x&logo=github)](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) +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bblanchon/ArduinoJson/ci.yml?branch=7.x&logo=github)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A7.x) +[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/7.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.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) -[![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/6.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.21.3&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.21.3) -[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.21.3)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.3) -[![ESP IDF](https://img.shields.io/static/v1?label=ESP+IDF&message=v6.21.3&logo=cpu&logoColor=white&color=blue)](https://components.espressif.com/components/bblanchon/arduinojson) +[![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/7.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x) [![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github&color=orange)](https://github.com/bblanchon/ArduinoJson/stargazers) [![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github&color=orange)](https://github.com/sponsors/bblanchon) @@ -18,31 +15,28 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). ## Features -* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/) - * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/) - * [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/) - * [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/) - * [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering) +* [JSON deserialization](https://arduinojson.org/v7/api/json/deserializejson/) + * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v7/api/config/decode_unicode/) + * [Optionally supports comments in the input](https://arduinojson.org/v7/api/config/enable_comments/) + * [Optionally filters the input to keep only desired values](https://arduinojson.org/v7/api/json/deserializejson/#filtering) * Supports single quotes as a string delimiter * Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/) -* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/) - * [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/) - * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/) -* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/) -* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/) +* [JSON serialization](https://arduinojson.org/v7/api/json/serializejson/) + * [Can write to a buffer or a stream](https://arduinojson.org/v7/api/json/serializejson/) + * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v7/api/json/serializejsonpretty/) +* [MessagePack serialization](https://arduinojson.org/v7/api/msgpack/serializemsgpack/) +* [MessagePack deserialization](https://arduinojson.org/v7/api/msgpack/deserializemsgpack/) * Efficient * [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/) * [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/) * [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/) - * [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/) - * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/) * [Deduplicates strings](https://arduinojson.org/news/2020/08/01/version-6-16-0/) * Versatile - * Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/) - * Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/) - * Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/) - * Supports [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/) - * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer) + * Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v7/how-to/use-external-ram-on-esp32/) + * Supports [`String`](https://arduinojson.org/v7/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v7/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v7/api/config/enable_string_view/) + * Supports [`Stream`](https://arduinojson.org/v7/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v7/api/config/enable_std_stream/) + * Supports [Flash strings](https://arduinojson.org/v7/api/config/enable_progmem/) + * Supports [custom readers](https://arduinojson.org/v7/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v7/api/json/serializejson/#custom-writer) * Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/) * Portable * Usable on any C++ project (not limited to Arduino) @@ -72,29 +66,29 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). * [Visual Micro](http://www.visualmicro.com/) * [Visual Studio](https://www.visualstudio.com/) * [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN) - * [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/) + * [CMake friendly](https://arduinojson.org/v7/how-to/use-arduinojson-with-cmake/) * Well designed - * [Elegant API](http://arduinojson.org/v6/example/) + * [Elegant API](http://arduinojson.org/v7/example/) * [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety) * Self-contained (no external dependency) * `const` friendly - * [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/) + * [`for` friendly](https://arduinojson.org/v7/api/jsonobject/begin_end/) * [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming) - * Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows) + * Handles [integer overflows](https://arduinojson.org/v7/api/jsonvariant/as/#integer-overflows) * Well tested - * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) + * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x) * Continuously tested on - * [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) - * [GCC 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) - * [Clang 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) + * [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x) + * [GCC 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) + * [Clang 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10, 11, 12, 13, 14, 15](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22) * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) * Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/) * Well documented - * [Tutorials](https://arduinojson.org/v6/doc/deserialization/) - * [Examples](https://arduinojson.org/v6/example/) - * [How-tos](https://arduinojson.org/v6/example/) - * [FAQ](https://arduinojson.org/v6/faq/) - * [Troubleshooter](https://arduinojson.org/v6/troubleshooter/) + * [Tutorials](https://arduinojson.org/v7/doc/deserialization/) + * [Examples](https://arduinojson.org/v7/example/) + * [How-tos](https://arduinojson.org/v7/example/) + * [FAQ](https://arduinojson.org/v7/faq/) + * [Troubleshooter](https://arduinojson.org/v7/troubleshooter/) * [Book](https://arduinojson.org/book/) * [Changelog](CHANGELOG.md) * Vibrant user community @@ -109,9 +103,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). Here is a program that parses a JSON document with ArduinoJson. ```c++ -char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; +const char* json = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; -DynamicJsonDocument doc(1024); +JsonDocument doc; deserializeJson(doc, json); const char* sensor = doc["sensor"]; @@ -120,14 +114,14 @@ double latitude = doc["data"][0]; double longitude = doc["data"][1]; ``` -See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/deserialization/) +See the [tutorial on arduinojson.org](https://arduinojson.org/v7/doc/deserialization/) ### Serialization Here is a program that generates a JSON document with ArduinoJson: ```c++ -DynamicJsonDocument doc(1024); +JsonDocument doc; doc["sensor"] = "gps"; doc["time"] = 1351824120; @@ -139,7 +133,7 @@ serializeJson(doc, Serial); // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} ``` -See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/serialization/) +See the [tutorial on arduinojson.org](https://arduinojson.org/v7/doc/serialization/) ## Sponsors diff --git a/lib/ArduinoJson/SUPPORT.md b/lib/ArduinoJson/SUPPORT.md new file mode 100644 index 000000000..c47e1b1ba --- /dev/null +++ b/lib/ArduinoJson/SUPPORT.md @@ -0,0 +1,27 @@ +# ArduinoJson Support + +First off, thank you very much for using ArduinoJson. + +We'll be very happy to help you, but first please read the following. + +## Before asking for help + +1. Read the [FAQ](https://arduinojson.org/faq/?utm_source=github&utm_medium=support) +2. Search in the [API Reference](https://arduinojson.org/api/?utm_source=github&utm_medium=support) + +If you did not find the answer, please create a [new issue on GitHub](https://github.com/bblanchon/ArduinoJson/issues/new). + +It is OK to add a comment to a currently opened issue, but please avoid adding comments to a closed issue. + +## Before hitting the Submit button + +Please provide all the relevant information: + +* Good title +* Short description of the problem +* Target platform +* Compiler model and version +* [MVCE](https://stackoverflow.com/help/mcve) +* Compiler output + +Good questions get fast answers! diff --git a/lib/ArduinoJson/keywords.txt b/lib/ArduinoJson/keywords.txt deleted file mode 100644 index 3dff06bfc..000000000 --- a/lib/ArduinoJson/keywords.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Macros -JSON_ARRAY_SIZE KEYWORD2 -JSON_OBJECT_SIZE KEYWORD2 -JSON_STRING_SIZE KEYWORD2 - -# Free functions -deserializeJson KEYWORD2 -deserializeMsgPack KEYWORD2 -serialized KEYWORD2 -serializeJson KEYWORD2 -serializeJsonPretty KEYWORD2 -serializeMsgPack KEYWORD2 -measureJson KEYWORD2 -measureJsonPretty KEYWORD2 -measureMsgPack KEYWORD2 - -# Methods -add KEYWORD2 -as KEYWORD2 -createNestedArray KEYWORD2 -createNestedObject KEYWORD2 -get KEYWORD2 -set KEYWORD2 -to KEYWORD2 - -# Type names -DeserializationError KEYWORD1 DATA_TYPE -DynamicJsonDocument KEYWORD1 DATA_TYPE -JsonArray KEYWORD1 DATA_TYPE -JsonArrayConst KEYWORD1 DATA_TYPE -JsonDocument KEYWORD1 DATA_TYPE -JsonFloat KEYWORD1 DATA_TYPE -JsonInteger KEYWORD1 DATA_TYPE -JsonObject KEYWORD1 DATA_TYPE -JsonObjectConst KEYWORD1 DATA_TYPE -JsonString KEYWORD1 DATA_TYPE -JsonUInt KEYWORD1 DATA_TYPE -JsonVariant KEYWORD1 DATA_TYPE -JsonVariantConst KEYWORD1 DATA_TYPE -StaticJsonDocument KEYWORD1 DATA_TYPE diff --git a/lib/ArduinoJson/library.properties b/lib/ArduinoJson/library.properties deleted file mode 100644 index 6a285cf0d..000000000 --- a/lib/ArduinoJson/library.properties +++ /dev/null @@ -1,11 +0,0 @@ -name=ArduinoJson -version=6.21.3 -author=Benoit Blanchon -maintainer=Benoit Blanchon -sentence=A simple and efficient JSON library for embedded C++. -paragraph=ArduinoJson supports ✔ serialization, ✔ deserialization, ✔ MessagePack, ✔ fixed allocation, ✔ zero-copy, ✔ streams, ✔ filtering, and more. It is the most popular Arduino library on GitHub ❤❤❤❤❤. Check out arduinojson.org for a comprehensive documentation. -category=Data Processing -url=https://arduinojson.org/?utm_source=meta&utm_medium=library.properties -architectures=* -repository=https://github.com/bblanchon/ArduinoJson.git -license=MIT diff --git a/lib/ArduinoJson/src/ArduinoJson.h b/lib/ArduinoJson/src/ArduinoJson.h index c9ac0ca64..fec64c3d1 100644 --- a/lib/ArduinoJson/src/ArduinoJson.h +++ b/lib/ArduinoJson/src/ArduinoJson.h @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson.hpp b/lib/ArduinoJson/src/ArduinoJson.hpp index 2d1b0be13..c210ed266 100644 --- a/lib/ArduinoJson/src/ArduinoJson.hpp +++ b/lib/ArduinoJson/src/ArduinoJson.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -30,18 +30,19 @@ #include "ArduinoJson/Object/JsonObject.hpp" #include "ArduinoJson/Variant/JsonVariantConst.hpp" -#include "ArduinoJson/Document/DynamicJsonDocument.hpp" -#include "ArduinoJson/Document/StaticJsonDocument.hpp" +#include "ArduinoJson/Document/JsonDocument.hpp" +#include "ArduinoJson/Array/ArrayImpl.hpp" #include "ArduinoJson/Array/ElementProxy.hpp" -#include "ArduinoJson/Array/JsonArrayImpl.hpp" #include "ArduinoJson/Array/Utilities.hpp" #include "ArduinoJson/Collection/CollectionImpl.hpp" -#include "ArduinoJson/Object/JsonObjectImpl.hpp" +#include "ArduinoJson/Memory/VariantPoolImpl.hpp" #include "ArduinoJson/Object/MemberProxy.hpp" +#include "ArduinoJson/Object/ObjectImpl.hpp" #include "ArduinoJson/Variant/ConverterImpl.hpp" +#include "ArduinoJson/Variant/JsonVariantCopier.hpp" #include "ArduinoJson/Variant/VariantCompare.hpp" -#include "ArduinoJson/Variant/VariantImpl.hpp" +#include "ArduinoJson/Variant/VariantRefBaseImpl.hpp" #include "ArduinoJson/Json/JsonDeserializer.hpp" #include "ArduinoJson/Json/JsonSerializer.hpp" diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp new file mode 100644 index 000000000..93a65d543 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayData.hpp @@ -0,0 +1,57 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include + +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + +class ArrayData : public CollectionData { + public: + VariantData* addElement(ResourceManager* resources) { + return addSlot(resources).data(); + } + + static VariantData* addElement(ArrayData* array, ResourceManager* resources) { + if (!array) + return nullptr; + return array->addElement(resources); + } + + VariantData* getOrAddElement(size_t index, ResourceManager* resources); + + VariantData* getElement(size_t index, const ResourceManager* resources) const; + + static VariantData* getElement(const ArrayData* array, size_t index, + const ResourceManager* resources) { + if (!array) + return nullptr; + return array->getElement(index, resources); + } + + void removeElement(size_t index, ResourceManager* resources); + + static void removeElement(ArrayData* array, size_t index, + ResourceManager* resources) { + if (!array) + return; + array->removeElement(index, resources); + } + + bool copyFrom(const ArrayData& src, ResourceManager* resources); + + static bool copy(ArrayData* dst, const ArrayData* src, + ResourceManager* resources) { + if (!dst || !src) + return false; + + return dst->copyFrom(*src, resources); + } + + private: + iterator at(size_t index, const ResourceManager* resources) const; +}; + +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp new file mode 100644 index 000000000..595e847b3 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp @@ -0,0 +1,50 @@ +// ArduinoJson - https://arduinojson.org +// Copyright © 2014-2024, Benoit BLANCHON +// MIT License + +#pragma once + +#include +#include + +ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE + +inline ArrayData::iterator ArrayData::at( + size_t index, const ResourceManager* resources) const { + auto it = createIterator(resources); + while (!it.done() && index) { + it.next(resources); + --index; + } + return it; +} + +inline VariantData* ArrayData::getOrAddElement(size_t index, + ResourceManager* resources) { + auto it = createIterator(resources); + while (!it.done() && index > 0) { + it.next(resources); + index--; + } + if (it.done()) + index++; + VariantData* element = it.data(); + while (index > 0) { + element = addElement(resources); + if (!element) + return nullptr; + index--; + } + return element; +} + +inline VariantData* ArrayData::getElement( + size_t index, const ResourceManager* resources) const { + return at(index, resources).data(); +} + +inline void ArrayData::removeElement(size_t index, ResourceManager* resources) { + remove(at(index, resources), resources); +} + +ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp index d6e9aa5d1..2ae26624a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -9,7 +9,7 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE // A proxy class to get or set an element of an array. -// https://arduinojson.org/v6/api/jsonarray/subscript/ +// https://arduinojson.org/v7/api/jsonarray/subscript/ template class ElementProxy : public VariantRefBase>, public VariantOperators> { @@ -40,17 +40,22 @@ class ElementProxy : public VariantRefBase>, } private: - FORCE_INLINE MemoryPool* getPool() const { - return VariantAttorney::getPool(upstream_); + FORCE_INLINE ResourceManager* getResourceManager() const { + return VariantAttorney::getResourceManager(upstream_); } FORCE_INLINE VariantData* getData() const { - return variantGetElement(VariantAttorney::getData(upstream_), index_); + return VariantData::getElement( + VariantAttorney::getData(upstream_), index_, + VariantAttorney::getResourceManager(upstream_)); } FORCE_INLINE VariantData* getOrCreateData() const { - return variantGetOrAddElement(VariantAttorney::getOrCreateData(upstream_), - index_, VariantAttorney::getPool(upstream_)); + auto data = VariantAttorney::getOrCreateData(upstream_); + if (!data) + return nullptr; + return data->getOrAddElement( + index_, VariantAttorney::getResourceManager(upstream_)); } TUpstream upstream_; diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp index d208e4175..069c353de 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArray.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -12,7 +12,7 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE class JsonObject; // A reference to an array in a JsonDocument -// https://arduinojson.org/v6/api/jsonarray/ +// https://arduinojson.org/v7/api/jsonarray/ class JsonArray : public detail::VariantOperators { friend class detail::VariantAttorney; @@ -20,155 +20,166 @@ class JsonArray : public detail::VariantOperators { typedef JsonArrayIterator iterator; // Constructs an unbound reference. - FORCE_INLINE JsonArray() : data_(0), pool_(0) {} + FORCE_INLINE JsonArray() : data_(0), resources_(0) {} // INTERNAL USE ONLY - FORCE_INLINE JsonArray(detail::MemoryPool* pool, detail::CollectionData* data) - : data_(data), pool_(pool) {} + FORCE_INLINE JsonArray(detail::ArrayData* data, + detail::ResourceManager* resources) + : data_(data), resources_(resources) {} // Returns a JsonVariant pointing to the array. - // https://arduinojson.org/v6/api/jsonvariant/ + // https://arduinojson.org/v7/api/jsonvariant/ operator JsonVariant() { void* data = data_; // prevent warning cast-align - return JsonVariant(pool_, reinterpret_cast(data)); + return JsonVariant(reinterpret_cast(data), + resources_); } // Returns a read-only reference to the array. - // https://arduinojson.org/v6/api/jsonarrayconst/ + // https://arduinojson.org/v7/api/jsonarrayconst/ operator JsonArrayConst() const { - return JsonArrayConst(data_); + return JsonArrayConst(data_, resources_); + } + + // Appends a new (empty) element to the array. + // Returns a reference to the new element. + // https://arduinojson.org/v7/api/jsonarray/add/ + template + typename detail::enable_if::value, T>::type + add() const { + return add().to(); } // Appends a new (null) element to the array. // Returns a reference to the new element. - // https://arduinojson.org/v6/api/jsonarray/add/ - JsonVariant add() const { - if (!data_) - return JsonVariant(); - return JsonVariant(pool_, data_->addElement(pool_)); + // https://arduinojson.org/v7/api/jsonarray/add/ + template + typename detail::enable_if::value, T>::type + add() const { + return JsonVariant(detail::ArrayData::addElement(data_, resources_), + resources_); } // Appends a value to the array. - // https://arduinojson.org/v6/api/jsonarray/add/ + // https://arduinojson.org/v7/api/jsonarray/add/ template FORCE_INLINE bool add(const T& value) const { - return add().set(value); + return add().set(value); } // Appends a value to the array. - // https://arduinojson.org/v6/api/jsonarray/add/ + // https://arduinojson.org/v7/api/jsonarray/add/ template FORCE_INLINE bool add(T* value) const { - return add().set(value); + return add().set(value); } // Returns an iterator to the first element of the array. - // https://arduinojson.org/v6/api/jsonarray/begin/ + // https://arduinojson.org/v7/api/jsonarray/begin/ FORCE_INLINE iterator begin() const { if (!data_) return iterator(); - return iterator(pool_, data_->head()); + return iterator(data_->createIterator(resources_), resources_); } // Returns an iterator following the last element of the array. - // https://arduinojson.org/v6/api/jsonarray/end/ + // https://arduinojson.org/v7/api/jsonarray/end/ FORCE_INLINE iterator end() const { return iterator(); } // Copies an array. - // https://arduinojson.org/v6/api/jsonarray/set/ + // https://arduinojson.org/v7/api/jsonarray/set/ FORCE_INLINE bool set(JsonArrayConst src) const { - if (!data_ || !src.data_) + if (!data_) return false; - return data_->copyFrom(*src.data_, pool_); - } - // Compares the content of two arrays. - FORCE_INLINE bool operator==(JsonArray rhs) const { - return JsonArrayConst(data_) == JsonArrayConst(rhs.data_); + clear(); + for (auto element : src) { + if (!add(element)) + return false; + } + + return true; } // Removes the element at the specified iterator. - // ⚠️ Doesn't release the memory associated with the removed element. - // https://arduinojson.org/v6/api/jsonarray/remove/ + // https://arduinojson.org/v7/api/jsonarray/remove/ FORCE_INLINE void remove(iterator it) const { - if (!data_) - return; - data_->removeSlot(it.slot_); + detail::ArrayData::remove(data_, it.iterator_, resources_); } // Removes the element at the specified index. - // ⚠️ Doesn't release the memory associated with the removed element. - // https://arduinojson.org/v6/api/jsonarray/remove/ + // https://arduinojson.org/v7/api/jsonarray/remove/ FORCE_INLINE void remove(size_t index) const { - if (!data_) - return; - data_->removeElement(index); + detail::ArrayData::removeElement(data_, index, resources_); } // Removes all the elements of the array. - // ⚠️ Doesn't release the memory associated with the removed elements. - // https://arduinojson.org/v6/api/jsonarray/clear/ + // https://arduinojson.org/v7/api/jsonarray/clear/ void clear() const { - if (!data_) - return; - data_->clear(); + detail::ArrayData::clear(data_, resources_); } // Gets or sets the element at the specified index. - // https://arduinojson.org/v6/api/jsonarray/subscript/ + // https://arduinojson.org/v7/api/jsonarray/subscript/ FORCE_INLINE detail::ElementProxy operator[](size_t index) const { return {*this, index}; } - // Creates an object and appends it to the array. - // https://arduinojson.org/v6/api/jsonarray/createnestedobject/ - FORCE_INLINE JsonObject createNestedObject() const; - - // Creates an array and appends it to the array. - // https://arduinojson.org/v6/api/jsonarray/createnestedarray/ - FORCE_INLINE JsonArray createNestedArray() const { - return add().to(); - } - operator JsonVariantConst() const { - return JsonVariantConst(collectionToVariant(data_)); + return JsonVariantConst(collectionToVariant(data_), resources_); } // Returns true if the reference is unbound. - // https://arduinojson.org/v6/api/jsonarray/isnull/ + // https://arduinojson.org/v7/api/jsonarray/isnull/ FORCE_INLINE bool isNull() const { return data_ == 0; } // Returns true if the reference is bound. - // https://arduinojson.org/v6/api/jsonarray/isnull/ + // https://arduinojson.org/v7/api/jsonarray/isnull/ FORCE_INLINE operator bool() const { return data_ != 0; } - // Returns the number of bytes occupied by the array. - // https://arduinojson.org/v6/api/jsonarray/memoryusage/ - FORCE_INLINE size_t memoryUsage() const { - return data_ ? data_->memoryUsage() : 0; - } - // Returns the depth (nesting level) of the array. - // https://arduinojson.org/v6/api/jsonarray/nesting/ + // https://arduinojson.org/v7/api/jsonarray/nesting/ FORCE_INLINE size_t nesting() const { - return variantNesting(collectionToVariant(data_)); + return detail::VariantData::nesting(collectionToVariant(data_), resources_); } // Returns the number of elements in the array. - // https://arduinojson.org/v6/api/jsonarray/size/ + // https://arduinojson.org/v7/api/jsonarray/size/ FORCE_INLINE size_t size() const { - return data_ ? data_->size() : 0; + return data_ ? data_->size(resources_) : 0; + } + + // DEPRECATED: use add() instead + ARDUINOJSON_DEPRECATED("use add() instead") + JsonVariant add() const { + return add(); + } + + // DEPRECATED: use add() instead + ARDUINOJSON_DEPRECATED("use add() instead") + JsonArray createNestedArray() const { + return add(); + } + + // DEPRECATED: use add() instead + ARDUINOJSON_DEPRECATED("use add() instead") + JsonObject createNestedObject() const; + + // DEPRECATED: always returns zero + ARDUINOJSON_DEPRECATED("always returns zero") + size_t memoryUsage() const { + return 0; } private: - detail::MemoryPool* getPool() const { - return pool_; + detail::ResourceManager* getResourceManager() const { + return resources_; } detail::VariantData* getData() const { @@ -179,33 +190,8 @@ class JsonArray : public detail::VariantOperators { return collectionToVariant(data_); } - detail::CollectionData* data_; - detail::MemoryPool* pool_; -}; - -template <> -struct Converter : private detail::VariantAttorney { - static void toJson(JsonVariantConst src, JsonVariant dst) { - variantCopyFrom(getData(dst), getData(src), getPool(dst)); - } - - static JsonArray fromJson(JsonVariant src) { - auto data = getData(src); - auto pool = getPool(src); - return JsonArray(pool, data != 0 ? data->asArray() : 0); - } - - static detail::InvalidConversion fromJson( - JsonVariantConst); - - static bool checkJson(JsonVariantConst) { - return false; - } - - static bool checkJson(JsonVariant src) { - auto data = getData(src); - return data && data->isArray(); - } + detail::ArrayData* data_; + detail::ResourceManager* resources_; }; ARDUINOJSON_END_PUBLIC_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp index 6a6463c8c..e988e8621 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayConst.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -13,7 +13,7 @@ ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE class JsonObject; // A read-only reference to an array in a JsonDocument -// https://arduinojson.org/v6/api/jsonarrayconst/ +// https://arduinojson.org/v7/api/jsonarrayconst/ class JsonArrayConst : public detail::VariantOperators { friend class JsonArray; friend class detail::VariantAttorney; @@ -22,15 +22,15 @@ class JsonArrayConst : public detail::VariantOperators { typedef JsonArrayConstIterator iterator; // Returns an iterator to the first element of the array. - // https://arduinojson.org/v6/api/jsonarrayconst/begin/ + // https://arduinojson.org/v7/api/jsonarrayconst/begin/ FORCE_INLINE iterator begin() const { if (!data_) return iterator(); - return iterator(data_->head()); + return iterator(data_->createIterator(resources_), resources_); } // Returns an iterator to the element following the last element of the array. - // https://arduinojson.org/v6/api/jsonarrayconst/end/ + // https://arduinojson.org/v7/api/jsonarrayconst/end/ FORCE_INLINE iterator end() const { return iterator(); } @@ -39,72 +39,49 @@ class JsonArrayConst : public detail::VariantOperators { FORCE_INLINE JsonArrayConst() : data_(0) {} // INTERNAL USE ONLY - FORCE_INLINE JsonArrayConst(const detail::CollectionData* data) - : data_(data) {} - - // Compares the content of two arrays. - // Returns true if the two arrays are equal. - FORCE_INLINE bool operator==(JsonArrayConst rhs) const { - if (data_ == rhs.data_) - return true; - if (!data_ || !rhs.data_) - return false; - - iterator it1 = begin(); - iterator it2 = rhs.begin(); - - for (;;) { - bool end1 = it1 == end(); - bool end2 = it2 == rhs.end(); - if (end1 && end2) - return true; - if (end1 || end2) - return false; - if (*it1 != *it2) - return false; - ++it1; - ++it2; - } - } + FORCE_INLINE JsonArrayConst(const detail::ArrayData* data, + const detail::ResourceManager* resources) + : data_(data), resources_(resources) {} // Returns the element at the specified index. - // https://arduinojson.org/v6/api/jsonarrayconst/subscript/ + // https://arduinojson.org/v7/api/jsonarrayconst/subscript/ FORCE_INLINE JsonVariantConst operator[](size_t index) const { - return JsonVariantConst(data_ ? data_->getElement(index) : 0); + return JsonVariantConst( + detail::ArrayData::getElement(data_, index, resources_), resources_); } operator JsonVariantConst() const { - return JsonVariantConst(collectionToVariant(data_)); + return JsonVariantConst(collectionToVariant(data_), resources_); } // Returns true if the reference is unbound. - // https://arduinojson.org/v6/api/jsonarrayconst/isnull/ + // https://arduinojson.org/v7/api/jsonarrayconst/isnull/ FORCE_INLINE bool isNull() const { return data_ == 0; } // Returns true if the reference is bound. - // https://arduinojson.org/v6/api/jsonarrayconst/isnull/ + // https://arduinojson.org/v7/api/jsonarrayconst/isnull/ FORCE_INLINE operator bool() const { return data_ != 0; } - // Returns the number of bytes occupied by the array. - // https://arduinojson.org/v6/api/jsonarrayconst/memoryusage/ - FORCE_INLINE size_t memoryUsage() const { - return data_ ? data_->memoryUsage() : 0; - } - // Returns the depth (nesting level) of the array. - // https://arduinojson.org/v6/api/jsonarrayconst/nesting/ + // https://arduinojson.org/v7/api/jsonarrayconst/nesting/ FORCE_INLINE size_t nesting() const { - return variantNesting(collectionToVariant(data_)); + return detail::VariantData::nesting(collectionToVariant(data_), resources_); } // Returns the number of elements in the array. - // https://arduinojson.org/v6/api/jsonarrayconst/size/ + // https://arduinojson.org/v7/api/jsonarrayconst/size/ FORCE_INLINE size_t size() const { - return data_ ? data_->size() : 0; + return data_ ? data_->size(resources_) : 0; + } + + // DEPRECATED: always returns zero + ARDUINOJSON_DEPRECATED("always returns zero") + size_t memoryUsage() const { + return 0; } private: @@ -112,24 +89,31 @@ class JsonArrayConst : public detail::VariantOperators { return collectionToVariant(data_); } - const detail::CollectionData* data_; + const detail::ArrayData* data_; + const detail::ResourceManager* resources_; }; -template <> -struct Converter : private detail::VariantAttorney { - static void toJson(JsonVariantConst src, JsonVariant dst) { - variantCopyFrom(getData(dst), getData(src), getPool(dst)); - } +// Compares the content of two arrays. +// Returns true if the two arrays are equal. +inline bool operator==(JsonArrayConst lhs, JsonArrayConst rhs) { + if (!lhs && !rhs) + return true; + if (!lhs || !rhs) + return false; - static JsonArrayConst fromJson(JsonVariantConst src) { - auto data = getData(src); - return data ? data->asArray() : 0; - } + auto a = lhs.begin(); + auto b = rhs.begin(); - static bool checkJson(JsonVariantConst src) { - auto data = getData(src); - return data && data->isArray(); + for (;;) { + if (a == b) // same pointer or both null + return true; + if (a == lhs.end() || b == rhs.end()) + return false; + if (*a != *b) + return false; + ++a; + ++b; } -}; +} ARDUINOJSON_END_PUBLIC_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp deleted file mode 100644 index dc0487af8..000000000 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayImpl.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#pragma once - -#include -#include - -ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE - -inline JsonObject JsonArray::createNestedObject() const { - return add().to(); -} - -ARDUINOJSON_END_PUBLIC_NAMESPACE - -ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE - -template -inline JsonArray VariantRefBase::createNestedArray() const { - return add().template to(); -} - -template -inline JsonObject VariantRefBase::createNestedObject() const { - return add().template to(); -} - -template -inline ElementProxy VariantRefBase::operator[]( - size_t index) const { - return ElementProxy(derived(), index); -} - -ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp index d9048b28c..70bb28f4a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/JsonArrayIterator.hpp @@ -1,121 +1,96 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once #include -#include ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE -class VariantPtr { +template +class Ptr { public: - VariantPtr(detail::MemoryPool* pool, detail::VariantData* data) - : variant_(pool, data) {} + Ptr(T value) : value_(value) {} - JsonVariant* operator->() { - return &variant_; + T* operator->() { + return &value_; } - JsonVariant& operator*() { - return variant_; + T& operator*() { + return value_; } private: - JsonVariant variant_; + T value_; }; class JsonArrayIterator { friend class JsonArray; public: - JsonArrayIterator() : slot_(0) {} - explicit JsonArrayIterator(detail::MemoryPool* pool, - detail::VariantSlot* slot) - : pool_(pool), slot_(slot) {} + JsonArrayIterator() {} + explicit JsonArrayIterator(detail::ArrayData::iterator iterator, + detail::ResourceManager* resources) + : iterator_(iterator), resources_(resources) {} - JsonVariant operator*() const { - return JsonVariant(pool_, slot_->data()); + JsonVariant operator*() { + return JsonVariant(iterator_.data(), resources_); } - VariantPtr operator->() { - return VariantPtr(pool_, slot_->data()); + Ptr operator->() { + return operator*(); } bool operator==(const JsonArrayIterator& other) const { - return slot_ == other.slot_; + return iterator_ == other.iterator_; } bool operator!=(const JsonArrayIterator& other) const { - return slot_ != other.slot_; + return iterator_ != other.iterator_; } JsonArrayIterator& operator++() { - slot_ = slot_->next(); - return *this; - } - - JsonArrayIterator& operator+=(size_t distance) { - slot_ = slot_->next(distance); + iterator_.next(resources_); return *this; } private: - detail::MemoryPool* pool_; - detail::VariantSlot* slot_; -}; - -class VariantConstPtr { - public: - VariantConstPtr(const detail::VariantData* data) : variant_(data) {} - - JsonVariantConst* operator->() { - return &variant_; - } - - JsonVariantConst& operator*() { - return variant_; - } - - private: - JsonVariantConst variant_; + detail::ArrayData::iterator iterator_; + detail::ResourceManager* resources_; }; class JsonArrayConstIterator { friend class JsonArray; public: - JsonArrayConstIterator() : slot_(0) {} - explicit JsonArrayConstIterator(const detail::VariantSlot* slot) - : slot_(slot) {} + JsonArrayConstIterator() {} + explicit JsonArrayConstIterator(detail::ArrayData::iterator iterator, + const detail::ResourceManager* resources) + : iterator_(iterator), resources_(resources) {} JsonVariantConst operator*() const { - return JsonVariantConst(slot_->data()); + return JsonVariantConst(iterator_.data(), resources_); } - VariantConstPtr operator->() { - return VariantConstPtr(slot_->data()); + Ptr operator->() { + return operator*(); } bool operator==(const JsonArrayConstIterator& other) const { - return slot_ == other.slot_; + return iterator_ == other.iterator_; } bool operator!=(const JsonArrayConstIterator& other) const { - return slot_ != other.slot_; + return iterator_ != other.iterator_; } JsonArrayConstIterator& operator++() { - slot_ = slot_->next(); - return *this; - } - - JsonArrayConstIterator& operator+=(size_t distance) { - slot_ = slot_->next(distance); + iterator_.next(resources_); return *this; } private: - const detail::VariantSlot* slot_; + detail::ArrayData::iterator iterator_; + const detail::ResourceManager* resources_; }; ARDUINOJSON_END_PUBLIC_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp index 398e11d45..ff589cea8 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -18,7 +18,7 @@ copyArray(const T& src, JsonVariant dst) { } // Copies values from an array to a JsonArray or a JsonVariant. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline typename detail::enable_if< !detail::is_base_of::value, bool>::type @@ -27,14 +27,14 @@ copyArray(T (&src)[N], const TDestination& dst) { } // Copies values from an array to a JsonArray or a JsonVariant. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline typename detail::enable_if< !detail::is_base_of::value, bool>::type copyArray(const T* src, size_t len, const TDestination& dst) { bool ok = true; for (size_t i = 0; i < len; i++) { - ok &= copyArray(src[i], dst.add()); + ok &= copyArray(src[i], dst.template add()); } return ok; } @@ -47,14 +47,14 @@ inline bool copyArray(const char* src, size_t, const TDestination& dst) { } // Copies values from an array to a JsonDocument. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline bool copyArray(const T& src, JsonDocument& dst) { return copyArray(src, dst.to()); } // Copies an array to a JsonDocument. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline bool copyArray(const T* src, size_t len, JsonDocument& dst) { return copyArray(src, len, dst.to()); @@ -70,14 +70,14 @@ copyArray(JsonVariantConst src, T& dst) { } // Copies values from a JsonArray or JsonVariant to an array. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline size_t copyArray(JsonArrayConst src, T (&dst)[N]) { return copyArray(src, dst, N); } // Copies values from a JsonArray or JsonVariant to an array. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline size_t copyArray(JsonArrayConst src, T* dst, size_t len) { size_t i = 0; @@ -101,7 +101,7 @@ inline size_t copyArray(JsonVariantConst src, char (&dst)[N]) { } // Copies values from a JsonDocument to an array. -// https://arduinojson.org/v6/api/misc/copyarray/ +// https://arduinojson.org/v7/api/misc/copyarray/ template inline typename detail::enable_if< detail::is_array::value && diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp index 090c98b9e..1010795ce 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -11,74 +11,108 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -class MemoryPool; class VariantData; class VariantSlot; -class CollectionData { - VariantSlot* head_; - VariantSlot* tail_; +class CollectionIterator { + friend class CollectionData; public: - // Must be a POD! - // - no constructor - // - no destructor - // - no virtual - // - no inheritance + CollectionIterator() : slot_(nullptr), currentId_(NULL_SLOT) {} - // Array only + void next(const ResourceManager* resources); - VariantData* addElement(MemoryPool* pool); - - VariantData* getElement(size_t index) const; - - VariantData* getOrAddElement(size_t index, MemoryPool* pool); - - void removeElement(size_t index); - - // Object only - - template - VariantData* addMember(TAdaptedString key, MemoryPool* pool); - - template - VariantData* getMember(TAdaptedString key) const; - - template - VariantData* getOrAddMember(TAdaptedString key, MemoryPool* pool); - - template - void removeMember(TAdaptedString key) { - removeSlot(getSlot(key)); + bool done() const { + return slot_ == nullptr; } - template - bool containsKey(const TAdaptedString& key) const; - - // Generic - - void clear(); - size_t memoryUsage() const; - size_t size() const; - - VariantSlot* addSlot(MemoryPool*); - void removeSlot(VariantSlot* slot); - - bool copyFrom(const CollectionData& src, MemoryPool* pool); - - VariantSlot* head() const { - return head_; + bool operator==(const CollectionIterator& other) const { + return slot_ == other.slot_; } - void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance); + bool operator!=(const CollectionIterator& other) const { + return slot_ != other.slot_; + } + + VariantData* operator->() { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return data(); + } + + VariantData& operator*() { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return *data(); + } + + const VariantData& operator*() const { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return *data(); + } + + const char* key() const; + bool ownsKey() const; + + void setKey(StringNode*); + void setKey(const char*); + + VariantData* data() { + return reinterpret_cast(slot_); + } + + const VariantData* data() const { + return reinterpret_cast(slot_); + } private: - VariantSlot* getSlot(size_t index) const; + CollectionIterator(VariantSlot* slot, SlotId slotId); - template - VariantSlot* getSlot(TAdaptedString key) const; + VariantSlot* slot_; + SlotId currentId_, nextId_; +}; - VariantSlot* getPreviousSlot(VariantSlot*) const; +class CollectionData { + SlotId head_ = NULL_SLOT; + SlotId tail_ = NULL_SLOT; + + public: + // Placement new + static void* operator new(size_t, void* p) noexcept { + return p; + } + + static void operator delete(void*, void*) noexcept {} + + using iterator = CollectionIterator; + + iterator createIterator(const ResourceManager* resources) const { + return iterator(resources->getSlot(head_), head_); + } + + size_t size(const ResourceManager*) const; + size_t nesting(const ResourceManager*) const; + + void clear(ResourceManager* resources); + + static void clear(CollectionData* collection, ResourceManager* resources) { + if (!collection) + return; + collection->clear(resources); + } + + void remove(iterator it, ResourceManager* resources); + + static void remove(CollectionData* collection, iterator it, + ResourceManager* resources) { + if (collection) + return collection->remove(it, resources); + } + + protected: + iterator addSlot(ResourceManager*); + + private: + SlotWithId getPreviousSlot(VariantSlot*, const ResourceManager*) const; + void releaseSlot(SlotWithId, ResourceManager*); }; inline const VariantData* collectionToVariant( diff --git a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp index 134d5bd64..79d9ac72b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -1,197 +1,133 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once #include -#include +#include #include +#include #include ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { - VariantSlot* slot = pool->allocVariant(); - if (!slot) - return 0; +inline CollectionIterator::CollectionIterator(VariantSlot* slot, SlotId slotId) + : slot_(slot), currentId_(slotId) { + nextId_ = slot_ ? slot_->next() : NULL_SLOT; +} - if (tail_) { - ARDUINOJSON_ASSERT(pool->owns(tail_)); // Can't alter a linked array/object - tail_->setNextNotNull(slot); - tail_ = slot; +inline const char* CollectionIterator::key() const { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return slot_->key(); +} + +inline void CollectionIterator::setKey(const char* s) { + ARDUINOJSON_ASSERT(slot_ != nullptr); + ARDUINOJSON_ASSERT(s != nullptr); + return slot_->setKey(s); +} + +inline void CollectionIterator::setKey(StringNode* s) { + ARDUINOJSON_ASSERT(slot_ != nullptr); + ARDUINOJSON_ASSERT(s != nullptr); + return slot_->setKey(s); +} + +inline bool CollectionIterator::ownsKey() const { + ARDUINOJSON_ASSERT(slot_ != nullptr); + return slot_->ownsKey(); +} + +inline void CollectionIterator::next(const ResourceManager* resources) { + ARDUINOJSON_ASSERT(currentId_ != NULL_SLOT); + slot_ = resources->getSlot(nextId_); + currentId_ = nextId_; + if (slot_) + nextId_ = slot_->next(); +} + +inline CollectionData::iterator CollectionData::addSlot( + ResourceManager* resources) { + auto slot = resources->allocSlot(); + if (!slot) + return {}; + if (tail_ != NULL_SLOT) { + auto tail = resources->getSlot(tail_); + tail->setNext(slot.id()); + tail_ = slot.id(); } else { - head_ = slot; - tail_ = slot; + head_ = slot.id(); + tail_ = slot.id(); + } + return iterator(slot, slot.id()); +} + +inline void CollectionData::clear(ResourceManager* resources) { + auto next = head_; + while (next != NULL_SLOT) { + auto currId = next; + auto slot = resources->getSlot(next); + next = slot->next(); + releaseSlot(SlotWithId(slot, currId), resources); } - slot->clear(); - return slot; + head_ = NULL_SLOT; + tail_ = NULL_SLOT; } -inline VariantData* CollectionData::addElement(MemoryPool* pool) { - return slotData(addSlot(pool)); -} - -template -inline VariantData* CollectionData::addMember(TAdaptedString key, - MemoryPool* pool) { - VariantSlot* slot = addSlot(pool); - if (!slotSetKey(slot, key, pool)) { - removeSlot(slot); - return 0; +inline SlotWithId CollectionData::getPreviousSlot( + VariantSlot* target, const ResourceManager* resources) const { + auto prev = SlotWithId(); + auto currentId = head_; + while (currentId != NULL_SLOT) { + auto currentSlot = resources->getSlot(currentId); + if (currentSlot == target) + return prev; + prev = SlotWithId(currentSlot, currentId); + currentId = currentSlot->next(); } - return slot->data(); + return SlotWithId(); } -inline void CollectionData::clear() { - head_ = 0; - tail_ = 0; -} - -template -inline bool CollectionData::containsKey(const TAdaptedString& key) const { - return getSlot(key) != 0; -} - -inline bool CollectionData::copyFrom(const CollectionData& src, - MemoryPool* pool) { - clear(); - for (VariantSlot* s = src.head_; s; s = s->next()) { - VariantData* var; - if (s->key() != 0) { - JsonString key(s->key(), - s->ownsKey() ? JsonString::Copied : JsonString::Linked); - var = addMember(adaptString(key), pool); - } else { - var = addElement(pool); - } - if (!var) - return false; - if (!var->copyFrom(*s->data(), pool)) - return false; - } - return true; -} - -template -inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { - if (key.isNull()) - return 0; - VariantSlot* slot = head_; - while (slot) { - if (stringEquals(key, adaptString(slot->key()))) - break; - slot = slot->next(); - } - return slot; -} - -inline VariantSlot* CollectionData::getSlot(size_t index) const { - if (!head_) - return 0; - return head_->next(index); -} - -inline VariantSlot* CollectionData::getPreviousSlot(VariantSlot* target) const { - VariantSlot* current = head_; - while (current) { - VariantSlot* next = current->next(); - if (next == target) - return current; - current = next; - } - return 0; -} - -template -inline VariantData* CollectionData::getMember(TAdaptedString key) const { - VariantSlot* slot = getSlot(key); - return slot ? slot->data() : 0; -} - -template -inline VariantData* CollectionData::getOrAddMember(TAdaptedString key, - MemoryPool* pool) { - // ignore null key - if (key.isNull()) - return 0; - - // search a matching key - VariantSlot* slot = getSlot(key); - if (slot) - return slot->data(); - - return addMember(key, pool); -} - -inline VariantData* CollectionData::getElement(size_t index) const { - VariantSlot* slot = getSlot(index); - return slot ? slot->data() : 0; -} - -inline VariantData* CollectionData::getOrAddElement(size_t index, - MemoryPool* pool) { - VariantSlot* slot = head_; - while (slot && index > 0) { - slot = slot->next(); - index--; - } - if (!slot) - index++; - while (index > 0) { - slot = addSlot(pool); - index--; - } - return slotData(slot); -} - -inline void CollectionData::removeSlot(VariantSlot* slot) { - if (!slot) +inline void CollectionData::remove(iterator it, ResourceManager* resources) { + if (it.done()) return; - VariantSlot* prev = getPreviousSlot(slot); - VariantSlot* next = slot->next(); + auto curr = it.slot_; + auto prev = getPreviousSlot(curr, resources); + auto next = curr->next(); if (prev) prev->setNext(next); else head_ = next; - if (!next) - tail_ = prev; + if (next == NULL_SLOT) + tail_ = prev.id(); + releaseSlot({it.slot_, it.currentId_}, resources); } -inline void CollectionData::removeElement(size_t index) { - removeSlot(getSlot(index)); -} - -inline size_t CollectionData::memoryUsage() const { - size_t total = 0; - for (VariantSlot* s = head_; s; s = s->next()) { - total += sizeof(VariantSlot) + s->data()->memoryUsage(); - if (s->ownsKey()) - total += strlen(s->key()) + 1; +inline size_t CollectionData::nesting(const ResourceManager* resources) const { + size_t maxChildNesting = 0; + for (auto it = createIterator(resources); !it.done(); it.next(resources)) { + size_t childNesting = it->nesting(resources); + if (childNesting > maxChildNesting) + maxChildNesting = childNesting; } - return total; + return maxChildNesting + 1; } -inline size_t CollectionData::size() const { - return slotSize(head_); +inline size_t CollectionData::size(const ResourceManager* resources) const { + size_t count = 0; + for (auto it = createIterator(resources); !it.done(); it.next(resources)) + count++; + return count; } -template -inline void movePointer(T*& p, ptrdiff_t offset) { - if (!p) - return; - p = reinterpret_cast( - reinterpret_cast(reinterpret_cast(p) + offset)); - ARDUINOJSON_ASSERT(isAligned(p)); -} - -inline void CollectionData::movePointers(ptrdiff_t stringDistance, - ptrdiff_t variantDistance) { - movePointer(head_, variantDistance); - movePointer(tail_, variantDistance); - for (VariantSlot* slot = head_; slot; slot = slot->next()) - slot->movePointers(stringDistance, variantDistance); +inline void CollectionData::releaseSlot(SlotWithId slot, + ResourceManager* resources) { + if (slot->ownsKey()) + resources->dereferenceString(slot->key()); + slot->data()->setNull(resources); + resources->freeSlot(slot); } ARDUINOJSON_END_PRIVATE_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp index ac0ea660a..12d60688a 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -59,15 +59,24 @@ # define ARDUINOJSON_USE_DOUBLE 1 #endif -// Store integral values with long (0) or long long (1) -#ifndef ARDUINOJSON_USE_LONG_LONG -# if defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ >= 4 || \ - defined(_MSC_VER) -# define ARDUINOJSON_USE_LONG_LONG 1 +// Pointer size: a heuristic to set sensible defaults +#ifndef ARDUINOJSON_SIZEOF_POINTER +# if defined(__SIZEOF_POINTER__) +# define ARDUINOJSON_SIZEOF_POINTER __SIZEOF_POINTER__ +# elif defined(_WIN64) && _WIN64 +# define ARDUINOJSON_SIZEOF_POINTER 8 // 64 bits +# else +# define ARDUINOJSON_SIZEOF_POINTER 4 // assume 32 bits otherwise # endif #endif + +// Store integral values with long (0) or long long (1) #ifndef ARDUINOJSON_USE_LONG_LONG -# define ARDUINOJSON_USE_LONG_LONG 0 +# if ARDUINOJSON_SIZEOF_POINTER >= 4 // 32 & 64 bits systems +# define ARDUINOJSON_USE_LONG_LONG 1 +# else +# define ARDUINOJSON_USE_LONG_LONG 0 +# endif #endif // Limit nesting as the stack is likely to be small @@ -75,19 +84,50 @@ # 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 -// Address space == 16-bit => max 127 values -# 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 +// Number of bytes to store the variant identifier +#ifndef ARDUINOJSON_SLOT_ID_SIZE +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_SLOT_ID_SIZE 1 // up to 255 slots +# elif ARDUINOJSON_SIZEOF_POINTER == 4 +# define ARDUINOJSON_SLOT_ID_SIZE 2 // up to 65535 slots # else -// Address space == 32-bit => max 32767 values -# define ARDUINOJSON_SLOT_OFFSET_SIZE 2 +# define ARDUINOJSON_SLOT_ID_SIZE 4 // up to 4294967295 slots +# endif +#endif + +// Capacity of each variant pool (in slots) +#ifndef ARDUINOJSON_POOL_CAPACITY +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_POOL_CAPACITY 16 // 128 bytes +# elif ARDUINOJSON_SIZEOF_POINTER == 4 +# define ARDUINOJSON_POOL_CAPACITY 64 // 1024 bytes +# else +# define ARDUINOJSON_POOL_CAPACITY 128 // 3072 bytes +# endif +#endif + +// Initial capacity of the pool list +#ifndef ARDUINOJSON_INITIAL_POOL_COUNT +# define ARDUINOJSON_INITIAL_POOL_COUNT 4 +#endif + +// Automatically call shrinkToFit() from deserializeXxx() +// Disabled by default on 8-bit platforms because it's not worth the increase in +// code size +#ifndef ARDUINOJSON_AUTO_SHRINK +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_AUTO_SHRINK 0 +# else +# define ARDUINOJSON_AUTO_SHRINK 1 +# endif +#endif + +// Number of bytes to store the length of a string +#ifndef ARDUINOJSON_STRING_LENGTH_SIZE +# if ARDUINOJSON_SIZEOF_POINTER <= 2 +# define ARDUINOJSON_STRING_LENGTH_SIZE 1 // up to 255 characters +# else +# define ARDUINOJSON_STRING_LENGTH_SIZE 2 // up to 65535 characters # endif #endif @@ -195,10 +235,6 @@ # define ARDUINOJSON_TAB " " #endif -#ifndef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION -# define ARDUINOJSON_ENABLE_STRING_DEDUPLICATION 1 -#endif - #ifndef ARDUINOJSON_STRING_BUFFER_SIZE # define ARDUINOJSON_STRING_BUFFER_SIZE 32 #endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp index 1bfc39392..fd32a55e9 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp index 8400cc0b2..4c73934fc 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationOptions.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp index 39883027d..76705560b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp @@ -1,17 +1,24 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once -#include +#include +#include ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE namespace DeserializationOption { class Filter { public: - explicit Filter(JsonVariantConst v) : variant_(v) {} +#if ARDUINOJSON_AUTO_SHRINK + explicit Filter(JsonDocument& doc) : variant_(doc) { + doc.shrinkToFit(); + } +#endif + + explicit Filter(JsonVariantConst variant) : variant_(variant) {} bool allow() const { return variant_; diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp index 6434275be..d30402b4b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp index 44437686a..c4b5edb74 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -19,7 +19,7 @@ struct Reader { int read() { // clang-format off - return source_->read(); // Error here? See https://arduinojson.org/v6/invalid-input/ + return source_->read(); // Error here? See https://arduinojson.org/v7/invalid-input/ // clang-format on } diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp index 8a8738858..43c5a432b 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -15,7 +15,7 @@ struct Readerread() as it ignores the timeout char c; return stream_->readBytes(&c, 1) ? static_cast(c) : -1; } diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp index 14491f44a..4730be016 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp index 97714afb1..fa8ff23d7 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp index c0ca4a771..1ca46c852 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp index eff67bac3..8603bb138 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp index 41e0c00aa..25ba63645 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp index b60f1cec8..ddb07b8b2 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp index 9f4d78e85..21d187640 100644 --- a/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp @@ -1,5 +1,5 @@ // ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON +// Copyright © 2014-2024, Benoit BLANCHON // MIT License #pragma once @@ -8,7 +8,6 @@ #include #include #include -#include ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE @@ -23,44 +22,62 @@ struct first_or_void { using type = T; }; -template