From e633292df18f3056e58616bdf2b7f9ddf81eb8a8 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 19 Jan 2019 14:45:16 +0100 Subject: [PATCH] Replaced JsonDocument::nestingLimit with a param to deserializeJson() --- CHANGELOG.md | 21 ++++ src/ArduinoJson.hpp | 4 + .../Deserialization/NestingLimit.hpp | 17 +++ .../Deserialization/deserialize.hpp | 32 +++--- src/ArduinoJson/Document/JsonDocument.hpp | 9 +- src/ArduinoJson/Json/JsonDeserializer.hpp | 25 +++-- .../MsgPack/MsgPackDeserializer.hpp | 26 +++-- test/JsonDeserializer/nestingLimit.cpp | 102 ++++++++++++++---- test/JsonDocument/DynamicJsonDocument.cpp | 10 -- test/JsonDocument/StaticJsonDocument.cpp | 12 --- test/MsgPackDeserializer/nestingLimit.cpp | 89 +++++++++++---- 11 files changed, 249 insertions(+), 98 deletions(-) create mode 100644 src/ArduinoJson/Deserialization/NestingLimit.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index f6eb155b..a2e97771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,13 @@ HEAD * `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()` > ### BREAKING CHANGES > +> #### `DynamicJsonDocument`'s constructor +> > The parameter to the constructor of `DynamicJsonDocument` is now mandatory > > Old code: @@ -28,6 +32,23 @@ HEAD > ```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) ----------- diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index 02223b27..a0a6ffee 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -49,4 +49,8 @@ using ARDUINOJSON_NAMESPACE::serializeJson; using ARDUINOJSON_NAMESPACE::serializeJsonPretty; using ARDUINOJSON_NAMESPACE::serializeMsgPack; using ARDUINOJSON_NAMESPACE::StaticJsonDocument; + +namespace DeserializationOption { +using ARDUINOJSON_NAMESPACE::NestingLimit; +} } // namespace ArduinoJson diff --git a/src/ArduinoJson/Deserialization/NestingLimit.hpp b/src/ArduinoJson/Deserialization/NestingLimit.hpp new file mode 100644 index 00000000..64e57173 --- /dev/null +++ b/src/ArduinoJson/Deserialization/NestingLimit.hpp @@ -0,0 +1,17 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +#pragma once + +#include "../Configuration.hpp" + +namespace ARDUINOJSON_NAMESPACE { + +struct NestingLimit { + NestingLimit() : value(ARDUINOJSON_DEFAULT_NESTING_LIMIT) {} + explicit NestingLimit(uint8_t n) : value(n) {} + + uint8_t value; +}; +} // namespace ARDUINOJSON_NAMESPACE diff --git a/src/ArduinoJson/Deserialization/deserialize.hpp b/src/ArduinoJson/Deserialization/deserialize.hpp index d2d5bdbd..c3a4fa69 100644 --- a/src/ArduinoJson/Deserialization/deserialize.hpp +++ b/src/ArduinoJson/Deserialization/deserialize.hpp @@ -5,12 +5,13 @@ #pragma once #include "../StringStorage/StringStorage.hpp" -#include "./ArduinoStreamReader.hpp" -#include "./CharPointerReader.hpp" -#include "./DeserializationError.hpp" -#include "./FlashStringReader.hpp" -#include "./IteratorReader.hpp" -#include "./StdStreamReader.hpp" +#include "ArduinoStreamReader.hpp" +#include "CharPointerReader.hpp" +#include "DeserializationError.hpp" +#include "FlashStringReader.hpp" +#include "IteratorReader.hpp" +#include "NestingLimit.hpp" +#include "StdStreamReader.hpp" namespace ARDUINOJSON_NAMESPACE { @@ -26,22 +27,24 @@ TDeserializer makeDeserializer(MemoryPool &pool, // TString = const std::string&, const String& template