mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 16:14:05 +01:00
Implement nesting() out of VariantData
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <ArduinoJson/Polyfills/attributes.hpp>
|
||||
#include <ArduinoJson/Strings/StoragePolicy.hpp>
|
||||
#include <ArduinoJson/Variant/VariantData.hpp>
|
||||
#include <ArduinoJson/Variant/Visitor.hpp>
|
||||
|
||||
namespace ARDUINOJSON_NAMESPACE {
|
||||
|
||||
@@ -106,4 +107,21 @@ inline bool variantIsNull(const VariantData *var) {
|
||||
return var == 0 || var->isNull();
|
||||
}
|
||||
|
||||
inline size_t variantNesting(const VariantData *var) {
|
||||
if (!var)
|
||||
return 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace ARDUINOJSON_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user