pub struct ValueWireEncodePreflight { /* private fields */ }json only.Expand description
Performs conservative resource checks before Wire V1 sorting and formatting.
The checker accumulates conservative lower bounds across successful calls.
Each public check is atomic: if it returns an error, all counters are
restored to their values before that call. The checker does not serialize,
retain a sorting index, or replace the authoritative final
JsonEncodeSession checks.
§Examples
use qubit_budget::MeasuredBudgetError;
use qubit_budget::json::JsonEncodeLimits;
use qubit_budget::json::JsonResource;
use qubit_value::Value;
use qubit_value::ValueWireEncodePreflight;
let limits = JsonEncodeLimits::builder().max_nodes(2_usize).build();
let mut preflight = ValueWireEncodePreflight::new(limits);
preflight.check_value(&Value::from(1_i32))?;
preflight.check_value(&Value::from(2_i32))?;Implementations§
Source§impl ValueWireEncodePreflight
impl ValueWireEncodePreflight
Sourcepub fn new(limits: JsonEncodeLimits) -> Self
pub fn new(limits: JsonEncodeLimits) -> Self
Sourcepub fn new_value_limits(limits: JsonValueLimits) -> Self
pub fn new_value_limits(limits: JsonValueLimits) -> Self
Creates a checker with zero accumulated usage for value-only limits.
The outer output budget remains unconfigured because another protocol envelope is expected to account for it.
§Parameters
limits supplies value ceilings without an outer output limit.
§Returns
A checker with zero accumulated usage.
Sourcepub fn new_u64_limits(limits: JsonEncodeLimitsU64<JsonResource, u64>) -> Self
pub fn new_u64_limits(limits: JsonEncodeLimitsU64<JsonResource, u64>) -> Self
Creates a checker from the u64 profile used by configuration wire
limits.
Values greater than usize::MAX on the current platform saturate at
usize::MAX instead of wrapping or truncating.
§Parameters
limits supplies the unsigned 64-bit configuration profile.
§Returns
A checker with zero accumulated usage.
Sourcepub fn check_value(
&mut self,
value: &Value,
) -> Result<(), MeasuredBudgetError<JsonResource, usize>>
pub fn check_value( &mut self, value: &Value, ) -> Result<(), MeasuredBudgetError<JsonResource, usize>>
Checks and accumulates one scalar value at the root of a payload.
Returns the first exceeded JSON resource limit. If checking fails, the accumulated state is restored to its value before this call.
§Parameters
value is borrowed for this check and is not retained.
§Returns
Ok(()) when all applicable measurements are admitted.
§Errors
Returns a measured budget error when a per-value or cumulative resource limit is exceeded, or when a cumulative counter overflows.
Sourcepub fn check_values(
&mut self,
values: &MultiValues,
) -> Result<(), MeasuredBudgetError<JsonResource, usize>>
pub fn check_values( &mut self, values: &MultiValues, ) -> Result<(), MeasuredBudgetError<JsonResource, usize>>
Checks and accumulates one homogeneous collection at the payload root.
Returns the first exceeded JSON resource limit. If checking fails, the accumulated state is restored to its value before this call.
§Parameters
values is the borrowed collection to check as a root array.
§Returns
Ok(()) when all applicable measurements are admitted.
§Errors
Returns a measured budget error when a per-value or cumulative resource limit is exceeded, or when a cumulative counter overflows.
Sourcepub fn check_container(
&mut self,
value: &ValueContainer,
) -> Result<(), MeasuredBudgetError<JsonResource, usize>>
pub fn check_container( &mut self, value: &ValueContainer, ) -> Result<(), MeasuredBudgetError<JsonResource, usize>>
Checks and accumulates an explicit scalar-or-collection payload.
Returns the first exceeded JSON resource limit. If checking fails, the accumulated state is restored to its value before this call.
§Parameters
value selects a borrowed scalar or collection payload.
§Returns
Ok(()) when all applicable measurements are admitted.
§Errors
Returns a measured budget error when a per-value or cumulative resource limit is exceeded, or when a cumulative counter overflows.