Skip to main content

min_encoded_len

Function min_encoded_len 

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

A lower bound on the number of bytes any value of schema encodes to on the wire.

Used to reject an array block whose claimed element count could not possibly fit in the remaining input: a block of len elements occupies at least len * min_encoded_len bytes. Only an under-estimate is ever safe here — an over-estimate would reject valid data — so anything whose floor we can’t prove (schema-resolution pieces, named-type recursion cycles) contributes 0, which simply relaxes the bound.

Crucially this returns 0 for zero-width types — null, an empty record, a record of only such fields — because those genuinely encode to no bytes. Materialize’s own writer emits a ten-element array<null> as [20, 0], so a blanket “count must not exceed remaining bytes” rule would reject valid input. For zero-width element types the caller falls back to the cumulative MAX_VALUE_NODES cap (weighted by min_value_nodes).