pub struct DecodeContext<'a> { /* private fields */ }Expand description
Per-decode limits threaded through every merge call.
Carries the remaining recursion depth and a shared unknown-field
allowance. The context is Copy — passing it to a callee hands over the
current depth by value, while the unknown-field allowance lives in a
Cell owned by the top-level decode entry point, so
every field decoded under one entry point draws from the same
allowance.
Constructed automatically by the Message convenience methods
(decode, decode_from_slice,
merge_from_slice) and by DecodeOptions.
Construct one manually only when calling Message::merge or the other
depth-threading methods directly — and construct a fresh limit cell
per top-level decode. Reusing one cell across decode calls makes the
limit cumulative: each call drains it further until every decode fails
with DecodeError::UnknownFieldLimitExceeded.
use core::cell::Cell;
use buffa::{DecodeContext, Message, DEFAULT_UNKNOWN_FIELD_LIMIT, RECURSION_LIMIT};
let limit = Cell::new(DEFAULT_UNKNOWN_FIELD_LIMIT);
let mut msg = Person::default();
msg.merge(&mut bytes, DecodeContext::new(RECURSION_LIMIT, &limit))?;Implementations§
Source§impl<'a> DecodeContext<'a>
impl<'a> DecodeContext<'a>
Sourcepub fn new(depth: u32, unknown_field_limit: &'a Cell<usize>) -> Self
pub fn new(depth: u32, unknown_field_limit: &'a Cell<usize>) -> Self
Create a context with depth remaining recursion levels and the
remaining unknown-field allowance stored in unknown_field_limit.
Sourcepub fn remaining_unknown_fields(&self) -> usize
pub fn remaining_unknown_fields(&self) -> usize
The number of additional unknown fields this decode may materialize.
Sourcepub fn descend(self) -> Result<Self, DecodeError>
pub fn descend(self) -> Result<Self, DecodeError>
Consume one level of recursion depth.
§Errors
Returns DecodeError::RecursionLimitExceeded when the depth budget
is exhausted.
Sourcepub fn register_unknown_field(&self) -> Result<(), DecodeError>
pub fn register_unknown_field(&self) -> Result<(), DecodeError>
Consume one slot of the shared unknown-field allowance.
Call before materializing an UnknownField.
§Errors
Returns DecodeError::UnknownFieldLimitExceeded (leaving the
allowance unchanged) when no slots remain.
Trait Implementations§
Source§impl<'a> Clone for DecodeContext<'a>
impl<'a> Clone for DecodeContext<'a>
Source§fn clone(&self) -> DecodeContext<'a>
fn clone(&self) -> DecodeContext<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more