forked from bblanchon/ArduinoJson
Add VariantData::nesting()
This commit is contained in:
@ -157,7 +157,7 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
|
|||||||
// Returns the depth (nesting level) of the array.
|
// Returns the depth (nesting level) of the array.
|
||||||
// https://arduinojson.org/v6/api/jsondocument/nesting/
|
// https://arduinojson.org/v6/api/jsondocument/nesting/
|
||||||
size_t nesting() const {
|
size_t nesting() const {
|
||||||
return variantNesting(&data_);
|
return data_.nesting();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the number of elements in the root array or object.
|
// Returns the number of elements in the root array or object.
|
||||||
|
@ -256,6 +256,20 @@ class VariantData {
|
|||||||
content_.asCollection.movePointers(variantDistance);
|
content_.asCollection.movePointers(variantDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t nesting() const {
|
||||||
|
auto collection = asCollection();
|
||||||
|
if (!collection)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
size_t maxChildNesting = 0;
|
||||||
|
for (const VariantSlot* s = collection->head(); s; s = s->next()) {
|
||||||
|
size_t childNesting = s->data()->nesting();
|
||||||
|
if (childNesting > maxChildNesting)
|
||||||
|
maxChildNesting = childNesting;
|
||||||
|
}
|
||||||
|
return maxChildNesting + 1;
|
||||||
|
}
|
||||||
|
|
||||||
void operator=(const VariantData& src) {
|
void operator=(const VariantData& src) {
|
||||||
content_ = src.content_;
|
content_ = src.content_;
|
||||||
flags_ = uint8_t((flags_ & OWNED_KEY_BIT) | (src.flags_ & ~OWNED_KEY_BIT));
|
flags_ = uint8_t((flags_ & OWNED_KEY_BIT) | (src.flags_ & ~OWNED_KEY_BIT));
|
||||||
|
@ -190,18 +190,7 @@ inline bool variantIsNull(const VariantData* var) {
|
|||||||
inline size_t variantNesting(const VariantData* var) {
|
inline size_t variantNesting(const VariantData* var) {
|
||||||
if (!var)
|
if (!var)
|
||||||
return 0;
|
return 0;
|
||||||
|
return var->nesting();
|
||||||
const CollectionData* collection = var->asCollection();
|
|
||||||
if (!collection)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
size_t maxChildNesting = 0;
|
|
||||||
for (const VariantSlot* s = collection->head(); s; s = s->next()) {
|
|
||||||
size_t childNesting = variantNesting(s->data());
|
|
||||||
if (childNesting > maxChildNesting)
|
|
||||||
maxChildNesting = childNesting;
|
|
||||||
}
|
|
||||||
return maxChildNesting + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
ARDUINOJSON_END_PRIVATE_NAMESPACE
|
||||||
|
Reference in New Issue
Block a user