pub struct ValueWireEncodePreflight { /* private fields */ }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
Creates a checker with zero accumulated usage from one limit profile.
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.
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.
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.
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.
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.
Trait Implementations§
Source§impl Clone for ValueWireEncodePreflight
impl Clone for ValueWireEncodePreflight
Source§fn clone(&self) -> ValueWireEncodePreflight
fn clone(&self) -> ValueWireEncodePreflight
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more