forked from bblanchon/ArduinoJson
Replaced JsonDocument::nestingLimit with a param to deserializeJson()
This commit is contained in:
@ -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
|
||||
|
17
src/ArduinoJson/Deserialization/NestingLimit.hpp
Normal file
17
src/ArduinoJson/Deserialization/NestingLimit.hpp
Normal file
@ -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
|
@ -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<TReader, TWriter> makeDeserializer(MemoryPool &pool,
|
||||
// TString = const std::string&, const String&
|
||||
template <template <typename, typename> class TDeserializer, typename TString>
|
||||
typename enable_if<!is_array<TString>::value, DeserializationError>::type
|
||||
deserialize(JsonDocument &doc, const TString &input) {
|
||||
deserialize(JsonDocument &doc, const TString &input,
|
||||
NestingLimit nestingLimit) {
|
||||
doc.clear();
|
||||
return makeDeserializer<TDeserializer>(
|
||||
doc.memoryPool(), makeReader(input),
|
||||
makeStringStorage(doc.memoryPool(), input), doc.nestingLimit)
|
||||
makeStringStorage(doc.memoryPool(), input), nestingLimit.value)
|
||||
.parse(doc.data());
|
||||
}
|
||||
//
|
||||
// DeserializationError deserialize(JsonDocument& doc, TChar* input);
|
||||
// TChar* = char*, const char*, const __FlashStringHelper*
|
||||
template <template <typename, typename> class TDeserializer, typename TChar>
|
||||
DeserializationError deserialize(JsonDocument &doc, TChar *input) {
|
||||
DeserializationError deserialize(JsonDocument &doc, TChar *input,
|
||||
NestingLimit nestingLimit) {
|
||||
doc.clear();
|
||||
return makeDeserializer<TDeserializer>(
|
||||
doc.memoryPool(), makeReader(input),
|
||||
makeStringStorage(doc.memoryPool(), input), doc.nestingLimit)
|
||||
makeStringStorage(doc.memoryPool(), input), nestingLimit.value)
|
||||
.parse(doc.data());
|
||||
}
|
||||
//
|
||||
@ -50,22 +53,23 @@ DeserializationError deserialize(JsonDocument &doc, TChar *input) {
|
||||
// TChar* = char*, const char*, const __FlashStringHelper*
|
||||
template <template <typename, typename> class TDeserializer, typename TChar>
|
||||
DeserializationError deserialize(JsonDocument &doc, TChar *input,
|
||||
size_t inputSize) {
|
||||
size_t inputSize, NestingLimit nestingLimit) {
|
||||
doc.clear();
|
||||
return makeDeserializer<TDeserializer>(
|
||||
doc.memoryPool(), makeReader(input, inputSize),
|
||||
makeStringStorage(doc.memoryPool(), input), doc.nestingLimit)
|
||||
makeStringStorage(doc.memoryPool(), input), nestingLimit.value)
|
||||
.parse(doc.data());
|
||||
}
|
||||
//
|
||||
// DeserializationError deserialize(JsonDocument& doc, TStream input);
|
||||
// TStream = std::istream&, Stream&
|
||||
template <template <typename, typename> class TDeserializer, typename TStream>
|
||||
DeserializationError deserialize(JsonDocument &doc, TStream &input) {
|
||||
DeserializationError deserialize(JsonDocument &doc, TStream &input,
|
||||
NestingLimit nestingLimit) {
|
||||
doc.clear();
|
||||
return makeDeserializer<TDeserializer>(
|
||||
doc.memoryPool(), makeReader(input),
|
||||
makeStringStorage(doc.memoryPool(), input), doc.nestingLimit)
|
||||
makeStringStorage(doc.memoryPool(), input), nestingLimit.value)
|
||||
.parse(doc.data());
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -12,8 +12,6 @@ namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
class JsonDocument : public Visitable {
|
||||
public:
|
||||
uint8_t nestingLimit;
|
||||
|
||||
template <typename Visitor>
|
||||
void accept(Visitor& visitor) const {
|
||||
return getVariant().accept(visitor);
|
||||
@ -67,14 +65,11 @@ class JsonDocument : public Visitable {
|
||||
}
|
||||
|
||||
protected:
|
||||
JsonDocument(MemoryPool pool)
|
||||
: nestingLimit(ARDUINOJSON_DEFAULT_NESTING_LIMIT), _pool(pool) {}
|
||||
JsonDocument(MemoryPool pool) : _pool(pool) {}
|
||||
|
||||
JsonDocument(char* buf, size_t capa)
|
||||
: nestingLimit(ARDUINOJSON_DEFAULT_NESTING_LIMIT), _pool(buf, capa) {}
|
||||
JsonDocument(char* buf, size_t capa) : _pool(buf, capa) {}
|
||||
|
||||
void copy(const JsonDocument& src) {
|
||||
nestingLimit = src.nestingLimit;
|
||||
to<VariantRef>().set(src.as<VariantRef>());
|
||||
}
|
||||
|
||||
|
@ -337,23 +337,30 @@ class JsonDeserializer {
|
||||
};
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeJson(JsonDocument &doc, const TInput &input) {
|
||||
return deserialize<JsonDeserializer>(doc, input);
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument &doc, const TInput &input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit);
|
||||
}
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeJson(JsonDocument &doc, TInput *input) {
|
||||
return deserialize<JsonDeserializer>(doc, input);
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument &doc, TInput *input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit);
|
||||
}
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeJson(JsonDocument &doc, TInput *input,
|
||||
size_t inputSize) {
|
||||
return deserialize<JsonDeserializer>(doc, input, inputSize);
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument &doc, TInput *input, size_t inputSize,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, inputSize, nestingLimit);
|
||||
}
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeJson(JsonDocument &doc, TInput &input) {
|
||||
return deserialize<JsonDeserializer>(doc, input);
|
||||
DeserializationError deserializeJson(
|
||||
JsonDocument &doc, TInput &input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<JsonDeserializer>(doc, input, nestingLimit);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
@ -327,24 +327,30 @@ class MsgPackDeserializer {
|
||||
};
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc,
|
||||
const TInput &input) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input);
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, const TInput &input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit);
|
||||
}
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, TInput *input) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input);
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TInput *input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit);
|
||||
}
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, TInput *input,
|
||||
size_t inputSize) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize);
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TInput *input, size_t inputSize,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, inputSize, nestingLimit);
|
||||
}
|
||||
|
||||
template <typename TInput>
|
||||
DeserializationError deserializeMsgPack(JsonDocument &doc, TInput &input) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input);
|
||||
DeserializationError deserializeMsgPack(
|
||||
JsonDocument &doc, TInput &input,
|
||||
NestingLimit nestingLimit = NestingLimit()) {
|
||||
return deserialize<MsgPackDeserializer>(doc, input, nestingLimit);
|
||||
}
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
Reference in New Issue
Block a user