diff --git a/lib_standalone/ArduinoJson/ArduinoJson.h b/lib/ArduinoJson/ArduinoJson.h similarity index 95% rename from lib_standalone/ArduinoJson/ArduinoJson.h rename to lib/ArduinoJson/ArduinoJson.h index 1606a3d6a..067661c77 100644 --- a/lib_standalone/ArduinoJson/ArduinoJson.h +++ b/lib/ArduinoJson/ArduinoJson.h @@ -1,5 +1,5 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#include "src/ArduinoJson.h" +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#include "src/ArduinoJson.h" diff --git a/lib_standalone/ArduinoJson/CHANGELOG.md b/lib/ArduinoJson/CHANGELOG.md similarity index 92% rename from lib_standalone/ArduinoJson/CHANGELOG.md rename to lib/ArduinoJson/CHANGELOG.md index 165f2dc59..2fa203e8b 100644 --- a/lib_standalone/ArduinoJson/CHANGELOG.md +++ b/lib/ArduinoJson/CHANGELOG.md @@ -1,965 +1,998 @@ -ArduinoJson: change log -======================= - -HEAD ----- - -* Fixed "maybe-uninitialized" warning (issue #1217) - -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: -> -> ```c++ -> DynamicJsonDocument doc1(64); -> doc1.set(String("example")); -> -> 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); -> ``` - -v5.13.2 -------- - -* Fixed `JsonBuffer::parse()` not respecting nesting limit correctly (issue #693) -* Fixed inconsistencies in nesting level counting (PR #695 from Zhenyu Wu) -* Fixed null values that could be pass to `strcmp()` (PR #745 from Mike Karlesky) -* Added macros `ARDUINOJSON_VERSION`, `ARDUINOJSON_VERSION_MAJOR`... - -v5.13.1 -------- - -* Fixed `JsonVariant::operator|(int)` that returned the default value if the variant contained a double (issue #675) -* Allowed non-quoted key to contain underscores (issue #665) - -v5.13.0 -------- - -* Changed the rules of string duplication (issue #658) -* `RawJson()` accepts any kind of string and obeys to the same rules for duplication -* Changed the return type of `strdup()` to `const char*` to prevent double duplication -* Marked `strdup()` as deprecated - -> ### New rules for string duplication -> -> | type | duplication | -> |:---------------------------|:------------| -> | const char* | no | -> | char* | ~~no~~ yes | -> | String | yes | -> | std::string | yes | -> | const __FlashStringHelper* | yes | -> -> These new rules make `JsonBuffer::strdup()` useless. - -v5.12.0 -------- - -* Added `JsonVariant::operator|` to return a default value (see below) -* Added a clear error message when compiled as C instead of C++ (issue #629) -* Added detection of MPLAB XC compiler (issue #629) -* Added detection of Keil ARM Compiler (issue #629) -* Added an example that shows how to save and load a configuration file -* Reworked all other examples - -> ### How to use the new feature? -> -> If you have a block like this: -> -> ```c++ -> const char* ssid = root["ssid"]; -> if (!ssid) -> ssid = "default ssid"; -> ``` -> -> You can simplify like that: -> -> ```c++ -> const char* ssid = root["ssid"] | "default ssid"; -> ``` - -v5.11.2 -------- - -* Fixed `DynamicJsonBuffer::clear()` not resetting allocation size (issue #561) -* Fixed incorrect rounding for float values (issue #588) - -v5.11.1 -------- - -* Removed dependency on `PGM_P` as Particle 0.6.2 doesn't define it (issue #546) -* Fixed warning "dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]" -* Fixed warning "floating constant exceeds range of 'float' [-Woverflow]" (issue #544) -* Fixed warning "this statement may fall through" [-Wimplicit-fallthrough=] (issue #539) -* Removed `ARDUINOJSON_DOUBLE_IS_64BITS` as it became useless. -* Fixed too many decimals places in float serialization (issue #543) - -v5.11.0 -------- - -* Made `JsonBuffer` non-copyable (PR #524 by @luisrayas3) -* Added `StaticJsonBuffer::clear()` -* Added `DynamicJsonBuffer::clear()` - -v5.10.1 -------- - -* Fixed IntelliSense errors in Visual Micro (issue #483) -* Fixed compilation in IAR Embedded Workbench (issue #515) -* Fixed reading "true" as a float (issue #516) -* Added `ARDUINOJSON_DOUBLE_IS_64BITS` -* Added `ARDUINOJSON_EMBEDDED_MODE` - -v5.10.0 -------- - -* Removed configurable number of decimal places (issues #288, #427 and #506) -* Changed exponentiation thresholds to `1e7` and `1e-5` (issues #288, #427 and #506) -* `JsonVariant::is()` now returns `true` for integers -* Fixed error `IsBaseOf is not a member of ArduinoJson::TypeTraits` (issue #495) -* Fixed error `forming reference to reference` (issue #495) - -> ### BREAKING CHANGES :warning: -> -> | Old syntax | New syntax | -> |:--------------------------------|:--------------------| -> | `double_with_n_digits(3.14, 2)` | `3.14` | -> | `float_with_n_digits(3.14, 2)` | `3.14f` | -> | `obj.set("key", 3.14, 2)` | `obj["key"] = 3.14` | -> | `arr.add(3.14, 2)` | `arr.add(3.14)` | -> -> | Input | Old output | New output | -> |:----------|:-----------|:-----------| -> | `3.14159` | `3.14` | `3.14159` | -> | `42.0` | `42.00` | `42` | -> | `0.0` | `0.00` | `0` | -> -> | Expression | Old result | New result | -> |:-------------------------------|:-----------|:-----------| -> | `JsonVariant(42).is()` | `true` | `true` | -> | `JsonVariant(42).is()` | `false` | `true` | -> | `JsonVariant(42).is()` | `false` | `true` | - -v5.9.0 ------- - -* Added `JsonArray::remove(iterator)` (issue #479) -* Added `JsonObject::remove(iterator)` -* Renamed `JsonArray::removeAt(size_t)` into `remove(size_t)` -* Renamed folder `include/` to `src/` -* Fixed warnings `floating constant exceeds range of float`and `floating constant truncated to zero` (issue #483) -* Removed `Print` class and converted `printTo()` to a template method (issue #276) -* Removed example `IndentedPrintExample.ino` -* Now compatible with Particle 0.6.1, thanks to Jacob Nite (issue #294 and PR #461 by @foodbag) - -v5.8.4 ------- - -* Added custom implementation of `strtod()` (issue #453) -* Added custom implementation of `strtol()` (issue #465) -* `char` is now treated as an integral type (issue #337, #370) - -v5.8.3 ------- - -* Fixed an access violation in `DynamicJsonBuffer` when memory allocation fails (issue #433) -* Added operators `==` and `!=` for two `JsonVariant`s (issue #436) -* Fixed `JsonVariant::operator[const FlashStringHelper*]` (issue #441) - -v5.8.2 ------- - -* Fixed parsing of comments (issue #421) -* Fixed ignored `Stream` timeout (issue #422) -* Made sure we don't read more that necessary (issue #422) -* Fixed error when the key of a `JsonObject` is a `char[]` (issue #423) -* Reduced code size when using `const` references -* Fixed error with string of type `unsigned char*` (issue #428) -* Added `deprecated` attribute on `asArray()`, `asObject()` and `asString()` (issue #420) - -v5.8.1 ------- - -* Fixed error when assigning a `volatile int` to a `JsonVariant` (issue #415) -* Fixed errors with Variable Length Arrays (issue #416) -* Fixed error when both `ARDUINOJSON_ENABLE_STD_STREAM` and `ARDUINOJSON_ENABLE_ARDUINO_STREAM` are set to `1` -* Fixed error "Stream does not name a type" (issue #412) - -v5.8.0 ------- - -* Added operator `==` to compare `JsonVariant` and strings (issue #402) -* Added support for `Stream` (issue #300) -* Reduced memory consumption by not duplicating spaces and comments - -> ### BREAKING CHANGES :warning: -> -> `JsonBuffer::parseObject()` and `JsonBuffer::parseArray()` have been pulled down to the derived classes `DynamicJsonBuffer` and `StaticJsonBufferBase`. -> -> This means that if you have code like: -> -> ```c++ -> void myFunction(JsonBuffer& jsonBuffer); -> ``` -> -> you need to replace it with one of the following: -> -> ```c++ -> void myFunction(DynamicJsonBuffer& jsonBuffer); -> void myFunction(StaticJsonBufferBase& jsonBuffer); -> template void myFunction(TJsonBuffer& jsonBuffer); -> ``` - -v5.7.3 ------- - -* Added an `printTo(char[N])` and `prettyPrintTo(char[N])` (issue #292) -* Added ability to set a nested value like this: `root["A"]["B"] = "C"` (issue #352) -* Renamed `*.ipp` to `*Impl.hpp` because they were ignored by Arduino IDE (issue #396) - -v5.7.2 ------- - -* Made PROGMEM available on more platforms (issue #381) -* Fixed PROGMEM causing an exception on ESP8266 (issue #383) - -v5.7.1 ------- - -* Added support for PROGMEM (issue #76) -* Fixed compilation error when index is not an `int` (issue #381) - -v5.7.0 ------- - -* Templatized all functions using `String` or `std::string` -* Removed `ArduinoJson::String` -* Removed `JsonVariant::defaultValue()` -* Removed non-template `JsonObject::get()` and `JsonArray.get()` -* Fixed support for `StringSumHelper` (issue #184) -* Replaced `ARDUINOJSON_USE_ARDUINO_STRING` by `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_ARDUINO_STRING` (issue #378) -* Added example `StringExample.ino` to show where `String` can be used -* Increased default nesting limit to 50 when compiled for a computer (issue #349) - -> ### BREAKING CHANGES :warning: -> -> The non-template functions `JsonObject::get()` and `JsonArray.get()` have been removed. This means that you need to explicitely tell the type you expect in return. -> -> Old code: -> -> ```c++ -> #define ARDUINOJSON_USE_ARDUINO_STRING 0 -> JsonVariant value1 = myObject.get("myKey"); -> JsonVariant value2 = myArray.get(0); -> ``` -> -> New code: -> -> ```c++ -> #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 -> #define ARDUINOJSON_ENABLE_STD_STRING 1 -> JsonVariant value1 = myObject.get("myKey"); -> JsonVariant value2 = myArray.get(0); -> ``` - -v5.6.7 ------- - -* Fixed `array[idx].as()` and `object[key].as()` -* Fixed return value of `JsonObject::set()` (issue #350) -* Fixed undefined behavior in `Prettyfier` and `Print` (issue #354) -* Fixed parser that incorrectly rejected floats containing a `+` (issue #349) - -v5.6.6 ------- - -* Fixed `-Wparentheses` warning introduced in v5.6.5 (PR #335 by @nuket) -* Added `.mbedignore` for ARM mbdeb (PR #334 by @nuket) -* Fixed `JsonVariant::success()` which didn't propagate `JsonArray::success()` nor `JsonObject::success()` (issue #342). - -v5.6.5 ------- - -* `as()` now returns `true` when input is `null` (issue #330) - -v5.6.4 ------- - -* Fixed error in float serialization (issue #324) - -v5.6.3 ------- - -* Improved speed of float serialization (about twice faster) -* Added `as()` as a synonym for `as()`... (issue #291) -* Fixed `call of overloaded isinf(double&) is ambiguous` (issue #284) - -v5.6.2 ------- - -* Fixed build when another lib does `#undef isnan` (issue #284) - -v5.6.1 ------- - -* Added missing `#pragma once` (issue #310) - -v5.6.0 ------- - -* ArduinoJson is now a header-only library (issue #199) - -v5.5.1 ------- - -* Fixed compilation error with Intel Galileo (issue #299) - -v5.5.0 ------- - -* Added `JsonVariant::success()` (issue #279) -* Renamed `JsonVariant::invalid()` to `JsonVariant::defaultValue()` - -v5.4.0 ------- - -* Changed `::String` to `ArduinoJson::String` (issue #275) -* Changed `::Print` to `ArduinoJson::Print` too - -v5.3.0 ------- - -* Added custom implementation of `ftoa` (issues #266, #267, #269 and #270) -* Added `JsonVariant JsonBuffer::parse()` (issue #265) -* Fixed `unsigned long` printed as `signed long` (issue #170) - -v5.2.0 ------- - -* Added `JsonVariant::as()` as a synonym for `JsonVariant::as()` (issue #257) -* Added example `JsonHttpClient` (issue #256) -* Added `JsonArray::copyTo()` and `JsonArray::copyFrom()` (issue #254) -* Added `RawJson()` to insert pregenerated JSON portions (issue #259) - -v5.1.1 ------- - -* Removed `String` duplication when one replaces a value in a `JsonObject` (PR #232 by @ulion) - -v5.1.0 ------- - -* Added support of `long long` (issue #171) -* Moved all build settings to `ArduinoJson/Configuration.hpp` - -> ### BREAKING CHANGE :warning: -> -> If you defined `ARDUINOJSON_ENABLE_STD_STREAM`, you now need to define it to `1`. - -v5.0.8 ------- - -* Made the library compatible with [PlatformIO](http://platformio.org/) (issue #181) -* Fixed `JsonVariant::is()` that was incorrectly returning false (issue #214) - -v5.0.7 ------- - -* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)` -* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161) - -> ### BREAKING CHANGES :warning: -> -> - `JsonVariant(true).as()` now returns `"true"` instead of `"1"` -> - `JsonVariant(false).as()` now returns `"false"` instead of `"0"` - -v5.0.6 ------- - -* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152) -* Fixed warning about library category in Arduino 1.6.6 (issue #147) -* Examples: Added a loop to wait for serial port to be ready (issue #156) - -v5.0.5 ------- - -* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143) -* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134) - -v5.0.4 ------- - -* Fixed ambiguous overload with `JsonArraySubscript` and `JsonObjectSubscript` (issue #122) - -v5.0.3 ------- - -* Fixed `printTo(String)` which wrote numbers instead of strings (issue #120) -* Fixed return type of `JsonArray::is()` and some others (issue #121) - -v5.0.2 ------- - -* Fixed segmentation fault in `parseObject(String)` and `parseArray(String)`, when the - `StaticJsonBuffer` is too small to hold a copy of the string -* Fixed Clang warning "register specifier is deprecated" (issue #102) -* Fixed GCC warning "declaration shadows a member" (issue #103) -* Fixed memory alignment, which made ESP8266 crash (issue #104) -* Fixed compilation on Visual Studio 2010 and 2012 (issue #107) - -v5.0.1 ------- - -* Fixed compilation with Arduino 1.0.6 (issue #99) - -v5.0.0 ------- - -* Added support of `String` class (issues #55, #56, #70, #77) -* Added `JsonBuffer::strdup()` to make a copy of a string (issues #10, #57) -* Implicitly call `strdup()` for `String` but not for `char*` (issues #84, #87) -* Added support of non standard JSON input (issue #44) -* Added support of comments in JSON input (issue #88) -* Added implicit cast between numerical types (issues #64, #69, #93) -* Added ability to read number values as string (issue #90) -* Redesigned `JsonVariant` to leverage converting constructors instead of assignment operators (issue #66) -* Switched to new the library layout (requires Arduino 1.0.6 or above) - -> ### BREAKING CHANGES :warning: -> -> - `JsonObject::add()` was renamed to `set()` -> - `JsonArray::at()` and `JsonObject::at()` were renamed to `get()` -> - Number of digits of floating point value are now set with `double_with_n_digits()` - -**Personal note about the `String` class**: -Support of the `String` class has been added to the library because many people use it in their programs. -However, you should not see this as an invitation to use the `String` class. -The `String` class is **bad** because it uses dynamic memory allocation. -Compared to static allocation, it compiles to a bigger, slower program, and is less predictable. -You certainly don't want that in an embedded environment! +ArduinoJson: change log +======================= + +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!=` +* 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: +> +> ```c++ +> DynamicJsonDocument doc1(64); +> doc1.set(String("example")); +> +> 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); +> ``` + +v5.13.2 +------- + +* Fixed `JsonBuffer::parse()` not respecting nesting limit correctly (issue #693) +* Fixed inconsistencies in nesting level counting (PR #695 from Zhenyu Wu) +* Fixed null values that could be pass to `strcmp()` (PR #745 from Mike Karlesky) +* Added macros `ARDUINOJSON_VERSION`, `ARDUINOJSON_VERSION_MAJOR`... + +v5.13.1 +------- + +* Fixed `JsonVariant::operator|(int)` that returned the default value if the variant contained a double (issue #675) +* Allowed non-quoted key to contain underscores (issue #665) + +v5.13.0 +------- + +* Changed the rules of string duplication (issue #658) +* `RawJson()` accepts any kind of string and obeys to the same rules for duplication +* Changed the return type of `strdup()` to `const char*` to prevent double duplication +* Marked `strdup()` as deprecated + +> ### New rules for string duplication +> +> | type | duplication | +> |:---------------------------|:------------| +> | const char* | no | +> | char* | ~~no~~ yes | +> | String | yes | +> | std::string | yes | +> | const __FlashStringHelper* | yes | +> +> These new rules make `JsonBuffer::strdup()` useless. + +v5.12.0 +------- + +* Added `JsonVariant::operator|` to return a default value (see below) +* Added a clear error message when compiled as C instead of C++ (issue #629) +* Added detection of MPLAB XC compiler (issue #629) +* Added detection of Keil ARM Compiler (issue #629) +* Added an example that shows how to save and load a configuration file +* Reworked all other examples + +> ### How to use the new feature? +> +> If you have a block like this: +> +> ```c++ +> const char* ssid = root["ssid"]; +> if (!ssid) +> ssid = "default ssid"; +> ``` +> +> You can simplify like that: +> +> ```c++ +> const char* ssid = root["ssid"] | "default ssid"; +> ``` + +v5.11.2 +------- + +* Fixed `DynamicJsonBuffer::clear()` not resetting allocation size (issue #561) +* Fixed incorrect rounding for float values (issue #588) + +v5.11.1 +------- + +* Removed dependency on `PGM_P` as Particle 0.6.2 doesn't define it (issue #546) +* Fixed warning "dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]" +* Fixed warning "floating constant exceeds range of 'float' [-Woverflow]" (issue #544) +* Fixed warning "this statement may fall through" [-Wimplicit-fallthrough=] (issue #539) +* Removed `ARDUINOJSON_DOUBLE_IS_64BITS` as it became useless. +* Fixed too many decimals places in float serialization (issue #543) + +v5.11.0 +------- + +* Made `JsonBuffer` non-copyable (PR #524 by @luisrayas3) +* Added `StaticJsonBuffer::clear()` +* Added `DynamicJsonBuffer::clear()` + +v5.10.1 +------- + +* Fixed IntelliSense errors in Visual Micro (issue #483) +* Fixed compilation in IAR Embedded Workbench (issue #515) +* Fixed reading "true" as a float (issue #516) +* Added `ARDUINOJSON_DOUBLE_IS_64BITS` +* Added `ARDUINOJSON_EMBEDDED_MODE` + +v5.10.0 +------- + +* Removed configurable number of decimal places (issues #288, #427 and #506) +* Changed exponentiation thresholds to `1e7` and `1e-5` (issues #288, #427 and #506) +* `JsonVariant::is()` now returns `true` for integers +* Fixed error `IsBaseOf is not a member of ArduinoJson::TypeTraits` (issue #495) +* Fixed error `forming reference to reference` (issue #495) + +> ### BREAKING CHANGES :warning: +> +> | Old syntax | New syntax | +> |:--------------------------------|:--------------------| +> | `double_with_n_digits(3.14, 2)` | `3.14` | +> | `float_with_n_digits(3.14, 2)` | `3.14f` | +> | `obj.set("key", 3.14, 2)` | `obj["key"] = 3.14` | +> | `arr.add(3.14, 2)` | `arr.add(3.14)` | +> +> | Input | Old output | New output | +> |:----------|:-----------|:-----------| +> | `3.14159` | `3.14` | `3.14159` | +> | `42.0` | `42.00` | `42` | +> | `0.0` | `0.00` | `0` | +> +> | Expression | Old result | New result | +> |:-------------------------------|:-----------|:-----------| +> | `JsonVariant(42).is()` | `true` | `true` | +> | `JsonVariant(42).is()` | `false` | `true` | +> | `JsonVariant(42).is()` | `false` | `true` | + +v5.9.0 +------ + +* Added `JsonArray::remove(iterator)` (issue #479) +* Added `JsonObject::remove(iterator)` +* Renamed `JsonArray::removeAt(size_t)` into `remove(size_t)` +* Renamed folder `include/` to `src/` +* Fixed warnings `floating constant exceeds range of float`and `floating constant truncated to zero` (issue #483) +* Removed `Print` class and converted `printTo()` to a template method (issue #276) +* Removed example `IndentedPrintExample.ino` +* Now compatible with Particle 0.6.1, thanks to Jacob Nite (issue #294 and PR #461 by @foodbag) + +v5.8.4 +------ + +* Added custom implementation of `strtod()` (issue #453) +* Added custom implementation of `strtol()` (issue #465) +* `char` is now treated as an integral type (issue #337, #370) + +v5.8.3 +------ + +* Fixed an access violation in `DynamicJsonBuffer` when memory allocation fails (issue #433) +* Added operators `==` and `!=` for two `JsonVariant`s (issue #436) +* Fixed `JsonVariant::operator[const FlashStringHelper*]` (issue #441) + +v5.8.2 +------ + +* Fixed parsing of comments (issue #421) +* Fixed ignored `Stream` timeout (issue #422) +* Made sure we don't read more that necessary (issue #422) +* Fixed error when the key of a `JsonObject` is a `char[]` (issue #423) +* Reduced code size when using `const` references +* Fixed error with string of type `unsigned char*` (issue #428) +* Added `deprecated` attribute on `asArray()`, `asObject()` and `asString()` (issue #420) + +v5.8.1 +------ + +* Fixed error when assigning a `volatile int` to a `JsonVariant` (issue #415) +* Fixed errors with Variable Length Arrays (issue #416) +* Fixed error when both `ARDUINOJSON_ENABLE_STD_STREAM` and `ARDUINOJSON_ENABLE_ARDUINO_STREAM` are set to `1` +* Fixed error "Stream does not name a type" (issue #412) + +v5.8.0 +------ + +* Added operator `==` to compare `JsonVariant` and strings (issue #402) +* Added support for `Stream` (issue #300) +* Reduced memory consumption by not duplicating spaces and comments + +> ### BREAKING CHANGES :warning: +> +> `JsonBuffer::parseObject()` and `JsonBuffer::parseArray()` have been pulled down to the derived classes `DynamicJsonBuffer` and `StaticJsonBufferBase`. +> +> This means that if you have code like: +> +> ```c++ +> void myFunction(JsonBuffer& jsonBuffer); +> ``` +> +> you need to replace it with one of the following: +> +> ```c++ +> void myFunction(DynamicJsonBuffer& jsonBuffer); +> void myFunction(StaticJsonBufferBase& jsonBuffer); +> template void myFunction(TJsonBuffer& jsonBuffer); +> ``` + +v5.7.3 +------ + +* Added an `printTo(char[N])` and `prettyPrintTo(char[N])` (issue #292) +* Added ability to set a nested value like this: `root["A"]["B"] = "C"` (issue #352) +* Renamed `*.ipp` to `*Impl.hpp` because they were ignored by Arduino IDE (issue #396) + +v5.7.2 +------ + +* Made PROGMEM available on more platforms (issue #381) +* Fixed PROGMEM causing an exception on ESP8266 (issue #383) + +v5.7.1 +------ + +* Added support for PROGMEM (issue #76) +* Fixed compilation error when index is not an `int` (issue #381) + +v5.7.0 +------ + +* Templatized all functions using `String` or `std::string` +* Removed `ArduinoJson::String` +* Removed `JsonVariant::defaultValue()` +* Removed non-template `JsonObject::get()` and `JsonArray.get()` +* Fixed support for `StringSumHelper` (issue #184) +* Replaced `ARDUINOJSON_USE_ARDUINO_STRING` by `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_ARDUINO_STRING` (issue #378) +* Added example `StringExample.ino` to show where `String` can be used +* Increased default nesting limit to 50 when compiled for a computer (issue #349) + +> ### BREAKING CHANGES :warning: +> +> The non-template functions `JsonObject::get()` and `JsonArray.get()` have been removed. This means that you need to explicitely tell the type you expect in return. +> +> Old code: +> +> ```c++ +> #define ARDUINOJSON_USE_ARDUINO_STRING 0 +> JsonVariant value1 = myObject.get("myKey"); +> JsonVariant value2 = myArray.get(0); +> ``` +> +> New code: +> +> ```c++ +> #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 +> #define ARDUINOJSON_ENABLE_STD_STRING 1 +> JsonVariant value1 = myObject.get("myKey"); +> JsonVariant value2 = myArray.get(0); +> ``` + +v5.6.7 +------ + +* Fixed `array[idx].as()` and `object[key].as()` +* Fixed return value of `JsonObject::set()` (issue #350) +* Fixed undefined behavior in `Prettyfier` and `Print` (issue #354) +* Fixed parser that incorrectly rejected floats containing a `+` (issue #349) + +v5.6.6 +------ + +* Fixed `-Wparentheses` warning introduced in v5.6.5 (PR #335 by @nuket) +* Added `.mbedignore` for ARM mbdeb (PR #334 by @nuket) +* Fixed `JsonVariant::success()` which didn't propagate `JsonArray::success()` nor `JsonObject::success()` (issue #342). + +v5.6.5 +------ + +* `as()` now returns `true` when input is `null` (issue #330) + +v5.6.4 +------ + +* Fixed error in float serialization (issue #324) + +v5.6.3 +------ + +* Improved speed of float serialization (about twice faster) +* Added `as()` as a synonym for `as()`... (issue #291) +* Fixed `call of overloaded isinf(double&) is ambiguous` (issue #284) + +v5.6.2 +------ + +* Fixed build when another lib does `#undef isnan` (issue #284) + +v5.6.1 +------ + +* Added missing `#pragma once` (issue #310) + +v5.6.0 +------ + +* ArduinoJson is now a header-only library (issue #199) + +v5.5.1 +------ + +* Fixed compilation error with Intel Galileo (issue #299) + +v5.5.0 +------ + +* Added `JsonVariant::success()` (issue #279) +* Renamed `JsonVariant::invalid()` to `JsonVariant::defaultValue()` + +v5.4.0 +------ + +* Changed `::String` to `ArduinoJson::String` (issue #275) +* Changed `::Print` to `ArduinoJson::Print` too + +v5.3.0 +------ + +* Added custom implementation of `ftoa` (issues #266, #267, #269 and #270) +* Added `JsonVariant JsonBuffer::parse()` (issue #265) +* Fixed `unsigned long` printed as `signed long` (issue #170) + +v5.2.0 +------ + +* Added `JsonVariant::as()` as a synonym for `JsonVariant::as()` (issue #257) +* Added example `JsonHttpClient` (issue #256) +* Added `JsonArray::copyTo()` and `JsonArray::copyFrom()` (issue #254) +* Added `RawJson()` to insert pregenerated JSON portions (issue #259) + +v5.1.1 +------ + +* Removed `String` duplication when one replaces a value in a `JsonObject` (PR #232 by @ulion) + +v5.1.0 +------ + +* Added support of `long long` (issue #171) +* Moved all build settings to `ArduinoJson/Configuration.hpp` + +> ### BREAKING CHANGE :warning: +> +> If you defined `ARDUINOJSON_ENABLE_STD_STREAM`, you now need to define it to `1`. + +v5.0.8 +------ + +* Made the library compatible with [PlatformIO](http://platformio.org/) (issue #181) +* Fixed `JsonVariant::is()` that was incorrectly returning false (issue #214) + +v5.0.7 +------ + +* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)` +* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161) + +> ### BREAKING CHANGES :warning: +> +> - `JsonVariant(true).as()` now returns `"true"` instead of `"1"` +> - `JsonVariant(false).as()` now returns `"false"` instead of `"0"` + +v5.0.6 +------ + +* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152) +* Fixed warning about library category in Arduino 1.6.6 (issue #147) +* Examples: Added a loop to wait for serial port to be ready (issue #156) + +v5.0.5 +------ + +* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143) +* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134) + +v5.0.4 +------ + +* Fixed ambiguous overload with `JsonArraySubscript` and `JsonObjectSubscript` (issue #122) + +v5.0.3 +------ + +* Fixed `printTo(String)` which wrote numbers instead of strings (issue #120) +* Fixed return type of `JsonArray::is()` and some others (issue #121) + +v5.0.2 +------ + +* Fixed segmentation fault in `parseObject(String)` and `parseArray(String)`, when the + `StaticJsonBuffer` is too small to hold a copy of the string +* Fixed Clang warning "register specifier is deprecated" (issue #102) +* Fixed GCC warning "declaration shadows a member" (issue #103) +* Fixed memory alignment, which made ESP8266 crash (issue #104) +* Fixed compilation on Visual Studio 2010 and 2012 (issue #107) + +v5.0.1 +------ + +* Fixed compilation with Arduino 1.0.6 (issue #99) + +v5.0.0 +------ + +* Added support of `String` class (issues #55, #56, #70, #77) +* Added `JsonBuffer::strdup()` to make a copy of a string (issues #10, #57) +* Implicitly call `strdup()` for `String` but not for `char*` (issues #84, #87) +* Added support of non standard JSON input (issue #44) +* Added support of comments in JSON input (issue #88) +* Added implicit cast between numerical types (issues #64, #69, #93) +* Added ability to read number values as string (issue #90) +* Redesigned `JsonVariant` to leverage converting constructors instead of assignment operators (issue #66) +* Switched to new the library layout (requires Arduino 1.0.6 or above) + +> ### BREAKING CHANGES :warning: +> +> - `JsonObject::add()` was renamed to `set()` +> - `JsonArray::at()` and `JsonObject::at()` were renamed to `get()` +> - Number of digits of floating point value are now set with `double_with_n_digits()` + +**Personal note about the `String` class**: +Support of the `String` class has been added to the library because many people use it in their programs. +However, you should not see this as an invitation to use the `String` class. +The `String` class is **bad** because it uses dynamic memory allocation. +Compared to static allocation, it compiles to a bigger, slower program, and is less predictable. +You certainly don't want that in an embedded environment! diff --git a/lib_standalone/ArduinoJson/LICENSE.md b/lib/ArduinoJson/LICENSE.md similarity index 99% rename from lib_standalone/ArduinoJson/LICENSE.md rename to lib/ArduinoJson/LICENSE.md index 30cef0992..90cb7e66e 100644 --- a/lib_standalone/ArduinoJson/LICENSE.md +++ b/lib/ArduinoJson/LICENSE.md @@ -1,10 +1,10 @@ -The MIT License (MIT) ---------------------- - -Copyright © 2014-2020 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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +The MIT License (MIT) +--------------------- + +Copyright © 2014-2020 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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib_standalone/ArduinoJson/README.md b/lib/ArduinoJson/README.md similarity index 90% rename from lib_standalone/ArduinoJson/README.md rename to lib/ArduinoJson/README.md index a1e19af60..5ae324731 100644 --- a/lib_standalone/ArduinoJson/README.md +++ b/lib/ArduinoJson/README.md @@ -1,137 +1,137 @@ -![ArduinoJson](banner.svg) - ---- - -[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.15.0)](https://www.ardu-badge.com/ArduinoJson/6.15.0) -[![Build Status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) -[![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=6.x)](https://travis-ci.org/bblanchon/ArduinoJson) -[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) -[![Coverage Status](https://coveralls.io/repos/github/bblanchon/ArduinoJson/badge.svg?branch=6.x)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) -[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat)](https://github.com/bblanchon/ArduinoJson/stargazers) - -ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). - -## Features - -* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme) - * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/?utm_source=github&utm_medium=readme) - * [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme) - * [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/?utm_source=github&utm_medium=readme) - * [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering?utm_source=github&utm_medium=readme) - * Supports single quotes as a string delimiter - * Compatible with NDJSON and JSON Lines -* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme) - * [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme) - * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/?utm_source=github&utm_medium=readme) -* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/?utm_source=github&utm_medium=readme) -* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/?utm_source=github&utm_medium=readme) -* Efficient - * [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) - * [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) - * [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) - * [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme) - * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme) -* Versatile - * [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme) - * Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme) - * Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme) - * [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme) - * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer?utm_source=github&utm_medium=readme) -* Portable - * Usable on any C++ project (not limited to Arduino) - * Compatible with C++98 - * Zero warnings with `-Wall -Wextra -pedantic` and `/W4` - * [Header-only library](https://en.wikipedia.org/wiki/Header-only) - * Works with virtually any board - * Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)... - * Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB) - * Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)... - * Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj) - * Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)... - * Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)... - * Tested on all major development environments - * [Arduino IDE](https://www.arduino.cc/en/Main/Software) - * [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/) - * [Atollic TrueSTUDIO](https://atollic.com/truestudio/) - * [Energia](http://energia.nu/) - * [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/) - * [Keil uVision](http://www.keil.com/) - * [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide) - * [PlatformIO](http://platformio.org/) - * [Sloeber plugin for Eclipse](https://eclipse.baeyens.it/) - * [Visual Micro](http://www.visualmicro.com/) - * [Visual Studio](https://www.visualstudio.com/) - * [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/t7KP7I6dVuLhqzDl) -* Well designed - * [Elegant API](http://127.0.0.1:4000/v6/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/?utm_source=github&utm_medium=readme) - * [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming) - * Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows?utm_source=github&utm_medium=readme) -* Well tested - * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) - * Continuously tested on - * [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) - * [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson) - * [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson) - * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) -* Well documented - * [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) - * [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) - * [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) - * [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme) - * [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme) -* Vibrant user community - * Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search) - * [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson) - * [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed) - -## Quickstart - -### Deserialization - -Here is a program that parses a JSON document with ArduinoJson. - -```c++ -char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - -DynamicJsonDocument doc(1024); -deserializeJson(doc, json); - -const char* sensor = doc["sensor"]; -long time = doc["time"]; -double latitude = doc["data"][0]; -double longitude = doc["data"][1]; -``` - -See the [tutorial on arduinojson.org](https://arduinojson.org/doc/decoding/?utm_source=github&utm_medium=readme) - -### Serialization - -Here is a program that generates a JSON document with ArduinoJson: - -```c++ -DynamicJsonDocument doc(1024); - -doc["sensor"] = "gps"; -doc["time"] = 1351824120; - -JsonArray data = doc.createNestedArray("data"); -data.add(48.756080); -data.add(2.302038); - -serializeJson(doc, Serial); -// This prints: -// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} -``` - -See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme) - -## Support the project - -Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)! - -What? You don't like it but you *love* it? -We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time?utm_source=github&utm_medium=readme! +![ArduinoJson](banner.svg) + +--- + +[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.16.1)](https://www.ardu-badge.com/ArduinoJson/6.16.1) +[![Build Status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) +[![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=6.x)](https://travis-ci.org/bblanchon/ArduinoJson) +[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) +[![Coverage Status](https://coveralls.io/repos/github/bblanchon/ArduinoJson/badge.svg?branch=6.x)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) +[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat)](https://github.com/bblanchon/ArduinoJson/stargazers) + +ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). + +## Features + +* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme) + * [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/?utm_source=github&utm_medium=readme) + * [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme) + * [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/?utm_source=github&utm_medium=readme) + * [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#filtering) + * Supports single quotes as a string delimiter + * Compatible with NDJSON and JSON Lines +* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme) + * [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme) + * [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/?utm_source=github&utm_medium=readme) +* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/?utm_source=github&utm_medium=readme) +* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/?utm_source=github&utm_medium=readme) +* Efficient + * [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) + * [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) + * [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme) + * [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme) + * [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme) + * Deduplicates strings +* Versatile + * [Supports custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme) + * Supports [Arduino's `String`](https://arduinojson.org/v6/api/config/enable_arduino_string/) and [STL's `std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme) + * Supports Arduino's `Stream` and [STL's `std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme) + * [Supports Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme) + * Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer) +* Portable + * Usable on any C++ project (not limited to Arduino) + * Compatible with C++98 + * Zero warnings with `-Wall -Wextra -pedantic` and `/W4` + * [Header-only library](https://en.wikipedia.org/wiki/Header-only) + * Works with virtually any board + * Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)... + * Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB) + * Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)... + * Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj) + * Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)... + * Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)... + * Tested on all major development environments + * [Arduino IDE](https://www.arduino.cc/en/Main/Software) + * [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/) + * [Atollic TrueSTUDIO](https://atollic.com/truestudio/) + * [Energia](http://energia.nu/) + * [IAR Embedded Workbench](https://www.iar.com/iar-embedded-workbench/) + * [Keil uVision](http://www.keil.com/) + * [MPLAB X IDE](http://www.microchip.com/mplab/mplab-x-ide) + * [PlatformIO](http://platformio.org/) + * [Sloeber plugin for Eclipse](https://eclipse.baeyens.it/) + * [Visual Micro](http://www.visualmicro.com/) + * [Visual Studio](https://www.visualstudio.com/) + * [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/t7KP7I6dVuLhqzDl) + * [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/?utm_source=github&utm_medium=readme) +* Well designed + * [Elegant API](http://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) + * [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/?utm_source=github&utm_medium=readme) + * [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming) + * Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/?utm_source=github&utm_medium=readme#integer-overflows) +* Well tested + * [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x) + * Continuously tested on + * [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x) + * [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson) + * [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8](https://travis-ci.org/bblanchon/ArduinoJson) + * [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson) +* Well documented + * [Tutorials](https://arduinojson.org/v6/doc/deserialization/?utm_source=github&utm_medium=readme) + * [Examples](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) + * [How-tos](https://arduinojson.org/v6/example/?utm_source=github&utm_medium=readme) + * [FAQ](https://arduinojson.org/v6/faq/?utm_source=github&utm_medium=readme) + * [Book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme) +* Vibrant user community + * Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories) and [PlatformIO](https://platformio.org/lib/search) + * [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson) + * [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed) + +## Quickstart + +### Deserialization + +Here is a program that parses a JSON document with ArduinoJson. + +```c++ +char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; + +DynamicJsonDocument doc(1024); +deserializeJson(doc, json); + +const char* sensor = doc["sensor"]; +long time = doc["time"]; +double latitude = doc["data"][0]; +double longitude = doc["data"][1]; +``` + +See the [tutorial on arduinojson.org](https://arduinojson.org/doc/decoding/?utm_source=github&utm_medium=readme) + +### Serialization + +Here is a program that generates a JSON document with ArduinoJson: + +```c++ +DynamicJsonDocument doc(1024); + +doc["sensor"] = "gps"; +doc["time"] = 1351824120; +doc["data"][0] = 48.756080; +doc["data"][1] = 2.302038; + +serializeJson(doc, Serial); +// This prints: +// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} +``` + +See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme) + +## Support the project + +Do you like this library? Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)! + +What? You don't like it but you *love* it? +We don't take donations anymore, but [we sell a book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme), so you can help and learn at the same time. diff --git a/lib/ArduinoJson/examples/JsonConfigFile/JsonConfigFile.ino b/lib/ArduinoJson/examples/JsonConfigFile/JsonConfigFile.ino new file mode 100644 index 000000000..e674e6652 --- /dev/null +++ b/lib/ArduinoJson/examples/JsonConfigFile/JsonConfigFile.ino @@ -0,0 +1,154 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to store your project configuration in a file. +// It uses the SD library but can be easily modified for any other file-system. +// +// The file contains a JSON document with the following content: +// { +// "hostname": "examples.com", +// "port": 2731 +// } +// +// To run this program, you need an SD card connected to the SPI bus as follows: +// * MOSI <-> pin 11 +// * MISO <-> pin 12 +// * CLK <-> pin 13 +// * CS <-> pin 4 +// +// https://arduinojson.org/v6/example/config/ + +#include +#include +#include + +// Our configuration structure. +// +// Never use a JsonDocument to store the configuration! +// A JsonDocument is *not* a permanent storage; it's only a temporary storage +// used during the serialization phase. See: +// https://arduinojson.org/v6/faq/why-must-i-create-a-separate-config-object/ +struct Config { + char hostname[64]; + int port; +}; + +const char *filename = "/config.txt"; // <- SD library uses 8.3 filenames +Config config; // <- global configuration object + +// Loads the configuration from a file +void loadConfiguration(const char *filename, Config &config) { + // Open file for reading + File file = SD.open(filename); + + // Allocate a temporary JsonDocument + // Don't forget to change the capacity to match your requirements. + // Use arduinojson.org/v6/assistant to compute the capacity. + StaticJsonDocument<512> doc; + + // Deserialize the JSON document + DeserializationError error = deserializeJson(doc, file); + if (error) + Serial.println(F("Failed to read file, using default configuration")); + + // Copy values from the JsonDocument to the Config + config.port = doc["port"] | 2731; + strlcpy(config.hostname, // <- destination + doc["hostname"] | "example.com", // <- source + sizeof(config.hostname)); // <- destination's capacity + + // Close the file (Curiously, File's destructor doesn't close the file) + file.close(); +} + +// Saves the configuration to a file +void saveConfiguration(const char *filename, const Config &config) { + // Delete existing file, otherwise the configuration is appended to the file + SD.remove(filename); + + // Open file for writing + File file = SD.open(filename, FILE_WRITE); + if (!file) { + Serial.println(F("Failed to create file")); + return; + } + + // Allocate a temporary JsonDocument + // Don't forget to change the capacity to match your requirements. + // Use arduinojson.org/assistant to compute the capacity. + StaticJsonDocument<256> doc; + + // Set the values in the document + doc["hostname"] = config.hostname; + doc["port"] = config.port; + + // Serialize JSON to file + if (serializeJson(doc, file) == 0) { + Serial.println(F("Failed to write to file")); + } + + // Close the file + file.close(); +} + +// Prints the content of a file to the Serial +void printFile(const char *filename) { + // Open file for reading + File file = SD.open(filename); + if (!file) { + Serial.println(F("Failed to read file")); + return; + } + + // Extract each characters by one by one + while (file.available()) { + Serial.print((char)file.read()); + } + Serial.println(); + + // Close the file + file.close(); +} + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // Initialize SD library + const int chipSelect = 4; + while (!SD.begin(chipSelect)) { + Serial.println(F("Failed to initialize SD library")); + delay(1000); + } + + // Should load default config if run for the first time + Serial.println(F("Loading configuration...")); + loadConfiguration(filename, config); + + // Create configuration file + Serial.println(F("Saving configuration...")); + saveConfiguration(filename, config); + + // Dump config file + Serial.println(F("Print config file...")); + printFile(filename); +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// serialization or deserialization problem. +// +// The book "Mastering ArduinoJson" contains a case study of a project that has +// a complex configuration with nested members. +// Contrary to this example, the project in the book uses the SPIFFS filesystem. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib/ArduinoJson/examples/JsonFilterExample/JsonFilterExample.ino b/lib/ArduinoJson/examples/JsonFilterExample/JsonFilterExample.ino new file mode 100644 index 000000000..ad37e6b9b --- /dev/null +++ b/lib/ArduinoJson/examples/JsonFilterExample/JsonFilterExample.ino @@ -0,0 +1,63 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to use DeserializationOpion::Filter +// +// https://arduinojson.org/v6/example/filter/ + +#include + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // The huge input: an extract from OpenWeatherMap response + const __FlashStringHelper* input_json = F( + "{\"cod\":\"200\",\"message\":0,\"list\":[{\"dt\":1581498000,\"main\":{" + "\"temp\":3.23,\"feels_like\":-3.63,\"temp_min\":3.23,\"temp_max\":4.62," + "\"pressure\":1014,\"sea_level\":1014,\"grnd_level\":1010,\"humidity\":" + "58,\"temp_kf\":-1.39},\"weather\":[{\"id\":800,\"main\":\"Clear\"," + "\"description\":\"clear " + "sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":0},\"wind\":{\"speed\":6." + "19,\"deg\":266},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 " + "09:00:00\"},{\"dt\":1581508800,\"main\":{\"temp\":6.09,\"feels_like\":-" + "1.07,\"temp_min\":6.09,\"temp_max\":7.13,\"pressure\":1015,\"sea_" + "level\":1015,\"grnd_level\":1011,\"humidity\":48,\"temp_kf\":-1.04}," + "\"weather\":[{\"id\":800,\"main\":\"Clear\",\"description\":\"clear " + "sky\",\"icon\":\"01d\"}],\"clouds\":{\"all\":9},\"wind\":{\"speed\":6." + "64,\"deg\":268},\"sys\":{\"pod\":\"d\"},\"dt_txt\":\"2020-02-12 " + "12:00:00\"}],\"city\":{\"id\":2643743,\"name\":\"London\",\"coord\":{" + "\"lat\":51.5085,\"lon\":-0.1257},\"country\":\"GB\",\"population\":" + "1000000,\"timezone\":0,\"sunrise\":1581492085,\"sunset\":1581527294}}"); + + // The filter: it contains "true" for each value we want to keep + StaticJsonDocument<200> filter; + filter["list"][0]["dt"] = true; + filter["list"][0]["main"]["temp"] = true; + + // Deserialize the document + StaticJsonDocument<400> doc; + deserializeJson(doc, input_json, DeserializationOption::Filter(filter)); + + // Print the result + serializeJsonPretty(doc, Serial); +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// deserialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on deserialization. +// It begins with a simple example, like the one above, and then adds more +// features like deserializing directly from a file or an HTTP request. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib_standalone/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp b/lib/ArduinoJson/examples/JsonGeneratorExample/JsonGeneratorExample.ino similarity index 51% rename from lib_standalone/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp rename to lib/ArduinoJson/examples/JsonGeneratorExample/JsonGeneratorExample.ino index 21a66db1f..e2ec4a98d 100644 --- a/lib_standalone/ArduinoJson/extras/scripts/wandbox/JsonGeneratorExample.cpp +++ b/lib/ArduinoJson/examples/JsonGeneratorExample/JsonGeneratorExample.ino @@ -1,60 +1,77 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License -// -// This example shows how to generate a JSON document with ArduinoJson. - -#include -#include "ArduinoJson.h" - -int main() { - // Allocate the JSON document - // - // Inside the brackets, 200 is the RAM allocated to this document. - // Don't forget to change this value to match your requirement. - // Use arduinojson.org/v6/assistant to compute the capacity. - StaticJsonDocument<200> doc; - - // StaticJsonObject allocates memory on the stack, it can be - // replaced by DynamicJsonDocument which allocates in the heap. - // - // DynamicJsonDocument doc(200); - - // StaticJsonObject allocates memory on the stack, it can be - // replaced by DynamicJsonDocument which allocates in the heap. - // - // DynamicJsonDocument doc(200); - - // Add values in the document - // - doc["sensor"] = "gps"; - doc["time"] = 1351824120; - - // Add an array. - // - JsonArray data = doc.createNestedArray("data"); - data.add(48.756080); - data.add(2.302038); - - // Generate the minified JSON and send it to STDOUT - // - serializeJson(doc, std::cout); - // The above line prints: - // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} - - // Start a new line - std::cout << std::endl; - - // Generate the prettified JSON and send it to STDOUT - // - serializeJsonPretty(doc, std::cout); - // The above line prints: - // { - // "sensor": "gps", - // "time": 1351824120, - // "data": [ - // 48.756080, - // 2.302038 - // ] - // } -} +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to generate a JSON document with ArduinoJson. +// +// https://arduinojson.org/v6/example/generator/ + +#include + +void setup() { + // Initialize Serial port + Serial.begin(9600); + while (!Serial) continue; + + // Allocate the JSON document + // + // Inside the brackets, 200 is the RAM allocated to this document. + // Don't forget to change this value to match your requirement. + // Use arduinojson.org/v6/assistant to compute the capacity. + StaticJsonDocument<200> doc; + + // StaticJsonObject allocates memory on the stack, it can be + // replaced by DynamicJsonDocument which allocates in the heap. + // + // DynamicJsonDocument doc(200); + + // Add values in the document + // + doc["sensor"] = "gps"; + doc["time"] = 1351824120; + + // Add an array. + // + JsonArray data = doc.createNestedArray("data"); + data.add(48.756080); + data.add(2.302038); + + // Generate the minified JSON and send it to the Serial port. + // + serializeJson(doc, Serial); + // The above line prints: + // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} + + // Start a new line + Serial.println(); + + // Generate the prettified JSON and send it to the Serial port. + // + serializeJsonPretty(doc, Serial); + // The above line prints: + // { + // "sensor": "gps", + // "time": 1351824120, + // "data": [ + // 48.756080, + // 2.302038 + // ] + // } +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// serialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on serialization. +// It begins with a simple example, like the one above, and then adds more +// features like serializing directly to a file or an HTTP request. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino b/lib/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino new file mode 100644 index 000000000..9614217b3 --- /dev/null +++ b/lib/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino @@ -0,0 +1,116 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to parse a JSON document in an HTTP response. +// It uses the Ethernet library, but can be easily adapted for Wifi. +// +// It performs a GET resquest on arduinojson.org/example.json +// Here is the expected response: +// { +// "sensor": "gps", +// "time": 1351824120, +// "data": [ +// 48.756080, +// 2.302038 +// ] +// } +// +// https://arduinojson.org/v6/example/http-client/ + +#include +#include +#include + +void setup() { + // Initialize Serial port + Serial.begin(9600); + while (!Serial) continue; + + // Initialize Ethernet library + byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; + if (!Ethernet.begin(mac)) { + Serial.println(F("Failed to configure Ethernet")); + return; + } + delay(1000); + + Serial.println(F("Connecting...")); + + // Connect to HTTP server + EthernetClient client; + client.setTimeout(10000); + if (!client.connect("arduinojson.org", 80)) { + Serial.println(F("Connection failed")); + return; + } + + Serial.println(F("Connected!")); + + // Send HTTP request + client.println(F("GET /example.json HTTP/1.0")); + client.println(F("Host: arduinojson.org")); + client.println(F("Connection: close")); + if (client.println() == 0) { + Serial.println(F("Failed to send request")); + return; + } + + // Check HTTP status + char status[32] = {0}; + client.readBytesUntil('\r', status, sizeof(status)); + // It should be "HTTP/1.0 200 OK" or "HTTP/1.1 200 OK" + if (strcmp(status + 9, "200 OK") != 0) { + Serial.print(F("Unexpected response: ")); + Serial.println(status); + return; + } + + // Skip HTTP headers + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println(F("Invalid response")); + return; + } + + // Allocate the JSON document + // Use arduinojson.org/v6/assistant to compute the capacity. + const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60; + DynamicJsonDocument doc(capacity); + + // Parse JSON object + DeserializationError error = deserializeJson(doc, client); + if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + return; + } + + // Extract values + Serial.println(F("Response:")); + Serial.println(doc["sensor"].as()); + Serial.println(doc["time"].as()); + Serial.println(doc["data"][0].as(), 6); + Serial.println(doc["data"][1].as(), 6); + + // Disconnect + client.stop(); +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// serialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on deserialization +// showing how to parse the response from GitHub's API. In the last chapter, +// it shows how to parse the huge documents from OpenWeatherMap +// and Reddit. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib_standalone/ArduinoJson/extras/scripts/wandbox/JsonParserExample.cpp b/lib/ArduinoJson/examples/JsonParserExample/JsonParserExample.ino similarity index 58% rename from lib_standalone/ArduinoJson/extras/scripts/wandbox/JsonParserExample.cpp rename to lib/ArduinoJson/examples/JsonParserExample/JsonParserExample.ino index 8cf6b9e9d..62ff8782b 100644 --- a/lib_standalone/ArduinoJson/extras/scripts/wandbox/JsonParserExample.cpp +++ b/lib/ArduinoJson/examples/JsonParserExample/JsonParserExample.ino @@ -1,59 +1,80 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License -// -// This example shows how to deserialize a JSON document with ArduinoJson. - -#include -#include "ArduinoJson.h" - -int main() { - // Allocate the JSON document - // - // Inside the brackets, 200 is the capacity of the memory pool in bytes. - // Don't forget to change this value to match your JSON document. - // Use arduinojson.org/v6/assistant to compute the capacity. - StaticJsonDocument<300> doc; - - // StaticJsonDocument allocates memory on the stack, it can be - // replaced by DynamicJsonDocument which allocates in the heap. - // - // DynamicJsonDocument doc(200); - - // JSON input string. - // - // Using a char[], as shown here, enables the "zero-copy" mode. This mode uses - // the minimal amount of memory because the JsonDocument stores pointers to - // the input buffer. - // If you use another type of input, ArduinoJson must copy the strings from - // the input to the JsonDocument, so you need to increase the capacity of the - // JsonDocument. - char json[] = - "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - - // Deserialize the JSON document - DeserializationError error = deserializeJson(doc, json); - - // Test if parsing succeeds. - if (error) { - std::cerr << "deserializeJson() failed: " << error.c_str() << std::endl; - return 1; - } - - // Fetch values. - // - // Most of the time, you can rely on the implicit casts. - // In other case, you can do doc["time"].as(); - const char* sensor = doc["sensor"]; - long time = doc["time"]; - double latitude = doc["data"][0]; - double longitude = doc["data"][1]; - - // Print values. - std::cout << sensor << std::endl; - std::cout << time << std::endl; - std::cout << latitude << std::endl; - std::cout << longitude << std::endl; - - return 0; -} +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to deserialize a JSON document with ArduinoJson. +// +// https://arduinojson.org/v6/example/parser/ + +#include + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // Allocate the JSON document + // + // Inside the brackets, 200 is the capacity of the memory pool in bytes. + // Don't forget to change this value to match your JSON document. + // Use arduinojson.org/v6/assistant to compute the capacity. + StaticJsonDocument<200> doc; + + // StaticJsonDocument allocates memory on the stack, it can be + // replaced by DynamicJsonDocument which allocates in the heap. + // + // DynamicJsonDocument doc(200); + + // JSON input string. + // + // Using a char[], as shown here, enables the "zero-copy" mode. This mode uses + // the minimal amount of memory because the JsonDocument stores pointers to + // the input buffer. + // If you use another type of input, ArduinoJson must copy the strings from + // the input to the JsonDocument, so you need to increase the capacity of the + // JsonDocument. + char json[] = + "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; + + // Deserialize the JSON document + DeserializationError error = deserializeJson(doc, json); + + // Test if parsing succeeds. + if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + return; + } + + // Fetch values. + // + // Most of the time, you can rely on the implicit casts. + // In other case, you can do doc["time"].as(); + const char* sensor = doc["sensor"]; + long time = doc["time"]; + double latitude = doc["data"][0]; + double longitude = doc["data"][1]; + + // Print values. + Serial.println(sensor); + Serial.println(time); + Serial.println(latitude, 6); + Serial.println(longitude, 6); +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// deserialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on deserialization. +// It begins with a simple example, like the one above, and then adds more +// features like deserializing directly from a file or an HTTP request. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib/ArduinoJson/examples/JsonServer/JsonServer.ino b/lib/ArduinoJson/examples/JsonServer/JsonServer.ino new file mode 100644 index 000000000..e0eea3fc6 --- /dev/null +++ b/lib/ArduinoJson/examples/JsonServer/JsonServer.ino @@ -0,0 +1,110 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to implement an HTTP server that sends a JSON document +// in the response. +// It uses the Ethernet library but can be easily adapted for Wifi. +// +// The JSON document contains the values of the analog and digital pins. +// It looks like that: +// { +// "analog": [0, 76, 123, 158, 192, 205], +// "digital": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0] +// } +// +// https://arduinojson.org/v6/example/http-server/ + +#include +#include +#include + +byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +EthernetServer server(80); + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // Initialize Ethernet libary + if (!Ethernet.begin(mac)) { + Serial.println(F("Failed to initialize Ethernet library")); + return; + } + + // Start to listen + server.begin(); + + Serial.println(F("Server is ready.")); + Serial.print(F("Please connect to http://")); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // Wait for an incomming connection + EthernetClient client = server.available(); + + // Do we have a client? + if (!client) return; + + Serial.println(F("New client")); + + // Read the request (we ignore the content in this example) + while (client.available()) client.read(); + + // Allocate a temporary JsonDocument + // Use arduinojson.org/v6/assistant to compute the capacity. + StaticJsonDocument<500> doc; + + // Create the "analog" array + JsonArray analogValues = doc.createNestedArray("analog"); + for (int pin = 0; pin < 6; pin++) { + // Read the analog input + int value = analogRead(pin); + + // Add the value at the end of the array + analogValues.add(value); + } + + // Create the "digital" array + JsonArray digitalValues = doc.createNestedArray("digital"); + for (int pin = 0; pin < 14; pin++) { + // Read the digital input + int value = digitalRead(pin); + + // Add the value at the end of the array + digitalValues.add(value); + } + + Serial.print(F("Sending: ")); + serializeJson(doc, Serial); + Serial.println(); + + // Write response headers + client.println(F("HTTP/1.0 200 OK")); + client.println(F("Content-Type: application/json")); + client.println(F("Connection: close")); + client.print(F("Content-Length: ")); + client.println(measureJsonPretty(doc)); + client.println(); + + // Write JSON document + serializeJsonPretty(doc, client); + + // Disconnect + client.stop(); +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// serialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on serialization. +// It begins with a simple example, then adds more features like serializing +// directly to a file or an HTTP client. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib/ArduinoJson/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/lib/ArduinoJson/examples/JsonUdpBeacon/JsonUdpBeacon.ino new file mode 100644 index 000000000..71fec895e --- /dev/null +++ b/lib/ArduinoJson/examples/JsonUdpBeacon/JsonUdpBeacon.ino @@ -0,0 +1,100 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to send a JSON document to a UDP socket. +// At regular interval, it sends a UDP packet that contains the status of +// analog and digital pins. +// It looks like that: +// { +// "analog": [0, 76, 123, 158, 192, 205], +// "digital": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0] +// } +// +// If you want to test this program, you need to be able to receive the UDP +// packets. +// For example, you can run netcat on your computer +// $ ncat -ulp 8888 +// See https://nmap.org/ncat/ +// +// https://arduinojson.org/v6/example/udp-beacon/ + +#include +#include +#include + +byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +IPAddress remoteIp(192, 168, 0, 108); // <- EDIT!!!! +unsigned short remotePort = 8888; +unsigned short localPort = 8888; +EthernetUDP udp; + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // Initialize Ethernet libary + if (!Ethernet.begin(mac)) { + Serial.println(F("Failed to initialize Ethernet library")); + return; + } + + // Enable UDP + udp.begin(localPort); +} + +void loop() { + // Allocate a temporary JsonDocument + // Use arduinojson.org/v6/assistant to compute the capacity. + StaticJsonDocument<500> doc; + + // Create the "analog" array + JsonArray analogValues = doc.createNestedArray("analog"); + for (int pin = 0; pin < 6; pin++) { + // Read the analog input + int value = analogRead(pin); + + // Add the value at the end of the array + analogValues.add(value); + } + + // Create the "digital" array + JsonArray digitalValues = doc.createNestedArray("digital"); + for (int pin = 0; pin < 14; pin++) { + // Read the digital input + int value = digitalRead(pin); + + // Add the value at the end of the array + digitalValues.add(value); + } + + // Log + Serial.print(F("Sending to ")); + Serial.print(remoteIp); + Serial.print(F(" on port ")); + Serial.println(remotePort); + serializeJson(doc, Serial); + + // Send UDP packet + udp.beginPacket(remoteIp, remotePort); + serializeJson(doc, udp); + udp.println(); + udp.endPacket(); + + // Wait + delay(10000); +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any +// serialization problem. +// +// The book "Mastering ArduinoJson" contains a tutorial on serialization. +// It begins with a simple example, then adds more features like serializing +// directly to a file or any stream. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib_standalone/ArduinoJson/extras/scripts/wandbox/MsgPackParserExample.cpp b/lib/ArduinoJson/examples/MsgPackParser/MsgPackParser.ino similarity index 51% rename from lib_standalone/ArduinoJson/extras/scripts/wandbox/MsgPackParserExample.cpp rename to lib/ArduinoJson/examples/MsgPackParser/MsgPackParser.ino index 241d76913..bae9bdae9 100644 --- a/lib_standalone/ArduinoJson/extras/scripts/wandbox/MsgPackParserExample.cpp +++ b/lib/ArduinoJson/examples/MsgPackParser/MsgPackParser.ino @@ -1,68 +1,75 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License -// -// This example shows how to generate a JSON document with ArduinoJson. - -#include -#include "ArduinoJson.h" - -int main() { - // Allocate the JSON document - // - // Inside the brackets, 300 is the size of the memory pool in bytes. - // Don't forget to change this value to match your JSON document. - // Use arduinojson.org/assistant to compute the capacity. - StaticJsonDocument<300> doc; - - // StaticJsonObject allocates memory on the stack, it can be - // replaced by DynamicJsonObject which allocates in the heap. - // - // DynamicJsonObject doc(200); - - // MessagePack input string. - // - // It's better to use a char[] as shown here. - // If you use a const char* or a String, ArduinoJson will - // have to make a copy of the input in the JsonBuffer. - uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115, - 164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100, - 97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148, - 112, 203, 64, 2, 106, 146, 230, 33, 49, 169}; - // This MessagePack document contains: - // { - // "sensor": "gps", - // "time": 1351824120, - // "data": [48.75608, 2.302038] - // } - - // doc of the object tree. - // - // It's a reference to the JsonObject, the actual bytes are inside the - // JsonBuffer with all the other nodes of the object tree. - // Memory is freed when jsonBuffer goes out of scope. - DeserializationError error = deserializeMsgPack(doc, input); - - // Test if parsing succeeds. - if (error) { - std::cerr << "deserializeMsgPack() failed: " << error.c_str() << std::endl; - return 1; - } - - // Fetch values. - // - // Most of the time, you can rely on the implicit casts. - // In other case, you can do doc["time"].as(); - const char* sensor = doc["sensor"]; - long time = doc["time"]; - double latitude = doc["data"][0]; - double longitude = doc["data"][1]; - - // Print values. - std::cout << sensor << std::endl; - std::cout << time << std::endl; - std::cout << latitude << std::endl; - std::cout << longitude << std::endl; - - return 0; -} +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows how to deserialize a MessagePack document with +// ArduinoJson. +// +// https://arduinojson.org/v6/example/msgpack-parser/ + +#include + +void setup() { + // Initialize serial port + Serial.begin(9600); + while (!Serial) continue; + + // Allocate the JSON document + // + // Inside the brackets, 200 is the capacity of the memory pool in bytes. + // Don't forget to change this value to match your JSON document. + // Use arduinojson.org/v6/assistant to compute the capacity. + StaticJsonDocument<200> doc; + + // StaticJsonObject allocates memory on the stack, it can be + // replaced by DynamicJsonObject which allocates in the heap. + // + // DynamicJsonObject doc(200); + + // MessagePack input string. + // + // Using a char[], as shown here, enables the "zero-copy" mode. This mode uses + // the minimal amount of memory because the JsonDocument stores pointers to + // the input buffer. + // If you use another type of input, ArduinoJson must copy the strings from + // the input to the JsonDocument, so you need to increase the capacity of the + // JsonDocument. + uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115, + 164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100, + 97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148, + 112, 203, 64, 2, 106, 146, 230, 33, 49, 169}; + // This MessagePack document contains: + // { + // "sensor": "gps", + // "time": 1351824120, + // "data": [48.75608, 2.302038] + // } + + DeserializationError error = deserializeMsgPack(doc, input); + + // Test if parsing succeeded. + if (error) { + Serial.print("deserializeMsgPack() failed: "); + Serial.println(error.c_str()); + return; + } + + // Fetch values. + // + // Most of the time, you can rely on the implicit casts. + // In other case, you can do doc["time"].as(); + const char* sensor = doc["sensor"]; + long time = doc["time"]; + double latitude = doc["data"][0]; + double longitude = doc["data"][1]; + + // Print values. + Serial.println(sensor); + Serial.println(time); + Serial.println(latitude, 6); + Serial.println(longitude, 6); +} + +void loop() { + // not used in this example +} diff --git a/lib/ArduinoJson/examples/ProgmemExample/ProgmemExample.ino b/lib/ArduinoJson/examples/ProgmemExample/ProgmemExample.ino new file mode 100644 index 000000000..7b7f81612 --- /dev/null +++ b/lib/ArduinoJson/examples/ProgmemExample/ProgmemExample.ino @@ -0,0 +1,72 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows the different ways you can use Flash strings with +// ArduinoJson. +// +// Use Flash strings sparingly, because ArduinoJson duplicates them in the +// JsonDocument. Prefer plain old char*, as they are more efficient in term of +// code size, speed, and memory usage. +// +// https://arduinojson.org/v6/example/progmem/ + +#include + +void setup() { +#ifdef PROGMEM // <- check that Flash strings are supported + + DynamicJsonDocument doc(1024); + + // You can use a Flash String as your JSON input. + // WARNING: the strings in the input will be duplicated in the JsonDocument. + deserializeJson(doc, F("{\"sensor\":\"gps\",\"time\":1351824120," + "\"data\":[48.756080,2.302038]}")); + JsonObject obj = doc.as(); + + // You can use a Flash String to get an element of a JsonObject + // No duplication is done. + long time = obj[F("time")]; + + // You can use a Flash String to set an element of a JsonObject + // WARNING: the content of the Flash String will be duplicated in the + // JsonDocument. + obj[F("time")] = time; + + // You can set a Flash String to a JsonObject or JsonArray: + // WARNING: the content of the Flash String will be duplicated in the + // JsonDocument. + obj["sensor"] = F("gps"); + + // It works with serialized() too: + obj["sensor"] = serialized(F("\"gps\"")); + obj["sensor"] = serialized(F("\xA3gps"), 3); + + // You can compare the content of a JsonVariant to a Flash String + if (obj["sensor"] == F("gps")) { + // ... + } + +#else + +#warning PROGMEM is not supported on this platform + +#endif +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any memory +// problem. +// +// The book "Mastering ArduinoJson" contains a quick C++ course that explains +// how your microcontroller stores strings in memory. It also tells why you +// should not abuse Flash strings with ArduinoJson. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib/ArduinoJson/examples/StringExample/StringExample.ino b/lib/ArduinoJson/examples/StringExample/StringExample.ino new file mode 100644 index 000000000..9fb443aed --- /dev/null +++ b/lib/ArduinoJson/examples/StringExample/StringExample.ino @@ -0,0 +1,77 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License +// +// This example shows the different ways you can use String with ArduinoJson. +// +// Use String objects sparingly, because ArduinoJson duplicates them in the +// JsonDocument. Prefer plain old char[], as they are more efficient in term of +// code size, speed, and memory usage. +// +// https://arduinojson.org/v6/example/string/ + +#include + +void setup() { + DynamicJsonDocument doc(1024); + + // You can use a String as your JSON input. + // WARNING: the string in the input will be duplicated in the JsonDocument. + String input = + "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; + deserializeJson(doc, input); + JsonObject obj = doc.as(); + + // You can use a String to get an element of a JsonObject + // No duplication is done. + long time = obj[String("time")]; + + // You can use a String to set an element of a JsonObject + // WARNING: the content of the String will be duplicated in the JsonDocument. + obj[String("time")] = time; + + // You can get a String from a JsonObject or JsonArray: + // No duplication is done, at least not in the JsonDocument. + String sensor = obj["sensor"]; + + // Unfortunately, the following doesn't work (issue #118): + // sensor = obj["sensor"]; // <- error "ambiguous overload for 'operator='" + // As a workaround, you need to replace by: + sensor = obj["sensor"].as(); + + // You can set a String to a JsonObject or JsonArray: + // WARNING: the content of the String will be duplicated in the JsonDocument. + obj["sensor"] = sensor; + + // It works with serialized() too: + obj["sensor"] = serialized(sensor); + + // You can also concatenate strings + // WARNING: the content of the String will be duplicated in the JsonDocument. + obj[String("sen") + "sor"] = String("gp") + "s"; + + // You can compare the content of a JsonObject with a String + if (obj["sensor"] == sensor) { + // ... + } + + // Lastly, you can print the resulting JSON to a String + String output; + serializeJson(doc, output); +} + +void loop() { + // not used in this example +} + +// See also +// -------- +// +// https://arduinojson.org/ contains the documentation for all the functions +// used above. It also includes an FAQ that will help you solve any problem. +// +// The book "Mastering ArduinoJson" contains a quick C++ course that explains +// how your microcontroller stores strings in memory. On several occasions, it +// shows how you can avoid String in your program. +// Learn more at https://arduinojson.org/book/ +// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤ diff --git a/lib_standalone/ArduinoJson/keywords.txt b/lib/ArduinoJson/keywords.txt similarity index 95% rename from lib_standalone/ArduinoJson/keywords.txt rename to lib/ArduinoJson/keywords.txt index a0c8d3810..a67a17f00 100644 --- a/lib_standalone/ArduinoJson/keywords.txt +++ b/lib/ArduinoJson/keywords.txt @@ -1,39 +1,39 @@ -# 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 -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 +# 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 +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_standalone/ArduinoJson/library.properties b/lib/ArduinoJson/library.properties similarity index 96% rename from lib_standalone/ArduinoJson/library.properties rename to lib/ArduinoJson/library.properties index b5f138474..7af2db406 100644 --- a/lib_standalone/ArduinoJson/library.properties +++ b/lib/ArduinoJson/library.properties @@ -1,11 +1,11 @@ -name=ArduinoJson -version=6.15.0 -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 +name=ArduinoJson +version=6.16.1 +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_standalone/ArduinoJson/src/ArduinoJson.h b/lib/ArduinoJson/src/ArduinoJson.h similarity index 94% rename from lib_standalone/ArduinoJson/src/ArduinoJson.h rename to lib/ArduinoJson/src/ArduinoJson.h index e5aac0fed..74eadd9b3 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson.h +++ b/lib/ArduinoJson/src/ArduinoJson.h @@ -1,17 +1,17 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#ifdef __cplusplus - -#include "ArduinoJson.hpp" - -using namespace ArduinoJson; - -#else - -#error ArduinoJson requires a C++ compiler, please change file extension to .cc or .cpp - -#endif +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#ifdef __cplusplus + +#include "ArduinoJson.hpp" + +using namespace ArduinoJson; + +#else + +#error ArduinoJson requires a C++ compiler, please change file extension to .cc or .cpp + +#endif diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson.hpp b/lib/ArduinoJson/src/ArduinoJson.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson.hpp rename to lib/ArduinoJson/src/ArduinoJson.hpp index d2a1f6309..040d2dbe4 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson.hpp +++ b/lib/ArduinoJson/src/ArduinoJson.hpp @@ -1,72 +1,73 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include "ArduinoJson/Configuration.hpp" - -#if !ARDUINOJSON_DEBUG -#ifdef __clang__ -#pragma clang system_header -#elif defined __GNUC__ -#pragma GCC system_header -#endif -#endif - -#include "ArduinoJson/Array/ArrayRef.hpp" -#include "ArduinoJson/Object/ObjectRef.hpp" -#include "ArduinoJson/Variant/VariantRef.hpp" - -#include "ArduinoJson/Document/DynamicJsonDocument.hpp" -#include "ArduinoJson/Document/StaticJsonDocument.hpp" - -#include "ArduinoJson/Array/ArrayImpl.hpp" -#include "ArduinoJson/Array/ElementProxy.hpp" -#include "ArduinoJson/Array/Utilities.hpp" -#include "ArduinoJson/Collection/CollectionImpl.hpp" -#include "ArduinoJson/Object/MemberProxy.hpp" -#include "ArduinoJson/Object/ObjectImpl.hpp" -#include "ArduinoJson/Variant/VariantAsImpl.hpp" -#include "ArduinoJson/Variant/VariantImpl.hpp" - -#include "ArduinoJson/Json/JsonDeserializer.hpp" -#include "ArduinoJson/Json/JsonSerializer.hpp" -#include "ArduinoJson/Json/PrettyJsonSerializer.hpp" -#include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp" -#include "ArduinoJson/MsgPack/MsgPackSerializer.hpp" - -#include "ArduinoJson/compatibility.hpp" - -namespace ArduinoJson { -typedef ARDUINOJSON_NAMESPACE::ArrayConstRef JsonArrayConst; -typedef ARDUINOJSON_NAMESPACE::ArrayRef JsonArray; -typedef ARDUINOJSON_NAMESPACE::Float JsonFloat; -typedef ARDUINOJSON_NAMESPACE::Integer JsonInteger; -typedef ARDUINOJSON_NAMESPACE::ObjectConstRef JsonObjectConst; -typedef ARDUINOJSON_NAMESPACE::ObjectRef JsonObject; -typedef ARDUINOJSON_NAMESPACE::Pair JsonPair; -typedef ARDUINOJSON_NAMESPACE::PairConst JsonPairConst; -typedef ARDUINOJSON_NAMESPACE::String JsonString; -typedef ARDUINOJSON_NAMESPACE::UInt JsonUInt; -typedef ARDUINOJSON_NAMESPACE::VariantConstRef JsonVariantConst; -typedef ARDUINOJSON_NAMESPACE::VariantRef JsonVariant; -using ARDUINOJSON_NAMESPACE::BasicJsonDocument; -using ARDUINOJSON_NAMESPACE::copyArray; -using ARDUINOJSON_NAMESPACE::DeserializationError; -using ARDUINOJSON_NAMESPACE::deserializeJson; -using ARDUINOJSON_NAMESPACE::deserializeMsgPack; -using ARDUINOJSON_NAMESPACE::DynamicJsonDocument; -using ARDUINOJSON_NAMESPACE::JsonDocument; -using ARDUINOJSON_NAMESPACE::measureJson; -using ARDUINOJSON_NAMESPACE::serialized; -using ARDUINOJSON_NAMESPACE::serializeJson; -using ARDUINOJSON_NAMESPACE::serializeJsonPretty; -using ARDUINOJSON_NAMESPACE::serializeMsgPack; -using ARDUINOJSON_NAMESPACE::StaticJsonDocument; - -namespace DeserializationOption { -using ARDUINOJSON_NAMESPACE::Filter; -using ARDUINOJSON_NAMESPACE::NestingLimit; -} // namespace DeserializationOption -} // namespace ArduinoJson +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include "ArduinoJson/Configuration.hpp" + +#if !ARDUINOJSON_DEBUG +#ifdef __clang__ +#pragma clang system_header +#elif defined __GNUC__ +#pragma GCC system_header +#endif +#endif + +#include "ArduinoJson/Array/ArrayRef.hpp" +#include "ArduinoJson/Object/ObjectRef.hpp" +#include "ArduinoJson/Variant/VariantRef.hpp" + +#include "ArduinoJson/Document/DynamicJsonDocument.hpp" +#include "ArduinoJson/Document/StaticJsonDocument.hpp" + +#include "ArduinoJson/Array/ArrayImpl.hpp" +#include "ArduinoJson/Array/ElementProxy.hpp" +#include "ArduinoJson/Array/Utilities.hpp" +#include "ArduinoJson/Collection/CollectionImpl.hpp" +#include "ArduinoJson/Object/MemberProxy.hpp" +#include "ArduinoJson/Object/ObjectImpl.hpp" +#include "ArduinoJson/Variant/VariantAsImpl.hpp" +#include "ArduinoJson/Variant/VariantCompare.hpp" +#include "ArduinoJson/Variant/VariantImpl.hpp" + +#include "ArduinoJson/Json/JsonDeserializer.hpp" +#include "ArduinoJson/Json/JsonSerializer.hpp" +#include "ArduinoJson/Json/PrettyJsonSerializer.hpp" +#include "ArduinoJson/MsgPack/MsgPackDeserializer.hpp" +#include "ArduinoJson/MsgPack/MsgPackSerializer.hpp" + +#include "ArduinoJson/compatibility.hpp" + +namespace ArduinoJson { +typedef ARDUINOJSON_NAMESPACE::ArrayConstRef JsonArrayConst; +typedef ARDUINOJSON_NAMESPACE::ArrayRef JsonArray; +typedef ARDUINOJSON_NAMESPACE::Float JsonFloat; +typedef ARDUINOJSON_NAMESPACE::Integer JsonInteger; +typedef ARDUINOJSON_NAMESPACE::ObjectConstRef JsonObjectConst; +typedef ARDUINOJSON_NAMESPACE::ObjectRef JsonObject; +typedef ARDUINOJSON_NAMESPACE::Pair JsonPair; +typedef ARDUINOJSON_NAMESPACE::PairConst JsonPairConst; +typedef ARDUINOJSON_NAMESPACE::String JsonString; +typedef ARDUINOJSON_NAMESPACE::UInt JsonUInt; +typedef ARDUINOJSON_NAMESPACE::VariantConstRef JsonVariantConst; +typedef ARDUINOJSON_NAMESPACE::VariantRef JsonVariant; +using ARDUINOJSON_NAMESPACE::BasicJsonDocument; +using ARDUINOJSON_NAMESPACE::copyArray; +using ARDUINOJSON_NAMESPACE::DeserializationError; +using ARDUINOJSON_NAMESPACE::deserializeJson; +using ARDUINOJSON_NAMESPACE::deserializeMsgPack; +using ARDUINOJSON_NAMESPACE::DynamicJsonDocument; +using ARDUINOJSON_NAMESPACE::JsonDocument; +using ARDUINOJSON_NAMESPACE::measureJson; +using ARDUINOJSON_NAMESPACE::serialized; +using ARDUINOJSON_NAMESPACE::serializeJson; +using ARDUINOJSON_NAMESPACE::serializeJsonPretty; +using ARDUINOJSON_NAMESPACE::serializeMsgPack; +using ARDUINOJSON_NAMESPACE::StaticJsonDocument; + +namespace DeserializationOption { +using ARDUINOJSON_NAMESPACE::Filter; +using ARDUINOJSON_NAMESPACE::NestingLimit; +} // namespace DeserializationOption +} // namespace ArduinoJson diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayFunctions.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayFunctions.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayFunctions.hpp rename to lib/ArduinoJson/src/ArduinoJson/Array/ArrayFunctions.hpp index c8335d289..c52db0ea6 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayFunctions.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayFunctions.hpp @@ -1,30 +1,30 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { - -inline VariantData *arrayAdd(CollectionData *arr, MemoryPool *pool) { - return arr ? arr->addElement(pool) : 0; -} - -template -inline void arrayAccept(const CollectionData *arr, Visitor &visitor) { - if (arr) - visitor.visitArray(*arr); - else - visitor.visitNull(); -} - -inline bool arrayEquals(const CollectionData *lhs, const CollectionData *rhs) { - if (lhs == rhs) - return true; - if (!lhs || !rhs) - return false; - return lhs->equalsArray(*rhs); -} -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +inline VariantData *arrayAdd(CollectionData *arr, MemoryPool *pool) { + return arr ? arr->addElement(pool) : 0; +} + +template +inline void arrayAccept(const CollectionData *arr, Visitor &visitor) { + if (arr) + visitor.visitArray(*arr); + else + visitor.visitNull(); +} + +inline bool arrayEquals(const CollectionData *lhs, const CollectionData *rhs) { + if (lhs == rhs) + return true; + if (!lhs || !rhs) + return false; + return lhs->equalsArray(*rhs); +} +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp rename to lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp index 21fe43bca..4c57ad8f2 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayImpl.hpp @@ -1,28 +1,28 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include - -namespace ARDUINOJSON_NAMESPACE { - -template -inline ArrayRef ArrayShortcuts::createNestedArray() const { - return impl()->addElement().template to(); -} - -template -inline ObjectRef ArrayShortcuts::createNestedObject() const { - return impl()->addElement().template to(); -} - -template -inline ElementProxy ArrayShortcuts::operator[]( - size_t index) const { - return ElementProxy(*impl(), index); -} - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +inline ArrayRef ArrayShortcuts::createNestedArray() const { + return impl()->addElement().template to(); +} + +template +inline ObjectRef ArrayShortcuts::createNestedObject() const { + return impl()->addElement().template to(); +} + +template +inline ElementProxy ArrayShortcuts::operator[]( + size_t index) const { + return ElementProxy(*impl(), index); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp rename to lib/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp index cb158d2b0..bacaaab3f 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayIterator.hpp @@ -1,121 +1,121 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include - -namespace ARDUINOJSON_NAMESPACE { - -class VariantPtr { - public: - VariantPtr(MemoryPool *pool, VariantData *data) : _variant(pool, data) {} - - VariantRef *operator->() { - return &_variant; - } - - VariantRef &operator*() { - return _variant; - } - - private: - VariantRef _variant; -}; - -class ArrayIterator { - public: - ArrayIterator() : _slot(0) {} - explicit ArrayIterator(MemoryPool *pool, VariantSlot *slot) - : _pool(pool), _slot(slot) {} - - VariantRef operator*() const { - return VariantRef(_pool, _slot->data()); - } - VariantPtr operator->() { - return VariantPtr(_pool, _slot->data()); - } - - bool operator==(const ArrayIterator &other) const { - return _slot == other._slot; - } - - bool operator!=(const ArrayIterator &other) const { - return _slot != other._slot; - } - - ArrayIterator &operator++() { - _slot = _slot->next(); - return *this; - } - - ArrayIterator &operator+=(size_t distance) { - _slot = _slot->next(distance); - return *this; - } - - VariantSlot *internal() { - return _slot; - } - - private: - MemoryPool *_pool; - VariantSlot *_slot; -}; - -class VariantConstPtr { - public: - VariantConstPtr(const VariantData *data) : _variant(data) {} - - VariantConstRef *operator->() { - return &_variant; - } - - VariantConstRef &operator*() { - return _variant; - } - - private: - VariantConstRef _variant; -}; - -class ArrayConstRefIterator { - public: - ArrayConstRefIterator() : _slot(0) {} - explicit ArrayConstRefIterator(const VariantSlot *slot) : _slot(slot) {} - - VariantConstRef operator*() const { - return VariantConstRef(_slot->data()); - } - VariantConstPtr operator->() { - return VariantConstPtr(_slot->data()); - } - - bool operator==(const ArrayConstRefIterator &other) const { - return _slot == other._slot; - } - - bool operator!=(const ArrayConstRefIterator &other) const { - return _slot != other._slot; - } - - ArrayConstRefIterator &operator++() { - _slot = _slot->next(); - return *this; - } - - ArrayConstRefIterator &operator+=(size_t distance) { - _slot = _slot->next(distance); - return *this; - } - - const VariantSlot *internal() { - return _slot; - } - - private: - const VariantSlot *_slot; -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +class VariantPtr { + public: + VariantPtr(MemoryPool *pool, VariantData *data) : _variant(pool, data) {} + + VariantRef *operator->() { + return &_variant; + } + + VariantRef &operator*() { + return _variant; + } + + private: + VariantRef _variant; +}; + +class ArrayIterator { + public: + ArrayIterator() : _slot(0) {} + explicit ArrayIterator(MemoryPool *pool, VariantSlot *slot) + : _pool(pool), _slot(slot) {} + + VariantRef operator*() const { + return VariantRef(_pool, _slot->data()); + } + VariantPtr operator->() { + return VariantPtr(_pool, _slot->data()); + } + + bool operator==(const ArrayIterator &other) const { + return _slot == other._slot; + } + + bool operator!=(const ArrayIterator &other) const { + return _slot != other._slot; + } + + ArrayIterator &operator++() { + _slot = _slot->next(); + return *this; + } + + ArrayIterator &operator+=(size_t distance) { + _slot = _slot->next(distance); + return *this; + } + + VariantSlot *internal() { + return _slot; + } + + private: + MemoryPool *_pool; + VariantSlot *_slot; +}; + +class VariantConstPtr { + public: + VariantConstPtr(const VariantData *data) : _variant(data) {} + + VariantConstRef *operator->() { + return &_variant; + } + + VariantConstRef &operator*() { + return _variant; + } + + private: + VariantConstRef _variant; +}; + +class ArrayConstRefIterator { + public: + ArrayConstRefIterator() : _slot(0) {} + explicit ArrayConstRefIterator(const VariantSlot *slot) : _slot(slot) {} + + VariantConstRef operator*() const { + return VariantConstRef(_slot->data()); + } + VariantConstPtr operator->() { + return VariantConstPtr(_slot->data()); + } + + bool operator==(const ArrayConstRefIterator &other) const { + return _slot == other._slot; + } + + bool operator!=(const ArrayConstRefIterator &other) const { + return _slot != other._slot; + } + + ArrayConstRefIterator &operator++() { + _slot = _slot->next(); + return *this; + } + + ArrayConstRefIterator &operator+=(size_t distance) { + _slot = _slot->next(distance); + return *this; + } + + const VariantSlot *internal() { + return _slot; + } + + private: + const VariantSlot *_slot; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp rename to lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp index bb2fbaa7c..abbee8df6 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayRef.hpp @@ -1,167 +1,167 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include -#include - -// Returns the size (in bytes) of an array with n elements. -// Can be very handy to determine the size of a StaticMemoryPool. -#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ - ((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::VariantSlot)) - -namespace ARDUINOJSON_NAMESPACE { - -class ObjectRef; -template -class ElementProxy; - -template -class ArrayRefBase { - public: - operator VariantConstRef() const { - const void* data = _data; // prevent warning cast-align - return VariantConstRef(reinterpret_cast(data)); - } - - template - FORCE_INLINE void accept(Visitor& visitor) const { - arrayAccept(_data, visitor); - } - - FORCE_INLINE bool isNull() const { - return _data == 0; - } - - FORCE_INLINE operator bool() const { - return _data != 0; - } - - FORCE_INLINE size_t memoryUsage() const { - return _data ? _data->memoryUsage() : 0; - } - - FORCE_INLINE size_t nesting() const { - return _data ? _data->nesting() : 0; - } - - FORCE_INLINE size_t size() const { - return _data ? _data->size() : 0; - } - - protected: - ArrayRefBase(TData* data) : _data(data) {} - TData* _data; -}; - -class ArrayConstRef : public ArrayRefBase, - public Visitable { - friend class ArrayRef; - typedef ArrayRefBase base_type; - - public: - typedef ArrayConstRefIterator iterator; - - FORCE_INLINE iterator begin() const { - if (!_data) - return iterator(); - return iterator(_data->head()); - } - - FORCE_INLINE iterator end() const { - return iterator(); - } - - FORCE_INLINE ArrayConstRef() : base_type(0) {} - FORCE_INLINE ArrayConstRef(const CollectionData* data) : base_type(data) {} - - FORCE_INLINE bool operator==(ArrayConstRef rhs) const { - return arrayEquals(_data, rhs._data); - } - - FORCE_INLINE VariantConstRef operator[](size_t index) const { - return getElement(index); - } - - FORCE_INLINE VariantConstRef getElement(size_t index) const { - return VariantConstRef(_data ? _data->getElement(index) : 0); - } -}; - -class ArrayRef : public ArrayRefBase, - public ArrayShortcuts, - public Visitable { - typedef ArrayRefBase base_type; - - public: - typedef ArrayIterator iterator; - - FORCE_INLINE ArrayRef() : base_type(0), _pool(0) {} - FORCE_INLINE ArrayRef(MemoryPool* pool, CollectionData* data) - : base_type(data), _pool(pool) {} - - operator VariantRef() { - void* data = _data; // prevent warning cast-align - return VariantRef(_pool, reinterpret_cast(data)); - } - - operator ArrayConstRef() const { - return ArrayConstRef(_data); - } - - VariantRef addElement() const { - return VariantRef(_pool, arrayAdd(_data, _pool)); - } - - FORCE_INLINE iterator begin() const { - if (!_data) - return iterator(); - return iterator(_pool, _data->head()); - } - - FORCE_INLINE iterator end() const { - return iterator(); - } - - // Copy a ArrayRef - FORCE_INLINE bool set(ArrayConstRef src) const { - if (!_data || !src._data) - return false; - return _data->copyFrom(*src._data, _pool); - } - - FORCE_INLINE bool operator==(ArrayRef rhs) const { - return arrayEquals(_data, rhs._data); - } - - // Internal use - FORCE_INLINE VariantRef getOrAddElement(size_t index) const { - return VariantRef(_pool, _data ? _data->getOrAddElement(index, _pool) : 0); - } - - // Gets the value at the specified index. - FORCE_INLINE VariantRef getElement(size_t index) const { - return VariantRef(_pool, _data ? _data->getElement(index) : 0); - } - - // Removes element at specified position. - FORCE_INLINE void remove(iterator it) const { - if (!_data) - return; - _data->removeSlot(it.internal()); - } - - // Removes element at specified index. - FORCE_INLINE void remove(size_t index) const { - if (!_data) - return; - _data->removeElement(index); - } - - private: - MemoryPool* _pool; -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include +#include + +// Returns the size (in bytes) of an array with n elements. +// Can be very handy to determine the size of a StaticMemoryPool. +#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ + ((NUMBER_OF_ELEMENTS) * sizeof(ARDUINOJSON_NAMESPACE::VariantSlot)) + +namespace ARDUINOJSON_NAMESPACE { + +class ObjectRef; +template +class ElementProxy; + +template +class ArrayRefBase { + public: + operator VariantConstRef() const { + const void* data = _data; // prevent warning cast-align + return VariantConstRef(reinterpret_cast(data)); + } + + template + FORCE_INLINE void accept(Visitor& visitor) const { + arrayAccept(_data, visitor); + } + + FORCE_INLINE bool isNull() const { + return _data == 0; + } + + FORCE_INLINE operator bool() const { + return _data != 0; + } + + FORCE_INLINE size_t memoryUsage() const { + return _data ? _data->memoryUsage() : 0; + } + + FORCE_INLINE size_t nesting() const { + return _data ? _data->nesting() : 0; + } + + FORCE_INLINE size_t size() const { + return _data ? _data->size() : 0; + } + + protected: + ArrayRefBase(TData* data) : _data(data) {} + TData* _data; +}; + +class ArrayConstRef : public ArrayRefBase, + public Visitable { + friend class ArrayRef; + typedef ArrayRefBase base_type; + + public: + typedef ArrayConstRefIterator iterator; + + FORCE_INLINE iterator begin() const { + if (!_data) + return iterator(); + return iterator(_data->head()); + } + + FORCE_INLINE iterator end() const { + return iterator(); + } + + FORCE_INLINE ArrayConstRef() : base_type(0) {} + FORCE_INLINE ArrayConstRef(const CollectionData* data) : base_type(data) {} + + FORCE_INLINE bool operator==(ArrayConstRef rhs) const { + return arrayEquals(_data, rhs._data); + } + + FORCE_INLINE VariantConstRef operator[](size_t index) const { + return getElement(index); + } + + FORCE_INLINE VariantConstRef getElement(size_t index) const { + return VariantConstRef(_data ? _data->getElement(index) : 0); + } +}; + +class ArrayRef : public ArrayRefBase, + public ArrayShortcuts, + public Visitable { + typedef ArrayRefBase base_type; + + public: + typedef ArrayIterator iterator; + + FORCE_INLINE ArrayRef() : base_type(0), _pool(0) {} + FORCE_INLINE ArrayRef(MemoryPool* pool, CollectionData* data) + : base_type(data), _pool(pool) {} + + operator VariantRef() { + void* data = _data; // prevent warning cast-align + return VariantRef(_pool, reinterpret_cast(data)); + } + + operator ArrayConstRef() const { + return ArrayConstRef(_data); + } + + VariantRef addElement() const { + return VariantRef(_pool, arrayAdd(_data, _pool)); + } + + FORCE_INLINE iterator begin() const { + if (!_data) + return iterator(); + return iterator(_pool, _data->head()); + } + + FORCE_INLINE iterator end() const { + return iterator(); + } + + // Copy a ArrayRef + FORCE_INLINE bool set(ArrayConstRef src) const { + if (!_data || !src._data) + return false; + return _data->copyFrom(*src._data, _pool); + } + + FORCE_INLINE bool operator==(ArrayRef rhs) const { + return arrayEquals(_data, rhs._data); + } + + // Internal use + FORCE_INLINE VariantRef getOrAddElement(size_t index) const { + return VariantRef(_pool, _data ? _data->getOrAddElement(index, _pool) : 0); + } + + // Gets the value at the specified index. + FORCE_INLINE VariantRef getElement(size_t index) const { + return VariantRef(_pool, _data ? _data->getElement(index) : 0); + } + + // Removes element at specified position. + FORCE_INLINE void remove(iterator it) const { + if (!_data) + return; + _data->removeSlot(it.internal()); + } + + // Removes element at specified index. + FORCE_INLINE void remove(size_t index) const { + if (!_data) + return; + _data->removeElement(index); + } + + private: + MemoryPool* _pool; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayShortcuts.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayShortcuts.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayShortcuts.hpp rename to lib/ArduinoJson/src/ArduinoJson/Array/ArrayShortcuts.hpp index 6f1021cd2..564197421 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ArrayShortcuts.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ArrayShortcuts.hpp @@ -1,47 +1,47 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include - -namespace ARDUINOJSON_NAMESPACE { -// Forward declarations. -template -class ElementProxy; - -template -class ArrayShortcuts { - public: - // Returns the element at specified index if the variant is an array. - FORCE_INLINE ElementProxy operator[](size_t index) const; - - FORCE_INLINE ObjectRef createNestedObject() const; - - FORCE_INLINE ArrayRef createNestedArray() const; - - // Adds the specified value at the end of the array. - // - // bool add(TValue); - // TValue = bool, long, int, short, float, double, serialized, VariantRef, - // std::string, String, ObjectRef - template - FORCE_INLINE bool add(const T &value) const { - return impl()->addElement().set(value); - } - // - // bool add(TValue); - // TValue = char*, const char*, const __FlashStringHelper* - template - FORCE_INLINE bool add(T *value) const { - return impl()->addElement().set(value); - } - - private: - const TArray *impl() const { - return static_cast(this); - } -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { +// Forward declarations. +template +class ElementProxy; + +template +class ArrayShortcuts { + public: + // Returns the element at specified index if the variant is an array. + FORCE_INLINE ElementProxy operator[](size_t index) const; + + FORCE_INLINE ObjectRef createNestedObject() const; + + FORCE_INLINE ArrayRef createNestedArray() const; + + // Adds the specified value at the end of the array. + // + // bool add(TValue); + // TValue = bool, long, int, short, float, double, serialized, VariantRef, + // std::string, String, ObjectRef + template + FORCE_INLINE bool add(const T &value) const { + return impl()->addElement().set(value); + } + // + // bool add(TValue); + // TValue = char*, const char*, const __FlashStringHelper* + template + FORCE_INLINE bool add(T *value) const { + return impl()->addElement().set(value); + } + + private: + const TArray *impl() const { + return static_cast(this); + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp similarity index 88% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp rename to lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp index 9af0994bf..4de117f2b 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Array/ElementProxy.hpp @@ -1,175 +1,178 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include -#include - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) -#endif - -namespace ARDUINOJSON_NAMESPACE { - -template -class ElementProxy : public VariantOperators >, - public Visitable { - typedef ElementProxy this_type; - - public: - FORCE_INLINE ElementProxy(TArray array, size_t index) - : _array(array), _index(index) {} - - FORCE_INLINE ElementProxy(const ElementProxy& src) - : _array(src._array), _index(src._index) {} - - FORCE_INLINE this_type& operator=(const this_type& src) { - getOrAddUpstreamElement().set(src.as()); - return *this; - } - - // Replaces the value - // - // operator=(const TValue&) - // TValue = bool, long, int, short, float, double, serialized, VariantRef, - // std::string, String, ArrayRef, ObjectRef - template - FORCE_INLINE this_type& operator=(const T& src) { - getOrAddUpstreamElement().set(src); - return *this; - } - // - // operator=(TValue) - // TValue = char*, const char*, const __FlashStringHelper* - template - FORCE_INLINE this_type& operator=(T* src) { - getOrAddUpstreamElement().set(src); - return *this; - } - - FORCE_INLINE bool operator==(VariantConstRef rhs) const { - return static_cast(getUpstreamElement()) == rhs; - } - - FORCE_INLINE bool operator!=(VariantConstRef rhs) const { - return static_cast(getUpstreamElement()) != rhs; - } - - FORCE_INLINE void clear() const { - getUpstreamElement().clear(); - } - - FORCE_INLINE bool isNull() const { - return getUpstreamElement().isNull(); - } - - template - FORCE_INLINE typename VariantAs::type as() const { - return getUpstreamElement().template as(); - } - - template - FORCE_INLINE bool is() const { - return getUpstreamElement().template is(); - } - - template - FORCE_INLINE typename VariantTo::type to() const { - return getOrAddUpstreamElement().template to(); - } - - // Replaces the value - // - // bool set(const TValue&) - // TValue = bool, long, int, short, float, double, serialized, VariantRef, - // std::string, String, ArrayRef, ObjectRef - template - FORCE_INLINE bool set(const TValue& value) const { - return getOrAddUpstreamElement().set(value); - } - // - // bool set(TValue) - // TValue = char*, const char*, const __FlashStringHelper* - template - FORCE_INLINE bool set(TValue* value) const { - return getOrAddUpstreamElement().set(value); - } - - template - void accept(Visitor& visitor) const { - return getUpstreamElement().accept(visitor); - } - - FORCE_INLINE size_t size() const { - return getUpstreamElement().size(); - } - - template - VariantRef getMember(TNestedKey* key) const { - return getUpstreamElement().getMember(key); - } - - template - VariantRef getMember(const TNestedKey& key) const { - return getUpstreamElement().getMember(key); - } - - template - VariantRef getOrAddMember(TNestedKey* key) const { - return getOrAddUpstreamElement().getOrAddMember(key); - } - - template - VariantRef getOrAddMember(const TNestedKey& key) const { - return getOrAddUpstreamElement().getOrAddMember(key); - } - - VariantRef addElement() const { - return getOrAddUpstreamElement().addElement(); - } - - VariantRef getElement(size_t index) const { - return getOrAddUpstreamElement().getElement(index); - } - - FORCE_INLINE void remove(size_t index) const { - getUpstreamElement().remove(index); - } - // remove(char*) const - // remove(const char*) const - // remove(const __FlashStringHelper*) const - template - FORCE_INLINE typename enable_if::value>::type remove( - TChar* key) const { - getUpstreamElement().remove(key); - } - // remove(const std::string&) const - // remove(const String&) const - template - FORCE_INLINE typename enable_if::value>::type remove( - const TString& key) const { - getUpstreamElement().remove(key); - } - - private: - FORCE_INLINE VariantRef getUpstreamElement() const { - return _array.getElement(_index); - } - - FORCE_INLINE VariantRef getOrAddUpstreamElement() const { - return _array.getOrAddElement(_index); - } - - TArray _array; - const size_t _index; -}; - -} // namespace ARDUINOJSON_NAMESPACE - -#ifdef _MSC_VER -#pragma warning(pop) -#endif +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4522) +#endif + +namespace ARDUINOJSON_NAMESPACE { + +template +class ElementProxy : public VariantOperators >, + public VariantShortcuts >, + public Visitable { + typedef ElementProxy this_type; + + public: + FORCE_INLINE ElementProxy(TArray array, size_t index) + : _array(array), _index(index) {} + + FORCE_INLINE ElementProxy(const ElementProxy& src) + : _array(src._array), _index(src._index) {} + + FORCE_INLINE this_type& operator=(const this_type& src) { + getOrAddUpstreamElement().set(src.as()); + return *this; + } + + // Replaces the value + // + // operator=(const TValue&) + // TValue = bool, long, int, short, float, double, serialized, VariantRef, + // std::string, String, ArrayRef, ObjectRef + template + FORCE_INLINE this_type& operator=(const T& src) { + getOrAddUpstreamElement().set(src); + return *this; + } + // + // operator=(TValue) + // TValue = char*, const char*, const __FlashStringHelper* + template + FORCE_INLINE this_type& operator=(T* src) { + getOrAddUpstreamElement().set(src); + return *this; + } + + FORCE_INLINE void clear() const { + getUpstreamElement().clear(); + } + + FORCE_INLINE bool isNull() const { + return getUpstreamElement().isNull(); + } + + template + FORCE_INLINE typename VariantAs::type as() const { + return getUpstreamElement().template as(); + } + + template + FORCE_INLINE operator T() const { + return getUpstreamElement(); + } + + template + FORCE_INLINE bool is() const { + return getUpstreamElement().template is(); + } + + template + FORCE_INLINE typename VariantTo::type to() const { + return getOrAddUpstreamElement().template to(); + } + + // Replaces the value + // + // bool set(const TValue&) + // TValue = bool, long, int, short, float, double, serialized, VariantRef, + // std::string, String, ArrayRef, ObjectRef + template + FORCE_INLINE bool set(const TValue& value) const { + return getOrAddUpstreamElement().set(value); + } + // + // bool set(TValue) + // TValue = char*, const char*, const __FlashStringHelper* + template + FORCE_INLINE bool set(TValue* value) const { + return getOrAddUpstreamElement().set(value); + } + + template + void accept(Visitor& visitor) const { + return getUpstreamElement().accept(visitor); + } + + FORCE_INLINE size_t size() const { + return getUpstreamElement().size(); + } + + template + VariantRef getMember(TNestedKey* key) const { + return getUpstreamElement().getMember(key); + } + + template + VariantRef getMember(const TNestedKey& key) const { + return getUpstreamElement().getMember(key); + } + + template + VariantRef getOrAddMember(TNestedKey* key) const { + return getOrAddUpstreamElement().getOrAddMember(key); + } + + template + VariantRef getOrAddMember(const TNestedKey& key) const { + return getOrAddUpstreamElement().getOrAddMember(key); + } + + VariantRef addElement() const { + return getOrAddUpstreamElement().addElement(); + } + + VariantRef getElement(size_t index) const { + return getOrAddUpstreamElement().getElement(index); + } + + VariantRef getOrAddElement(size_t index) const { + return getOrAddUpstreamElement().getOrAddElement(index); + } + + FORCE_INLINE void remove(size_t index) const { + getUpstreamElement().remove(index); + } + // remove(char*) const + // remove(const char*) const + // remove(const __FlashStringHelper*) const + template + FORCE_INLINE typename enable_if::value>::type remove( + TChar* key) const { + getUpstreamElement().remove(key); + } + // remove(const std::string&) const + // remove(const String&) const + template + FORCE_INLINE typename enable_if::value>::type remove( + const TString& key) const { + getUpstreamElement().remove(key); + } + + private: + FORCE_INLINE VariantRef getUpstreamElement() const { + return _array.getElement(_index); + } + + FORCE_INLINE VariantRef getOrAddUpstreamElement() const { + return _array.getOrAddElement(_index); + } + + TArray _array; + const size_t _index; +}; + +} // namespace ARDUINOJSON_NAMESPACE + +#ifdef _MSC_VER +#pragma warning(pop) +#endif diff --git a/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp new file mode 100644 index 000000000..07ebf9b55 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Array/Utilities.hpp @@ -0,0 +1,150 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +// Copy a 1D array to a JsonArray +template +inline typename enable_if::value && + !is_base_of::value, + bool>::type +copyArray(T (&src)[N], const TDestination& dst) { + return copyArray(src, N, dst); +} + +// Copy a 1D array to a JsonDocument +template +inline bool copyArray(T (&src)[N], JsonDocument& dst) { + return copyArray(src, dst.to()); +} + +// Copy a 1D array to a JsonArray +template +inline typename enable_if::value && + !is_base_of::value, + bool>::type +copyArray(T* src, size_t len, const TDestination& dst) { + bool ok = true; + for (size_t i = 0; i < len; i++) { + ok &= dst.add(src[i]); + } + return ok; +} + +// Copy a 1D array to a JsonDocument +template +inline bool copyArray(T* src, size_t len, JsonDocument& dst) { + return copyArray(src, len, dst.to()); +} + +// Copy a 2D array to a JsonArray +template +inline typename enable_if::value, + bool>::type +copyArray(T (&src)[N1][N2], const TDestination& dst) { + bool ok = true; + for (size_t i = 0; i < N1; i++) { + ArrayRef nestedArray = dst.createNestedArray(); + for (size_t j = 0; j < N2; j++) { + ok &= nestedArray.add(src[i][j]); + } + } + return ok; +} + +// Copy a 2D array to a JsonDocument +template +inline bool copyArray(T (&src)[N1][N2], JsonDocument& dst) { + return copyArray(src, dst.to()); +} + +template +class ArrayCopier1D { + public: + ArrayCopier1D(T* destination, size_t capacity) + : _destination(destination), _capacity(capacity), _size(0) {} + + void visitArray(const CollectionData& array) { + VariantSlot* slot = array.head(); + + while (slot != 0 && _size < _capacity) { + _destination[_size++] = variantAs(slot->data()); + slot = slot->next(); + } + } + void visitObject(const CollectionData&) {} + void visitFloat(Float) {} + void visitString(const char*) {} + void visitRawJson(const char*, size_t) {} + void visitNegativeInteger(UInt) {} + void visitPositiveInteger(UInt) {} + void visitBoolean(bool) {} + void visitNull() {} + + size_t result() const { + return _size; + } + + private: + T* _destination; + size_t _capacity; + size_t _size; +}; + +template +class ArrayCopier2D { + public: + ArrayCopier2D(T (*destination)[N1][N2]) : _destination(destination) {} + + void visitArray(const CollectionData& array) { + VariantSlot* slot = array.head(); + size_t n = 0; + while (slot != 0 && n < N1) { + ArrayCopier1D copier((*_destination)[n++], N2); + variantAccept(slot->data(), copier); + slot = slot->next(); + } + } + void visitObject(const CollectionData&) {} + void visitFloat(Float) {} + void visitString(const char*) {} + void visitRawJson(const char*, size_t) {} + void visitNegativeInteger(UInt) {} + void visitPositiveInteger(UInt) {} + void visitBoolean(bool) {} + void visitNull() {} + + private: + T (*_destination)[N1][N2]; + size_t _capacity1, _capacity2; +}; + +// Copy a JsonArray to a 1D array +template +inline typename enable_if::value, size_t>::type copyArray( + const TSource& src, T (&dst)[N]) { + return copyArray(src, dst, N); +} + +// Copy a JsonArray to a 1D array +template +inline size_t copyArray(const TSource& src, T* dst, size_t len) { + ArrayCopier1D copier(dst, len); + src.accept(copier); + return copier.result(); +} + +// Copy a JsonArray to a 2D array +template +inline void copyArray(const TSource& src, T (&dst)[N1][N2]) { + ArrayCopier2D copier(&dst); + src.accept(copier); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp rename to lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp index 13fb78b24..7cb0fd1fe 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionData.hpp @@ -1,88 +1,88 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include - -#include // size_t - -namespace ARDUINOJSON_NAMESPACE { - -class MemoryPool; -class VariantData; -class VariantSlot; - -class CollectionData { - VariantSlot *_head; - VariantSlot *_tail; - - public: - // Must be a POD! - // - no constructor - // - no destructor - // - no virtual - // - no inheritance - - // Array only - - VariantData *addElement(MemoryPool *pool); - - VariantData *getElement(size_t index) const; - - VariantData *getOrAddElement(size_t index, MemoryPool *pool); - - void removeElement(size_t index); - - bool equalsArray(const CollectionData &other) const; - - // 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)); - } - - template - bool containsKey(const TAdaptedString &key) const; - - bool equalsObject(const CollectionData &other) const; - - // Generic - - void clear(); - size_t memoryUsage() const; - size_t nesting() const; - size_t size() const; - - VariantSlot *addSlot(MemoryPool *); - void removeSlot(VariantSlot *slot); - - bool copyFrom(const CollectionData &src, MemoryPool *pool); - - VariantSlot *head() const { - return _head; - } - - void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance); - - private: - VariantSlot *getSlot(size_t index) const; - - template - VariantSlot *getSlot(TAdaptedString key) const; - - VariantSlot *getPreviousSlot(VariantSlot *) const; -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +#include // size_t + +namespace ARDUINOJSON_NAMESPACE { + +class MemoryPool; +class VariantData; +class VariantSlot; + +class CollectionData { + VariantSlot *_head; + VariantSlot *_tail; + + public: + // Must be a POD! + // - no constructor + // - no destructor + // - no virtual + // - no inheritance + + // Array only + + VariantData *addElement(MemoryPool *pool); + + VariantData *getElement(size_t index) const; + + VariantData *getOrAddElement(size_t index, MemoryPool *pool); + + void removeElement(size_t index); + + bool equalsArray(const CollectionData &other) const; + + // 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)); + } + + template + bool containsKey(const TAdaptedString &key) const; + + bool equalsObject(const CollectionData &other) const; + + // Generic + + void clear(); + size_t memoryUsage() const; + size_t nesting() const; + size_t size() const; + + VariantSlot *addSlot(MemoryPool *); + void removeSlot(VariantSlot *slot); + + bool copyFrom(const CollectionData &src, MemoryPool *pool); + + VariantSlot *head() const { + return _head; + } + + void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance); + + private: + VariantSlot *getSlot(size_t index) const; + + template + VariantSlot *getSlot(TAdaptedString key) const; + + VariantSlot *getPreviousSlot(VariantSlot *) const; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp similarity index 93% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp rename to lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp index 910a2a620..e81497b29 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Collection/CollectionImpl.hpp @@ -1,228 +1,232 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include - -namespace ARDUINOJSON_NAMESPACE { - -inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { - VariantSlot* slot = pool->allocVariant(); - if (!slot) - return 0; - - if (_tail) { - _tail->setNextNotNull(slot); - _tail = slot; - } else { - _head = slot; - _tail = slot; - } - - slot->clear(); - return 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; - } - return slot->data(); -} - -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) { - if (s->ownsKey()) - var = addMember(RamStringAdapter(s->key()), pool); - else - var = addMember(ConstRamStringAdapter(s->key()), pool); - } else { - var = addElement(pool); - } - if (!var) - return false; - if (!var->copyFrom(*s->data(), pool)) - return false; - } - return true; -} - -inline bool CollectionData::equalsObject(const CollectionData& other) const { - size_t count = 0; - for (VariantSlot* slot = _head; slot; slot = slot->next()) { - VariantData* v1 = slot->data(); - VariantData* v2 = other.getMember(adaptString(slot->key())); - if (!variantEquals(v1, v2)) - return false; - count++; - } - return count == other.size(); -} - -inline bool CollectionData::equalsArray(const CollectionData& other) const { - VariantSlot* s1 = _head; - VariantSlot* s2 = other._head; - for (;;) { - if (s1 == s2) - return true; - if (!s1 || !s2) - return false; - if (!variantEquals(s1->data(), s2->data())) - return false; - s1 = s1->next(); - s2 = s2->next(); - } -} - -template -inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { - VariantSlot* slot = _head; - while (slot) { - if (key.equals(slot->key())) - break; - slot = slot->next(); - } - return slot; -} - -inline VariantSlot* CollectionData::getSlot(size_t index) const { - 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) - return; - VariantSlot* prev = getPreviousSlot(slot); - VariantSlot* next = slot->next(); - if (prev) - prev->setNext(next); - else - _head = next; - if (!next) - _tail = prev; -} - -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; - } - return total; -} - -inline size_t CollectionData::nesting() const { - size_t maxChildNesting = 0; - for (VariantSlot* s = _head; s; s = s->next()) { - size_t childNesting = s->data()->nesting(); - if (childNesting > maxChildNesting) - maxChildNesting = childNesting; - } - return maxChildNesting + 1; -} - -inline size_t CollectionData::size() const { - return slotSize(_head); -} - -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); -} - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +inline bool variantEquals(const VariantData* a, const VariantData* b) { + return variantCompare(a, b) == COMPARE_RESULT_EQUAL; +} + +inline VariantSlot* CollectionData::addSlot(MemoryPool* pool) { + VariantSlot* slot = pool->allocVariant(); + if (!slot) + return 0; + + if (_tail) { + _tail->setNextNotNull(slot); + _tail = slot; + } else { + _head = slot; + _tail = slot; + } + + slot->clear(); + return 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; + } + return slot->data(); +} + +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) { + if (s->ownsKey()) + var = addMember(RamStringAdapter(s->key()), pool); + else + var = addMember(ConstRamStringAdapter(s->key()), pool); + } else { + var = addElement(pool); + } + if (!var) + return false; + if (!var->copyFrom(*s->data(), pool)) + return false; + } + return true; +} + +inline bool CollectionData::equalsObject(const CollectionData& other) const { + size_t count = 0; + for (VariantSlot* slot = _head; slot; slot = slot->next()) { + VariantData* v1 = slot->data(); + VariantData* v2 = other.getMember(adaptString(slot->key())); + if (!variantEquals(v1, v2)) + return false; + count++; + } + return count == other.size(); +} + +inline bool CollectionData::equalsArray(const CollectionData& other) const { + VariantSlot* s1 = _head; + VariantSlot* s2 = other._head; + for (;;) { + if (s1 == s2) + return true; + if (!s1 || !s2) + return false; + if (!variantEquals(s1->data(), s2->data())) + return false; + s1 = s1->next(); + s2 = s2->next(); + } +} + +template +inline VariantSlot* CollectionData::getSlot(TAdaptedString key) const { + VariantSlot* slot = _head; + while (slot) { + if (key.equals(slot->key())) + break; + slot = slot->next(); + } + return slot; +} + +inline VariantSlot* CollectionData::getSlot(size_t index) const { + 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) + return; + VariantSlot* prev = getPreviousSlot(slot); + VariantSlot* next = slot->next(); + if (prev) + prev->setNext(next); + else + _head = next; + if (!next) + _tail = prev; +} + +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; + } + return total; +} + +inline size_t CollectionData::nesting() const { + size_t maxChildNesting = 0; + for (VariantSlot* s = _head; s; s = s->next()) { + size_t childNesting = s->data()->nesting(); + if (childNesting > maxChildNesting) + maxChildNesting = childNesting; + } + return maxChildNesting + 1; +} + +inline size_t CollectionData::size() const { + return slotSize(_head); +} + +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); +} + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Configuration.hpp b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp similarity index 90% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Configuration.hpp rename to lib/ArduinoJson/src/ArduinoJson/Configuration.hpp index e6c01a2f1..24e7b17da 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Configuration.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Configuration.hpp @@ -1,220 +1,232 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#if defined(_MSC_VER) -#define ARDUINOJSON_HAS_INT64 1 -#else -#define ARDUINOJSON_HAS_INT64 0 -#endif - -#if __cplusplus >= 201103L -#define ARDUINOJSON_HAS_LONG_LONG 1 -#define ARDUINOJSON_HAS_NULLPTR 1 -#define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 -#else -#define ARDUINOJSON_HAS_LONG_LONG 0 -#define ARDUINOJSON_HAS_NULLPTR 0 -#define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 -#endif - -// Small or big machine? -#ifndef ARDUINOJSON_EMBEDDED_MODE -#if defined(ARDUINO) /* Arduino*/ \ - || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ - || defined(__XC) /* MPLAB XC compiler */ \ - || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ - || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ -#define ARDUINOJSON_EMBEDDED_MODE 1 -#else -#define ARDUINOJSON_EMBEDDED_MODE 0 -#endif -#endif - -// Auto enable std::stream if the right headers are here and no conflicting -// macro is defined -#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) -#if __has_include() && \ - __has_include() && \ - !defined(min) && \ - !defined(max) -#define ARDUINOJSON_ENABLE_STD_STREAM 1 -#else -#define ARDUINOJSON_ENABLE_STD_STREAM 0 -#endif -#endif - -// Auto enable std::string if the right header is here and no conflicting -// macro is defined -#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) -#if __has_include() && !defined(min) && !defined(max) -#define ARDUINOJSON_ENABLE_STD_STRING 1 -#else -#define ARDUINOJSON_ENABLE_STD_STRING 0 -#endif -#endif - -#if ARDUINOJSON_EMBEDDED_MODE - -// Store floats by default to reduce the memory usage (issue #134) -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 0 -#endif - -// Store longs by default, because they usually match the size of a float. -#ifndef ARDUINOJSON_USE_LONG_LONG -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif - -// Embedded systems usually don't have std::string -#ifndef ARDUINOJSON_ENABLE_STD_STRING -#define ARDUINOJSON_ENABLE_STD_STRING 0 -#endif - -// Embedded systems usually don't have std::stream -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 0 -#endif - -// Limit nesting as the stack is likely to be small -#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT -#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 -#endif - -#else // ARDUINOJSON_EMBEDDED_MODE - -// On a computer we have plenty of memory so we can use doubles -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 1 -#endif - -// Use long long when available -#ifndef ARDUINOJSON_USE_LONG_LONG -#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 -#define ARDUINOJSON_USE_LONG_LONG 1 -#else -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif -#endif - -// On a computer, we can use std::string -#ifndef ARDUINOJSON_ENABLE_STD_STRING -#define ARDUINOJSON_ENABLE_STD_STRING 1 -#endif - -// On a computer, we can assume std::stream -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 1 -#endif - -// On a computer, the stack is large so we can increase nesting limit -#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT -#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 -#endif - -#endif // ARDUINOJSON_EMBEDDED_MODE - -#ifdef ARDUINO - -#include - -// Enable support for Arduino's String class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 -#endif - -// Enable support for Arduino's Stream class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM -#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 -#endif - -// Enable support for Arduino's Print class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT -#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1 -#endif - -#else // ARDUINO - -// Disable support for Arduino's String class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 -#endif - -// Disable support for Arduino's Stream class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM -#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 -#endif - -// Disable support for Arduino's Print class -#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT -#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 -#endif - -#endif // ARDUINO - -#ifndef ARDUINOJSON_ENABLE_PROGMEM -#ifdef PROGMEM -#define ARDUINOJSON_ENABLE_PROGMEM 1 -#else -#define ARDUINOJSON_ENABLE_PROGMEM 0 -#endif -#endif - -// Convert unicode escape sequence (\u0123) to UTF-8 -#ifndef ARDUINOJSON_DECODE_UNICODE -#define ARDUINOJSON_DECODE_UNICODE 0 -#endif - -// Ignore comments in input -#ifndef ARDUINOJSON_ENABLE_COMMENTS -#define ARDUINOJSON_ENABLE_COMMENTS 0 -#endif - -// Support NaN in JSON -#ifndef ARDUINOJSON_ENABLE_NAN -#define ARDUINOJSON_ENABLE_NAN 0 -#endif - -// Support Infinity in JSON -#ifndef ARDUINOJSON_ENABLE_INFINITY -#define ARDUINOJSON_ENABLE_INFINITY 0 -#endif - -// Control the exponentiation threshold for big numbers -// CAUTION: cannot be more that 1e9 !!!! -#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD -#define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 -#endif - -// Control the exponentiation threshold for small numbers -#ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD -#define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 -#endif - -#ifndef ARDUINOJSON_LITTLE_ENDIAN -#if defined(_MSC_VER) || \ - (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ - defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64) -#define ARDUINOJSON_LITTLE_ENDIAN 1 -#else -#define ARDUINOJSON_LITTLE_ENDIAN 0 -#endif -#endif - -#ifndef ARDUINOJSON_TAB -#define ARDUINOJSON_TAB " " -#endif - -#ifndef ARDUINOJSON_STRING_BUFFER_SIZE -#define ARDUINOJSON_STRING_BUFFER_SIZE 32 -#endif - -#ifndef ARDUINOJSON_DEBUG -#ifdef __PLATFORMIO_BUILD_DEBUG__ -#define ARDUINOJSON_DEBUG 1 -#else -#define ARDUINOJSON_DEBUG 0 -#endif -#endif +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#if __cplusplus >= 201103L +#define ARDUINOJSON_HAS_LONG_LONG 1 +#define ARDUINOJSON_HAS_NULLPTR 1 +#define ARDUINOJSON_HAS_RVALUE_REFERENCES 1 +#else +#define ARDUINOJSON_HAS_LONG_LONG 0 +#define ARDUINOJSON_HAS_NULLPTR 0 +#define ARDUINOJSON_HAS_RVALUE_REFERENCES 0 +#endif + +#if defined(_MSC_VER) && !ARDUINOJSON_HAS_LONG_LONG +#define ARDUINOJSON_HAS_INT64 1 +#else +#define ARDUINOJSON_HAS_INT64 0 +#endif + +// Small or big machine? +#ifndef ARDUINOJSON_EMBEDDED_MODE +#if defined(ARDUINO) /* Arduino*/ \ + || defined(__IAR_SYSTEMS_ICC__) /* IAR Embedded Workbench */ \ + || defined(__XC) /* MPLAB XC compiler */ \ + || defined(__ARMCC_VERSION) /* Keil ARM Compiler */ \ + || defined(__AVR) /* Atmel AVR8/GNU C Compiler */ +#define ARDUINOJSON_EMBEDDED_MODE 1 +#else +#define ARDUINOJSON_EMBEDDED_MODE 0 +#endif +#endif + +// Auto enable std::stream if the right headers are here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) +#if __has_include() && \ + __has_include() && \ + !defined(min) && \ + !defined(max) +#define ARDUINOJSON_ENABLE_STD_STREAM 1 +#else +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#endif +#endif + +// Auto enable std::string if the right header is here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) +#if __has_include() && !defined(min) && !defined(max) +#define ARDUINOJSON_ENABLE_STD_STRING 1 +#else +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#endif +#endif + +#if ARDUINOJSON_EMBEDDED_MODE + +// Store floats by default to reduce the memory usage (issue #134) +#ifndef ARDUINOJSON_USE_DOUBLE +#define ARDUINOJSON_USE_DOUBLE 0 +#endif + +// Store longs by default, because they usually match the size of a float. +#ifndef ARDUINOJSON_USE_LONG_LONG +#define ARDUINOJSON_USE_LONG_LONG 0 +#endif + +// Embedded systems usually don't have std::string +#ifndef ARDUINOJSON_ENABLE_STD_STRING +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#endif + +// Embedded systems usually don't have std::stream +#ifndef ARDUINOJSON_ENABLE_STD_STREAM +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#endif + +// Limit nesting as the stack is likely to be small +#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10 +#endif + +#else // ARDUINOJSON_EMBEDDED_MODE + +// On a computer we have plenty of memory so we can use doubles +#ifndef ARDUINOJSON_USE_DOUBLE +#define ARDUINOJSON_USE_DOUBLE 1 +#endif + +// Use long long when available +#ifndef ARDUINOJSON_USE_LONG_LONG +#if ARDUINOJSON_HAS_LONG_LONG || ARDUINOJSON_HAS_INT64 +#define ARDUINOJSON_USE_LONG_LONG 1 +#else +#define ARDUINOJSON_USE_LONG_LONG 0 +#endif +#endif + +// On a computer, we can use std::string +#ifndef ARDUINOJSON_ENABLE_STD_STRING +#define ARDUINOJSON_ENABLE_STD_STRING 1 +#endif + +// On a computer, we can assume std::stream +#ifndef ARDUINOJSON_ENABLE_STD_STREAM +#define ARDUINOJSON_ENABLE_STD_STREAM 1 +#endif + +// On a computer, the stack is large so we can increase nesting limit +#ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT +#define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50 +#endif + +#endif // ARDUINOJSON_EMBEDDED_MODE + +#ifdef ARDUINO + +#include + +// Enable support for Arduino's String class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#endif + +// Enable support for Arduino's Stream class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM +#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1 +#endif + +// Enable support for Arduino's Print class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT +#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 1 +#endif + +#else // ARDUINO + +// Disable support for Arduino's String class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING +#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0 +#endif + +// Disable support for Arduino's Stream class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM +#define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0 +#endif + +// Disable support for Arduino's Print class +#ifndef ARDUINOJSON_ENABLE_ARDUINO_PRINT +#define ARDUINOJSON_ENABLE_ARDUINO_PRINT 0 +#endif + +#endif // ARDUINO + +#ifndef ARDUINOJSON_ENABLE_PROGMEM +#ifdef PROGMEM +#define ARDUINOJSON_ENABLE_PROGMEM 1 +#else +#define ARDUINOJSON_ENABLE_PROGMEM 0 +#endif +#endif + +// Convert unicode escape sequence (\u0123) to UTF-8 +#ifndef ARDUINOJSON_DECODE_UNICODE +#define ARDUINOJSON_DECODE_UNICODE 1 +#endif + +// Ignore comments in input +#ifndef ARDUINOJSON_ENABLE_COMMENTS +#define ARDUINOJSON_ENABLE_COMMENTS 0 +#endif + +// Support NaN in JSON +#ifndef ARDUINOJSON_ENABLE_NAN +#define ARDUINOJSON_ENABLE_NAN 0 +#endif + +// Support Infinity in JSON +#ifndef ARDUINOJSON_ENABLE_INFINITY +#define ARDUINOJSON_ENABLE_INFINITY 0 +#endif + +// Control the exponentiation threshold for big numbers +// CAUTION: cannot be more that 1e9 !!!! +#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD +#define ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD 1e7 +#endif + +// Control the exponentiation threshold for small numbers +#ifndef ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD +#define ARDUINOJSON_NEGATIVE_EXPONENTIATION_THRESHOLD 1e-5 +#endif + +#ifndef ARDUINOJSON_LITTLE_ENDIAN +#if defined(_MSC_VER) || \ + (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \ + defined(__LITTLE_ENDIAN__) || defined(__i386) || defined(__x86_64) +#define ARDUINOJSON_LITTLE_ENDIAN 1 +#else +#define ARDUINOJSON_LITTLE_ENDIAN 0 +#endif +#endif + +#ifndef ARDUINOJSON_ENABLE_ALIGNMENT +#if defined(__AVR) +#define ARDUINOJSON_ENABLE_ALIGNMENT 0 +#else +#define ARDUINOJSON_ENABLE_ALIGNMENT 1 +#endif +#endif + +#ifndef ARDUINOJSON_TAB +#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 + +#ifndef ARDUINOJSON_DEBUG +#ifdef __PLATFORMIO_BUILD_DEBUG__ +#define ARDUINOJSON_DEBUG 1 +#else +#define ARDUINOJSON_DEBUG 0 +#endif +#endif diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp index 9ffd0de94..4efc57dfc 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/DeserializationError.hpp @@ -1,115 +1,115 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -#if ARDUINOJSON_ENABLE_STD_STREAM -#include -#endif - -namespace ARDUINOJSON_NAMESPACE { - -class DeserializationError { - // safe bool idiom - typedef void (DeserializationError::*bool_type)() const; - void safeBoolHelper() const {} - - public: - enum Code { - Ok, - IncompleteInput, - InvalidInput, - NoMemory, - NotSupported, - TooDeep - }; - - DeserializationError() {} - DeserializationError(Code c) : _code(c) {} - - // Compare with DeserializationError - friend bool operator==(const DeserializationError& lhs, - const DeserializationError& rhs) { - return lhs._code == rhs._code; - } - friend bool operator!=(const DeserializationError& lhs, - const DeserializationError& rhs) { - return lhs._code != rhs._code; - } - - // Compare with Code - friend bool operator==(const DeserializationError& lhs, Code rhs) { - return lhs._code == rhs; - } - friend bool operator==(Code lhs, const DeserializationError& rhs) { - return lhs == rhs._code; - } - friend bool operator!=(const DeserializationError& lhs, Code rhs) { - return lhs._code != rhs; - } - friend bool operator!=(Code lhs, const DeserializationError& rhs) { - return lhs != rhs._code; - } - - // Behaves like a bool - operator bool_type() const { - return _code != Ok ? &DeserializationError::safeBoolHelper : 0; - } - friend bool operator==(bool value, const DeserializationError& err) { - return static_cast(err) == value; - } - friend bool operator==(const DeserializationError& err, bool value) { - return static_cast(err) == value; - } - friend bool operator!=(bool value, const DeserializationError& err) { - return static_cast(err) != value; - } - friend bool operator!=(const DeserializationError& err, bool value) { - return static_cast(err) != value; - } - - // Returns internal enum, useful for switch statement - Code code() const { - return _code; - } - - const char* c_str() const { - switch (_code) { - case Ok: - return "Ok"; - case TooDeep: - return "TooDeep"; - case NoMemory: - return "NoMemory"; - case InvalidInput: - return "InvalidInput"; - case IncompleteInput: - return "IncompleteInput"; - case NotSupported: - return "NotSupported"; - default: - return "???"; - } - } - - private: - Code _code; -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream& operator<<(std::ostream& s, - const DeserializationError& e) { - s << e.c_str(); - return s; -} - -inline std::ostream& operator<<(std::ostream& s, DeserializationError::Code c) { - s << DeserializationError(c).c_str(); - return s; -} -#endif - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +#if ARDUINOJSON_ENABLE_STD_STREAM +#include +#endif + +namespace ARDUINOJSON_NAMESPACE { + +class DeserializationError { + // safe bool idiom + typedef void (DeserializationError::*bool_type)() const; + void safeBoolHelper() const {} + + public: + enum Code { + Ok, + IncompleteInput, + InvalidInput, + NoMemory, + NotSupported, + TooDeep + }; + + DeserializationError() {} + DeserializationError(Code c) : _code(c) {} + + // Compare with DeserializationError + friend bool operator==(const DeserializationError& lhs, + const DeserializationError& rhs) { + return lhs._code == rhs._code; + } + friend bool operator!=(const DeserializationError& lhs, + const DeserializationError& rhs) { + return lhs._code != rhs._code; + } + + // Compare with Code + friend bool operator==(const DeserializationError& lhs, Code rhs) { + return lhs._code == rhs; + } + friend bool operator==(Code lhs, const DeserializationError& rhs) { + return lhs == rhs._code; + } + friend bool operator!=(const DeserializationError& lhs, Code rhs) { + return lhs._code != rhs; + } + friend bool operator!=(Code lhs, const DeserializationError& rhs) { + return lhs != rhs._code; + } + + // Behaves like a bool + operator bool_type() const { + return _code != Ok ? &DeserializationError::safeBoolHelper : 0; + } + friend bool operator==(bool value, const DeserializationError& err) { + return static_cast(err) == value; + } + friend bool operator==(const DeserializationError& err, bool value) { + return static_cast(err) == value; + } + friend bool operator!=(bool value, const DeserializationError& err) { + return static_cast(err) != value; + } + friend bool operator!=(const DeserializationError& err, bool value) { + return static_cast(err) != value; + } + + // Returns internal enum, useful for switch statement + Code code() const { + return _code; + } + + const char* c_str() const { + switch (_code) { + case Ok: + return "Ok"; + case TooDeep: + return "TooDeep"; + case NoMemory: + return "NoMemory"; + case InvalidInput: + return "InvalidInput"; + case IncompleteInput: + return "IncompleteInput"; + case NotSupported: + return "NotSupported"; + default: + return "???"; + } + } + + private: + Code _code; +}; + +#if ARDUINOJSON_ENABLE_STD_STREAM +inline std::ostream& operator<<(std::ostream& s, + const DeserializationError& e) { + s << e.c_str(); + return s; +} + +inline std::ostream& operator<<(std::ostream& s, DeserializationError::Code c) { + s << DeserializationError(c).c_str(); + return s; +} +#endif + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp similarity index 94% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp index 252488799..fb41a9d03 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Filter.hpp @@ -1,66 +1,66 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { - -class Filter { - public: - explicit Filter(VariantConstRef v) : _variant(v) {} - - bool allow() const { - return _variant; - } - - bool allowArray() const { - return _variant == true || _variant.is(); - } - - bool allowObject() const { - return _variant == true || _variant.is(); - } - - bool allowValue() const { - return _variant == true; - } - - template - Filter operator[](const TKey& key) const { - if (_variant == true) // "true" means "allow recursively" - return *this; - else - return Filter(_variant[key]); - } - - private: - VariantConstRef _variant; -}; - -struct AllowAllFilter { - bool allow() const { - return true; - } - - bool allowArray() const { - return true; - } - - bool allowObject() const { - return true; - } - - bool allowValue() const { - return true; - } - - template - AllowAllFilter operator[](const TKey&) const { - return AllowAllFilter(); - } -}; - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +class Filter { + public: + explicit Filter(VariantConstRef v) : _variant(v) {} + + bool allow() const { + return _variant; + } + + bool allowArray() const { + return _variant == true || _variant.is(); + } + + bool allowObject() const { + return _variant == true || _variant.is(); + } + + bool allowValue() const { + return _variant == true; + } + + template + Filter operator[](const TKey& key) const { + if (_variant == true) // "true" means "allow recursively" + return *this; + else + return Filter(_variant[key]); + } + + private: + VariantConstRef _variant; +}; + +struct AllowAllFilter { + bool allow() const { + return true; + } + + bool allowArray() const { + return true; + } + + bool allowObject() const { + return true; + } + + bool allowValue() const { + return true; + } + + template + AllowAllFilter operator[](const TKey&) const { + return AllowAllFilter(); + } +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp index 8f33b6c7d..47e36d0fd 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/NestingLimit.hpp @@ -1,29 +1,29 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include - -namespace ARDUINOJSON_NAMESPACE { - -class NestingLimit { - public: - NestingLimit() : _value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} - explicit NestingLimit(uint8_t n) : _value(n) {} - - NestingLimit decrement() const { - ARDUINOJSON_ASSERT(_value > 0); - return NestingLimit(static_cast(_value - 1)); - } - - bool reached() const { - return _value == 0; - } - - private: - uint8_t _value; -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +class NestingLimit { + public: + NestingLimit() : _value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} + explicit NestingLimit(uint8_t n) : _value(n) {} + + NestingLimit decrement() const { + ARDUINOJSON_ASSERT(_value > 0); + return NestingLimit(static_cast(_value - 1)); + } + + bool reached() const { + return _value == 0; + } + + private: + uint8_t _value; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp similarity index 91% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp index 9473f69e1..a71134ab9 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Reader.hpp @@ -1,55 +1,56 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -#include // for size_t - -namespace ARDUINOJSON_NAMESPACE { - -// The default reader is a simple wrapper for Readers that are not copiable -template -struct Reader { - public: - Reader(TSource& source) : _source(&source) {} - - int read() { - return _source->read(); - } - - size_t readBytes(char* buffer, size_t length) { - return _source->readBytes(buffer, length); - } - - private: - TSource* _source; -}; - -template -struct BoundedReader { - // no default implementation because we need to pass the size to the - // constructor -}; -} // namespace ARDUINOJSON_NAMESPACE - -#include -#include - -#if ARDUINOJSON_ENABLE_ARDUINO_STREAM -#include -#endif - -#if ARDUINOJSON_ENABLE_ARDUINO_STRING -#include -#endif - -#if ARDUINOJSON_ENABLE_PROGMEM -#include -#endif - -#if ARDUINOJSON_ENABLE_STD_STREAM -#include -#endif +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +#include // for size_t + +namespace ARDUINOJSON_NAMESPACE { + +// The default reader is a simple wrapper for Readers that are not copiable +template +struct Reader { + public: + Reader(TSource& source) : _source(&source) {} + + int read() { + return _source->read(); + } + + size_t readBytes(char* buffer, size_t length) { + return _source->readBytes(buffer, length); + } + + private: + TSource* _source; +}; + +template +struct BoundedReader { + // no default implementation because we need to pass the size to the + // constructor +}; +} // namespace ARDUINOJSON_NAMESPACE + +#include +#include +#include + +#if ARDUINOJSON_ENABLE_ARDUINO_STREAM +#include +#endif + +#if ARDUINOJSON_ENABLE_ARDUINO_STRING +#include +#endif + +#if ARDUINOJSON_ENABLE_PROGMEM +#include +#endif + +#if ARDUINOJSON_ENABLE_STD_STREAM +#include +#endif diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp index 06352585c..a50485d03 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStreamReader.hpp @@ -1,31 +1,31 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { - -template -struct Reader::value>::type> { - public: - explicit Reader(Stream& stream) : _stream(&stream) {} - - int read() { - // don't use _stream.read() as it ignores the timeout - char c; - return _stream->readBytes(&c, 1) ? static_cast(c) : -1; - } - - size_t readBytes(char* buffer, size_t length) { - return _stream->readBytes(buffer, length); - } - - private: - Stream* _stream; -}; - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> { + public: + explicit Reader(Stream& stream) : _stream(&stream) {} + + int read() { + // don't use _stream.read() as it ignores the timeout + char c; + return _stream->readBytes(&c, 1) ? static_cast(c) : -1; + } + + size_t readBytes(char* buffer, size_t length) { + return _stream->readBytes(buffer, length); + } + + private: + Stream* _stream; +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp index 5b6bcd2eb..71cbc56b1 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/ArduinoStringReader.hpp @@ -1,17 +1,17 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -namespace ARDUINOJSON_NAMESPACE { - -template -struct Reader::value>::type> - : BoundedReader { - explicit Reader(const ::String& s) - : BoundedReader(s.c_str(), s.length()) {} -}; - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> + : BoundedReader { + explicit Reader(const ::String& s) + : BoundedReader(s.c_str(), s.length()) {} +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp index 36b7fde6d..3c8ad2745 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -1,53 +1,53 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -namespace ARDUINOJSON_NAMESPACE { - -template <> -struct Reader { - const char* _ptr; - - public: - explicit Reader(const __FlashStringHelper* ptr) - : _ptr(reinterpret_cast(ptr)) {} - - int read() { - return pgm_read_byte(_ptr++); - } - - size_t readBytes(char* buffer, size_t length) { - memcpy_P(buffer, _ptr, length); - _ptr += length; - return length; - } -}; - -template <> -struct BoundedReader { - const char* _ptr; - const char* _end; - - public: - explicit BoundedReader(const __FlashStringHelper* ptr, size_t size) - : _ptr(reinterpret_cast(ptr)), _end(_ptr + size) {} - - int read() { - if (_ptr < _end) - return pgm_read_byte(_ptr++); - else - return -1; - } - - size_t readBytes(char* buffer, size_t length) { - size_t available = static_cast(_end - _ptr); - if (available < length) - length = available; - memcpy_P(buffer, _ptr, length); - _ptr += length; - return length; - } -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template <> +struct Reader { + const char* _ptr; + + public: + explicit Reader(const __FlashStringHelper* ptr) + : _ptr(reinterpret_cast(ptr)) {} + + int read() { + return pgm_read_byte(_ptr++); + } + + size_t readBytes(char* buffer, size_t length) { + memcpy_P(buffer, _ptr, length); + _ptr += length; + return length; + } +}; + +template <> +struct BoundedReader { + const char* _ptr; + const char* _end; + + public: + explicit BoundedReader(const __FlashStringHelper* ptr, size_t size) + : _ptr(reinterpret_cast(ptr)), _end(_ptr + size) {} + + int read() { + if (_ptr < _end) + return pgm_read_byte(_ptr++); + else + return -1; + } + + size_t readBytes(char* buffer, size_t length) { + size_t available = static_cast(_end - _ptr); + if (available < length) + length = available; + memcpy_P(buffer, _ptr, length); + _ptr += length; + return length; + } +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp index 2f07c3442..1c2893031 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/IteratorReader.hpp @@ -1,43 +1,43 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -namespace ARDUINOJSON_NAMESPACE { - -template -class IteratorReader { - TIterator _ptr, _end; - - public: - explicit IteratorReader(TIterator begin, TIterator end) - : _ptr(begin), _end(end) {} - - int read() { - if (_ptr < _end) - return static_cast(*_ptr++); - else - return -1; - } - - size_t readBytes(char* buffer, size_t length) { - size_t i = 0; - while (i < length && _ptr < _end) buffer[i++] = *_ptr++; - return i; - } -}; - -template -struct void_ { - typedef void type; -}; - -template -struct Reader::type> - : IteratorReader { - explicit Reader(const TSource& source) - : IteratorReader(source.begin(), - source.end()) {} -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +namespace ARDUINOJSON_NAMESPACE { + +template +class IteratorReader { + TIterator _ptr, _end; + + public: + explicit IteratorReader(TIterator begin, TIterator end) + : _ptr(begin), _end(end) {} + + int read() { + if (_ptr < _end) + return static_cast(*_ptr++); + else + return -1; + } + + size_t readBytes(char* buffer, size_t length) { + size_t i = 0; + while (i < length && _ptr < _end) buffer[i++] = *_ptr++; + return i; + } +}; + +template +struct void_ { + typedef void type; +}; + +template +struct Reader::type> + : IteratorReader { + explicit Reader(const TSource& source) + : IteratorReader(source.begin(), + source.end()) {} +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp similarity index 96% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp index 5f238a1df..44cc63cdd 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/RamReader.hpp @@ -1,50 +1,50 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { - -template -struct IsCharOrVoid { - static const bool value = - is_same::value || is_same::value || - is_same::value || is_same::value; -}; - -template -struct IsCharOrVoid : IsCharOrVoid {}; - -template -struct Reader::value>::type> { - const char* _ptr; - - public: - explicit Reader(const void* ptr) - : _ptr(ptr ? reinterpret_cast(ptr) : "") {} - - int read() { - return static_cast(*_ptr++); - } - - size_t readBytes(char* buffer, size_t length) { - for (size_t i = 0; i < length; i++) buffer[i] = *_ptr++; - return length; - } -}; - -template -struct BoundedReader::value>::type> - : public IteratorReader { - public: - explicit BoundedReader(const void* ptr, size_t len) - : IteratorReader(reinterpret_cast(ptr), - reinterpret_cast(ptr) + len) {} -}; - -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct IsCharOrVoid { + static const bool value = + is_same::value || is_same::value || + is_same::value || is_same::value; +}; + +template +struct IsCharOrVoid : IsCharOrVoid {}; + +template +struct Reader::value>::type> { + const char* _ptr; + + public: + explicit Reader(const void* ptr) + : _ptr(ptr ? reinterpret_cast(ptr) : "") {} + + int read() { + return static_cast(*_ptr++); + } + + size_t readBytes(char* buffer, size_t length) { + for (size_t i = 0; i < length; i++) buffer[i] = *_ptr++; + return length; + } +}; + +template +struct BoundedReader::value>::type> + : public IteratorReader { + public: + explicit BoundedReader(const void* ptr, size_t len) + : IteratorReader(reinterpret_cast(ptr), + reinterpret_cast(ptr) + len) {} +}; + +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp similarity index 95% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp index 1e7f83fd4..e4f56145b 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/StdStreamReader.hpp @@ -1,29 +1,29 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include - -namespace ARDUINOJSON_NAMESPACE { - -template -struct Reader::value>::type> { - public: - explicit Reader(std::istream& stream) : _stream(&stream) {} - - int read() { - return _stream->get(); - } - - size_t readBytes(char* buffer, size_t length) { - _stream->read(buffer, static_cast(length)); - return static_cast(_stream->gcount()); - } - - private: - std::istream* _stream; -}; -} // namespace ARDUINOJSON_NAMESPACE +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader::value>::type> { + public: + explicit Reader(std::istream& stream) : _stream(&stream) {} + + int read() { + return _stream->get(); + } + + size_t readBytes(char* buffer, size_t length) { + _stream->read(buffer, static_cast(length)); + return static_cast(_stream->gcount()); + } + + private: + std::istream* _stream; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp new file mode 100644 index 000000000..aecc9de83 --- /dev/null +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/Readers/VariantReader.hpp @@ -0,0 +1,34 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2020 +// MIT License + +#pragma once + +#include +#include + +namespace ARDUINOJSON_NAMESPACE { + +template +struct Reader, void> : Reader { + explicit Reader(const ElementProxy& x) + : Reader(x.template as()) {} +}; + +template +struct Reader, void> : Reader { + explicit Reader(const MemberProxy& x) + : Reader(x.template as()) {} +}; + +template <> +struct Reader : Reader { + explicit Reader(VariantRef x) : Reader(x.as()) {} +}; + +template <> +struct Reader : Reader { + explicit Reader(VariantConstRef x) + : Reader(x.as()) {} +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp similarity index 85% rename from lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp rename to lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp index f80f587bf..d0907842a 100644 --- a/lib_standalone/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/lib/ArduinoJson/src/ArduinoJson/Deserialization/deserialize.hpp @@ -1,71 +1,68 @@ -// ArduinoJson - arduinojson.org -// Copyright Benoit Blanchon 2014-2020 -// MIT License - -#pragma once - -#include -#include -#include -#include -#include - -namespace ARDUINOJSON_NAMESPACE { - -template