pub struct JsonDecodeSession<'a, R = JsonResource, Q = usize>where
Q: ResourceQuantity,{ /* private fields */ }json only.Expand description
Mutable resource accounting for one JSON decoding operation.
Use Self::from_limits for a session that owns budgets created from
immutable limits, or one of the borrowing_* constructors when the caller
owns the budgets. Create an attempt with Self::begin_value for each
complete value; input charges are immediate, while value accounting is
committed by JsonDecodeAttempt::commit.
§Type Parameters
R- Caller-defined resource identity retained by limits and errors.Q- Exact unsigned quantity used for measurements and accounting.
§Examples
use qubit_budget::json::JsonDecodeLimits;
use qubit_budget::json::JsonDecodeSession;
use qubit_budget::json::JsonMeasurement;
let limits = JsonDecodeLimits::builder()
.max_input_bytes(4_usize)
.max_nodes(1_usize)
.build();
let mut session = JsonDecodeSession::from_limits(limits);
let mut attempt = session.begin_value();
attempt
.try_consume_input_bytes(4)
.expect("the input should fit");
attempt
.try_admit(JsonMeasurement::Null { depth: 1 })
.expect("the value should fit");
attempt.commit()?;
assert_eq!(session.input_budget().expect("input budget").used(), 4);Implementations§
Source§impl<'a, R, Q> JsonDecodeSession<'a, R, Q>where
R: Clone,
Q: ResourceQuantity,
impl<'a, R, Q> JsonDecodeSession<'a, R, Q>where
R: Clone,
Q: ResourceQuantity,
Sourcepub fn borrowing_value(value: &'a mut JsonValueBudget<R, Q>) -> Self
pub fn borrowing_value(value: &'a mut JsonValueBudget<R, Q>) -> Self
Sourcepub fn borrowing_input(
input: &'a mut ResourceBudget<R, Q>,
value: &'a mut JsonValueBudget<R, Q>,
) -> Self
pub fn borrowing_input( input: &'a mut ResourceBudget<R, Q>, value: &'a mut JsonValueBudget<R, Q>, ) -> Self
Sourcepub fn borrowing_all(
input: &'a mut ResourceBudget<R, Q>,
normalized_input: &'a mut ResourceBudget<R, Q>,
value: &'a mut JsonValueBudget<R, Q>,
) -> Self
pub fn borrowing_all( input: &'a mut ResourceBudget<R, Q>, normalized_input: &'a mut ResourceBudget<R, Q>, value: &'a mut JsonValueBudget<R, Q>, ) -> Self
Creates a session borrowing all caller-owned decode budgets.
§Parameters
input- Input supplied to this operation.normalized_input- Optional caller-owned normalized-input budget.value- Caller-owned JSON value budget to update after a successful decode attempt.
§Returns
Creates a session borrowing all caller-owned decode budgets.
Sourcepub fn begin_value(&mut self) -> JsonDecodeAttempt<'_, R, Q>
pub fn begin_value(&mut self) -> JsonDecodeAttempt<'_, R, Q>
Starts accounting for one complete JSON value.
The returned attempt charges raw and normalized input immediately, but
publishes staged JSON value accounting only after a successful commit.
A value-admission failure poisons commit; dropping the attempt rolls
back only the staged value state.
§Returns
Starts accounting for one complete JSON value.
Sourcepub fn input_budget(&self) -> Option<&ResourceBudget<R, Q>>
pub fn input_budget(&self) -> Option<&ResourceBudget<R, Q>>
Returns the raw input budget when configured.
§Returns
Returns the raw input budget when configured.
None indicates that the corresponding limit or budget dimension is
unconfigured.
Sourcepub fn max_input_bytes(&self) -> Option<Q>
pub fn max_input_bytes(&self) -> Option<Q>
Returns the configured raw input-byte maximum.
§Returns
Returns the configured raw input-byte maximum.
None indicates that the corresponding limit or budget dimension is
unconfigured.
Sourcepub fn max_normalized_input_bytes(&self) -> Option<Q>
pub fn max_normalized_input_bytes(&self) -> Option<Q>
Returns the configured normalized input-byte maximum.
§Returns
Returns the configured normalized input-byte maximum.
None indicates that the corresponding limit or budget dimension is
unconfigured.
Sourcepub fn normalized_input_budget(&self) -> Option<&ResourceBudget<R, Q>>
pub fn normalized_input_budget(&self) -> Option<&ResourceBudget<R, Q>>
Returns the normalized input budget when configured.
§Returns
Returns the normalized input budget when configured.
None indicates that the corresponding limit or budget dimension is
unconfigured.
Sourcepub fn value_budget(&self) -> &JsonValueBudget<R, Q>
pub fn value_budget(&self) -> &JsonValueBudget<R, Q>
Returns the value budget for read-only inspection.
§Returns
Returns the value budget for read-only inspection.