Skip to main content

skip_field_depth

Function skip_field_depth 

Source
pub fn skip_field_depth(
    tag: Tag,
    buf: &mut impl Buf,
    depth: u32,
) -> Result<(), DecodeError>
Expand description

Skip a field’s payload, with an explicit recursion depth budget for groups.

Generated code must call this (not skip_field) when a decode context is in scope (passing ctx.depth()), to prevent unknown group fields from resetting the recursion budget and allowing depth-doubling attacks.

depth is the remaining nesting budget. For group fields this function calls itself recursively, decrementing depth by one each level. Unlike decode_unknown_field, skipping materializes nothing, so this function deliberately takes only the depth — it never consumes the unknown-field allowance.

§Errors

Returns an error if the buffer is too short, if a length-delimited payload length overflows usize, if the wire type is EndGroup (malformed stream), or if group nesting exceeds depth.