16bool checkValue(
const Value&
value,
size_t depth,
size_t maxDepth,
size_t maxElements,
size_t maxStringBytes,
17 ValueBudget& budget) {
18 if (
depth > maxDepth)
return false;
20 [&](
const auto&
current) ->
bool {
21 using T = std::decay_t<
decltype(
current)>;
22 if constexpr (std::is_same_v<T, std::string>) {
23 budget.stringBytes +=
current.size();
24 return budget.stringBytes <= maxStringBytes;
25 }
else if constexpr (std::is_same_v<T, Value::Array>) {
26 budget.elements +=
current.size();
27 if (budget.elements > maxElements)
return false;
28 for (
const auto& entry :
current)
29 if (!checkValue(entry,
depth + 1, maxDepth, maxElements, maxStringBytes, budget))
return false;
31 }
else if constexpr (std::is_same_v<T, Value::Object>) {
32 budget.elements +=
current.size();
33 if (budget.elements > maxElements)
return false;
35 budget.stringBytes +=
key.size();
36 if (budget.stringBytes > maxStringBytes ||
37 !checkValue(entry,
depth + 1, maxDepth, maxElements, maxStringBytes, budget))
51 if (maxDepth == 0)
return false;
53 return checkValue(*
this, 1, maxDepth, maxElements, maxStringBytes, budget);
bool isWithinLimits(size_t maxDepth, size_t maxElements, size_t maxStringBytes) const
Validate nesting, element count and approximate string byte limits.
Type type() const
Return the active value type.