Skip to main content

min_value_nodes

Function min_value_nodes 

Source
fn min_value_nodes(schema: SchemaNode<'_>) -> usize
Expand description

A lower bound on the number of Value nodes a single value of schema materializes into when decoded.

Used to weight an array/map element so the cumulative MAX_VALUE_NODES cap bounds decoded memory, not just element count. The amplifying case the cap exists for — null and records of only zero-width fields — is counted exactly here (a record always materializes every field, and none of these types involve a union/array/map whose runtime size we couldn’t predict), so the bound is tight where it matters most.

As with min_encoded_len, only an under-estimate is ever safe (an over-estimate would reject valid data), so a nested array/map contributes 1 — its empty-collection floor — and its actual contents are charged against the shared MAX_VALUE_NODES budget as they are decoded (so the cap still composes through nesting); a union contributes 1 (its count is already bounded by the remaining input via its one-byte branch floor); and unprovable schema-resolution pieces contribute 1. Every value is at least one node, so the weight is always >= 1.