Skip to main content

DecodeContext

Struct DecodeContext 

Source
pub struct DecodeContext<'a> { /* private fields */ }
Expand description

Shared monotonic decode state.

Implementations§

Source§

impl DecodeContext<'_>

Source

pub fn reserve_capacity_limit<T>( &self, values: &mut Vec<T>, count: usize, operation: &'static str, ) -> Result<(), ResourceLimit>

Reserve backing storage without admitting values not yet inserted.

Source

pub fn reserve_capacity<T>( &self, values: &mut Vec<T>, count: usize, operation: &'static str, ) -> Result<(), CodecError>

Retains vector storage whose slots were admitted in aggregate.

Source

pub fn vector_storage<T>( &self, count: usize, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Creates retained storage whose collection slots are admitted separately.

Source

pub fn reserve_scoped_collection<T>( &self, count: usize, operation: &'static str, ) -> Result<ScopedReservation<'_>, CodecError>

Admits scoped collection slots whose storage is allocated by a later operation.

Source

pub fn scoped_vector_storage<T>( &self, count: usize, operation: &'static str, ) -> Result<(Vec<T>, ScopedReservation<'_>), CodecError>

Creates scoped storage whose collection slots are admitted separately.

Source

pub fn reserve_scoped_vec<T>( &self, reservation: &mut ScopedReservation<'_>, values: &mut Vec<T>, count: usize, operation: &'static str, ) -> Result<(), CodecError>

Grows scoped storage and admits additional vector slots.

Source

pub fn reserve_scoped_vec_limit<T>( &self, reservation: &mut ScopedReservation<'_>, values: &mut Vec<T>, count: usize, operation: &'static str, ) -> Result<(), ResourceLimit>

Reserves storage with a resource-only refusal channel.

Source

pub fn push_scoped_vec<T>( &self, reservation: &mut ScopedReservation<'_>, values: &mut Vec<T>, value: T, operation: &'static str, ) -> Result<(), CodecError>

Appends one item with scoped storage and a charged collection slot.

Source

pub fn reserve_temporary_vec<T>( &self, values: &mut Vec<T>, count: usize, operation: &'static str, ) -> Result<ScopedReservation<'_>, ResourceLimit>

Reserves temporary vector storage and returns its live byte reservation.

Source

pub fn copy_temporary_slice<T: Copy>( &self, values: &[T], operation: &'static str, ) -> Result<(Vec<T>, ScopedReservation<'_>), ResourceLimit>

Copies a slice into scoped storage and returns its live byte reservation.

Source

pub fn collect_retained_texts<'text>( &self, values: impl IntoIterator<Item = &'text str>, operation: &'static str, ) -> Result<Vec<String>, CodecError>

Collects retained text and charges both vector storage and text bytes.

Source

pub fn collect_scoped_texts<'text>( &self, values: impl IntoIterator<Item = &'text str>, operation: &'static str, ) -> Result<(Vec<String>, ScopedReservation<'_>), CodecError>

Copies scoped text values and returns the reservation for their storage.

Source

pub fn format_scoped_text( &self, reservation: &mut ScopedReservation<'_>, args: Arguments<'_>, operation: &'static str, ) -> Result<String, CodecError>

Formats text in an existing scope after charging its byte count as work.

Source

pub fn reserve_record_vec<T>( &self, records: &mut Vec<T>, count: usize, text_bytes: u64, operation: &'static str, ) -> Result<(), CodecError>

Admits records, retains their storage and additional text, and reserves slots.

Source

pub fn collect_retained_vec<T>( &self, values: impl IntoIterator<Item = T>, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Collects retained slots before adding each value.

Source

pub fn charge_btree_lookup( &self, len: usize, operation: &'static str, ) -> Result<(), CodecError>

Admits the comparison bound for one standard-library B-tree lookup.

Source

pub fn insert_scoped_btree_set<T: Ord>( &self, reservation: &mut ScopedReservation<'_>, values: &mut BTreeSet<T>, value: T, work_operation: &'static str, operation: &'static str, ) -> Result<bool, CodecError>

Inserts a new scoped tree key after charging lookup work and node storage.

Source

pub fn insert_scoped_btree_map_if_vacant<K: Ord, V>( &self, reservation: &mut ScopedReservation<'_>, values: &mut BTreeMap<K, V>, key: K, value: V, work_operation: &'static str, operation: &'static str, ) -> Result<bool, CodecError>

Inserts a vacant scoped tree entry after charging lookup work and node storage.

Source

pub fn push_scoped_btree_group<K: Ord, V>( &self, reservation: &mut ScopedReservation<'_>, groups: &mut BTreeMap<K, Vec<V>>, key: K, value: impl FnOnce() -> V, owned_bytes: usize, operation: &'static str, ) -> Result<(), CodecError>

Appends a lazily built value to a scoped group after aggregate admission.

Source

pub fn admit_retained_btree_record<K, V>( &self, owned_bytes: usize, operation: &'static str, ) -> Result<(), CodecError>

Admits tree-record storage, owned bytes, one slot and one work unit.

Without the current tree length, each record admits one backing node.

Source

pub fn collect_scoped_btree_groups<'ctx, K: Ord, V>( &'ctx self, values: impl IntoIterator<Item = (K, V)>, operation: &'static str, ) -> Result<(BTreeMap<K, Vec<V>>, ScopedReservation<'ctx>), CodecError>

Collects scoped groups in input order within each key.

Source

pub fn collect_scoped_btree_map<'ctx, K: Ord, V>( &'ctx self, values: impl IntoIterator<Item = (K, V)>, operation: &'static str, ) -> Result<(BTreeMap<K, V>, ScopedReservation<'ctx>), CodecError>

Collects scoped entries, keeping the last value for each key.

Source

pub fn reserve_scoped_string( &self, reservation: &mut ScopedReservation<'_>, text: &mut String, additional: usize, operation: &'static str, ) -> Result<(), CodecError>

Grows a scoped string after admitting its additional byte storage.

Source

pub fn scoped_string( &self, length: usize, operation: &'static str, ) -> Result<(String, ScopedReservation<'_>), CodecError>

Creates empty scoped text with fallible storage admission.

Source

pub fn collection_vec<T>( &self, count: usize, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Allocates a vector for count admitted items.

Source

pub fn reserve_vec<T>( &self, values: &mut Vec<T>, additional: usize, operation: &'static str, ) -> Result<(), CodecError>

Reserves additional vector items and charges their admission.

Source

pub fn reserve_vec_limit<T>( &self, values: &mut Vec<T>, additional: usize, operation: &'static str, ) -> Result<(), ResourceLimit>

Reserves storage with a resource-only refusal channel.

Source

pub fn collect_indexed_vec<T>( &self, count: usize, operation: &'static str, value_at: impl FnMut(usize) -> Result<T, CodecError>, ) -> Result<Vec<T>, CodecError>

Builds a vector of indexed values after charging all slots.

Source

pub fn push_vec<T>( &self, values: &mut Vec<T>, value: T, operation: &'static str, ) -> Result<(), CodecError>

Adds one vector item after charging its slot.

Source

pub fn push_formatted_retained( &self, values: &mut Vec<String>, args: Arguments<'_>, slots_operation: &'static str, text_operation: &'static str, ) -> Result<(), CodecError>

Adds a formatted retained note after charging its collection slot.

Source

pub fn append_vec<T>( &self, target: &mut Vec<T>, source: &mut Vec<T>, operation: &'static str, ) -> Result<(), CodecError>

Moves all source items into a vector after charging their slots.

Source

pub fn extend_vec<T>( &self, target: &mut Vec<T>, source: Vec<T>, operation: &'static str, ) -> Result<(), CodecError>

Moves owned items into a vector after charging their slots.

Source

pub fn collect_vec<T>( &self, values: impl IntoIterator<Item = T>, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Collects iterator values with a charged slot for each value.

Source

pub fn try_collect_vec<T, E: From<CodecError>>( &self, values: impl IntoIterator<Item = Result<T, E>>, operation: &'static str, ) -> Result<Vec<T>, E>

Collects fallible iterator values with a charged slot for each success.

Source

pub fn insert_scoped_btree_value<T: Ord>( &self, reservation: &mut ScopedReservation<'_>, values: &mut BTreeSet<T>, value: T, operation: &'static str, ) -> Result<bool, CodecError>

Inserts a unique tree value after admitting its scoped value storage.

Source

pub fn insert_hash_set<T: Eq + Hash>( &self, values: &mut HashSet<T>, value: T, operation: &'static str, ) -> Result<bool, CodecError>

Inserts a new set item after charging its slot.

Source

pub fn insert_string_set( &self, values: &mut HashSet<String>, value: &str, operation: &'static str, ) -> Result<bool, CodecError>

Inserts a copied string into a set if the value is new.

Source

pub fn extend_hash_set<T: Eq + Hash>( &self, values: &mut HashSet<T>, additions: impl IntoIterator<Item = T>, operation: &'static str, ) -> Result<(), CodecError>

Extends a set with one charged slot for each distinct new value.

Source

pub fn collect_hash_set<T: Eq + Hash>( &self, values: impl IntoIterator<Item = T>, operation: &'static str, ) -> Result<HashSet<T>, CodecError>

Collects distinct values into a charged hash set.

Source

pub fn admit_hash_map_entry<K: Eq + Hash, V>( &self, values: &mut HashMap<K, V>, key: &K, operation: &'static str, ) -> Result<(), CodecError>

Reserves a map slot only when the key is new.

Source

pub fn push_hash_group<K: Eq + Hash, V>( &self, values: &mut HashMap<K, Vec<V>>, key: K, value: V, index_operation: &'static str, value_operation: &'static str, ) -> Result<(), CodecError>

Appends a grouped value after admitting both new index and value slots.

Source

pub fn insert_hash_map<K: Eq + Hash, V>( &self, values: &mut HashMap<K, V>, key: K, value: V, operation: &'static str, ) -> Result<Option<V>, CodecError>

Inserts a map entry after admitting a new key, if needed.

Source

pub fn collect_hash_map<K: Eq + Hash, V>( &self, values: impl IntoIterator<Item = (K, V)>, operation: &'static str, ) -> Result<HashMap<K, V>, CodecError>

Collects entries into a charged hash map.

Source

pub fn copy_scoped_text( &self, text: &str, reservation: &mut ScopedReservation<'_>, operation: &'static str, ) -> Result<String, CodecError>

Copies temporary text while its scoped reservation remains live.

Source

pub fn push_back<T>( &self, values: &mut VecDeque<T>, value: T, operation: &'static str, ) -> Result<(), CodecError>

Appends a deque item after charging its slot.

Source

pub fn push_front<T>( &self, values: &mut VecDeque<T>, value: T, operation: &'static str, ) -> Result<(), CodecError>

Prepends a deque item after charging its slot.

Source

pub fn reserve_heap<T: Ord>( &self, values: &mut BinaryHeap<T>, count: usize, operation: &'static str, ) -> Result<(), CodecError>

Reserves slots in a binary heap after charging them.

Source

pub fn optional_collection_vec<T>( &self, present: bool, count: usize, operation: &'static str, ) -> Result<Option<Vec<T>>, CodecError>

Creates a charged vector only when the source is present.

Source

pub fn copy_rows<T: Copy>( &self, values: &[T], row_len: usize, row_operation: &'static str, item_operation: &'static str, ) -> Result<Vec<Vec<T>>, CodecError>

Copies a flat lane into rows after admitting every row and element slot.

Source

pub fn try_collect_retained_with<I, T, E: From<CodecError>>( &self, values: impl IntoIterator<Item = I>, operation: &'static str, map: impl FnMut(I) -> Result<T, E>, ) -> Result<Vec<T>, E>

Collects fallible values and admits the storage of each output slot.

Source

pub fn copy_slice<T: Copy>( &self, values: &[T], operation: &'static str, ) -> Result<Vec<T>, CodecError>

Copies a slice after charging its collection slots.

Source

pub fn collect_options<T>( &self, values: impl IntoIterator<Item = Option<T>>, operation: &'static str, ) -> Result<Option<Vec<T>>, CodecError>

Collects optional values, stopping at the first absent value.

Source

pub fn collect_fallible_options<T, E: Into<CodecError>>( &self, values: impl IntoIterator<Item = Result<Option<T>, E>>, operation: &'static str, ) -> Result<Option<Vec<T>>, CodecError>

Collects fallible optional values, stopping at the first absent value.

Source

pub fn collect_string_set<'a>( &self, values: impl IntoIterator<Item = &'a str>, operation: &'static str, ) -> Result<HashSet<String>, CodecError>

Collects retained strings into a charged hash set.

Source

pub fn copy_retained_rows<T: Copy>( &self, rows: &[Vec<T>], row_operation: &'static str, item_operation: &'static str, ) -> Result<Vec<Vec<T>>, CodecError>

Copies retained rows and charges row and item slots.

Source

pub fn copy_retained_set<T: Copy + Eq + Hash>( &self, values: &HashSet<T>, operation: &'static str, ) -> Result<HashSet<T>, CodecError>

Copies a retained set after charging storage and entries.

Source

pub fn reserve_set<T: Eq + Hash>( &self, values: &mut HashSet<T>, count: usize, operation: &'static str, ) -> Result<(), CodecError>

Reserves hash set entries after charging their slots.

Source

pub fn reserve_map<K: Eq + Hash, V>( &self, values: &mut HashMap<K, V>, count: usize, operation: &'static str, ) -> Result<(), CodecError>

Reserves hash map entries after charging their slots.

Source

pub fn admit_btree_node_storage<K, V>( &self, len: usize, operation: &'static str, ) -> Result<(), CodecError>

Admits the backing nodes for one ordered entry whose slot is already charged.

Source

pub fn admit_btree_entry<K: Ord, V>( &self, values: &BTreeMap<K, V>, key: &K, operation: &'static str, ) -> Result<(), CodecError>

Charges a new B-tree map key before insertion.

Source

pub fn insert_btree_map<K: Ord, V>( &self, values: &mut BTreeMap<K, V>, key: K, value: V, operation: &'static str, ) -> Result<Option<V>, CodecError>

Inserts a B-tree map entry after charging a new key.

Source

pub fn insert_btree_set<T: Ord>( &self, values: &mut BTreeSet<T>, value: T, operation: &'static str, ) -> Result<bool, CodecError>

Inserts a B-tree set item after charging a new value.

Source

pub fn collect_btree_set<T: Ord>( &self, values: impl IntoIterator<Item = T>, operation: &'static str, ) -> Result<BTreeSet<T>, CodecError>

Collects distinct ordered values after admitting each new entry.

Source

pub fn push_btree_group<K: Ord, V>( &self, groups: &mut BTreeMap<K, Vec<V>>, key: K, value: V, group_operation: &'static str, item_operation: &'static str, ) -> Result<(), CodecError>

Appends an ordered group member after admitting its group and slot.

Source

pub fn insert_btree_group_set<K: Ord, V: Ord>( &self, groups: &mut BTreeMap<K, BTreeSet<V>>, key: K, value: V, group_operation: &'static str, item_operation: &'static str, ) -> Result<(), CodecError>

Inserts an ordered group member after admitting its group and value.

Source

pub fn resize_retained_bytes( &self, values: &mut Vec<u8>, length: usize, fill: u8, operation: &'static str, ) -> Result<(), CodecError>

Resizes a byte buffer after admitting additional retained storage.

Source

pub fn extend_retained_bytes( &self, target: &mut Vec<u8>, source: &[u8], operation: &'static str, ) -> Result<(), CodecError>

Extends retained bytes after charging both their slots and storage.

Source

pub fn temporary_vec<T>( &self, count: usize, operation: &'static str, ) -> Result<(Vec<T>, ScopedReservation<'_>), CodecError>

Reserves a scoped vector and returns its live reservation.

Source

pub fn temporary_set<T: Eq + Hash>( &self, count: usize, operation: &'static str, ) -> Result<(HashSet<T>, ScopedReservation<'_>), CodecError>

Reserves a scoped hash set and returns its live reservation.

Source

pub fn temporary_set_limit<T: Eq + Hash>( &self, count: usize, operation: &'static str, ) -> Result<(HashSet<T>, ScopedReservation<'_>), ResourceLimit>

Reserves a scoped hash set with a typed resource error.

Source

pub fn collect_scoped_string_set<'text>( &self, count: usize, values: impl IntoIterator<Item = &'text str>, operation: &'static str, ) -> Result<(HashSet<&'text str>, ScopedReservation<'_>), CodecError>

Collects a borrowed string index with scoped hash storage.

Source

pub fn collect_scoped_string_map<'text, V>( &self, count: usize, values: impl IntoIterator<Item = (&'text str, V)>, operation: &'static str, ) -> Result<(HashMap<&'text str, V>, ScopedReservation<'_>), CodecError>

Collects a borrowed string-keyed index with scoped hash storage.

Source

pub fn temporary_queue<T>( &self, count: usize, operation: &'static str, ) -> Result<(VecDeque<T>, ScopedReservation<'_>), CodecError>

Reserves a scoped deque and returns its live reservation.

Source

pub fn charge_formatted_retained( &self, args: Arguments<'_>, operation: &'static str, ) -> Result<(), CodecError>

Charges retained text produced by a later aggregate materialization.

Source

pub fn format_retained( &self, args: Arguments<'_>, operation: &'static str, ) -> Result<String, CodecError>

Formats a retained string after charging its exact byte count.

Source

pub fn format_scoped( &self, args: Arguments<'_>, operation: &'static str, ) -> Result<(String, ScopedReservation<'_>), CodecError>

Formats a temporary string and returns its live reservation.

Source

pub fn append_retained( &self, output: &mut String, suffix: &str, operation: &'static str, ) -> Result<(), CodecError>

Appends retained text after charging its bytes.

Source

pub fn append_formatted_retained( &self, output: &mut String, args: Arguments<'_>, operation: &'static str, ) -> Result<(), CodecError>

Appends formatted text after admitting its exact retained byte count.

Source

pub fn retained_string( &self, length: usize, operation: &'static str, ) -> Result<String, CodecError>

Reserves an empty retained string after charging its declared length.

Source

pub fn retained_suffix( &self, value: &str, suffix: &str, operation: &'static str, ) -> Result<String, CodecError>

Copies retained text and appends a retained suffix.

Source

pub fn copy_retained_strings( &self, values: &[String], operation: &'static str, ) -> Result<Vec<String>, CodecError>

Copies a slice of retained strings after charging collection slots.

Source

pub fn join_retained<S: AsRef<str>>( &self, parts: &[S], separator: &str, operation: &'static str, ) -> Result<String, CodecError>

Joins retained text after measuring and charging the exact byte count.

Source

pub fn join_display_retained<T: Display>( &self, values: impl IntoIterator<Item = T>, separator: &str, operation: &'static str, ) -> Result<String, CodecError>

Joins displayed values while charging each retained text fragment.

Source§

impl<'a> DecodeContext<'a>

Source

pub fn new( arena: &'a DecodeArena, policy: &DecodePolicy, container_only: bool, ) -> Self

Creates one session before input acquisition and detection.

Source

pub fn for_loaded_input( arena: &'a DecodeArena, policy: &DecodePolicy, input_bytes: u64, ) -> Result<Self, CodecError>

Starts post-decode processing with the measured byte length of an already loaded input. This admits the input-proportional allowances without keeping another copy of the source bytes. Format-declared counts must not be used as the input length.

Source

pub fn read_root( reader: &mut dyn ReadSeek, arena: &'a DecodeArena, policy: &DecodePolicy, container_only: bool, ) -> Result<(Self, View<'a>), CodecError>

Reads the root input under max_input_bytes, copies it into the arena, registers the root space, establishes input-proportional allowances, and returns the context and root view.

Source

pub fn from_root_bytes( bytes: &'a [u8], arena: &'a DecodeArena, policy: &DecodePolicy, ) -> Result<(Self, View<'a>), CodecError>

Builds a context over caller-owned root bytes, for fuzz targets and tests. The arena still backs any expansions produced during decode.

Source

pub fn from_root_bytes_limit( bytes: &'a [u8], arena: &'a DecodeArena, policy: &DecodePolicy, ) -> Result<(Self, View<'a>), ResourceLimit>

Builds a root context with a resource-only refusal channel.

Source

pub fn policy(&self) -> &DecodePolicy

Returns the decode policy in force.

Source

pub fn container_only(&self) -> bool

Returns whether the caller requested container-only decoding.

Source

pub fn reserve_scoped( &self, bytes: u64, operation: &'static str, ) -> Result<ScopedReservation<'_>, CodecError>

Reserves bytes held by a temporary materialization.

Source

pub fn try_materialized<T>( &self, bytes: u64, operation: &'static str, allocate: impl FnOnce() -> Result<T, TryReserveError>, ) -> Result<(ScopedReservation<'_>, T), CodecError>

Admits a temporary byte allocation and holds its reservation until released.

Source

pub fn reserve_scoped_limit( &self, bytes: u64, operation: &'static str, ) -> Result<ScopedReservation<'_>, ResourceLimit>

Reserves temporary bytes and returns the typed resource refusal.

Source

pub fn charge_retained( &self, bytes: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges bytes retained for the remainder of this session.

Source

pub fn charge_retained_limit( &self, bytes: u64, operation: &'static str, ) -> Result<(), ResourceLimit>

Charge retained storage with a resource-only refusal channel.

Source

pub fn with_scoped_storage<T, E: From<CodecError>>( &self, operation: &'static str, build: impl FnOnce() -> Result<T, E>, ) -> Result<(T, ScopedReservation<'_>), E>

Charges storage created by the closure as temporary until its reservation is dropped.

Source

pub fn copy_retained_text_limit( &self, text: &str, operation: &'static str, ) -> Result<String, ResourceLimit>

Copies admitted text into retained storage with a typed resource refusal.

Source

pub fn copy_retained_text( &self, text: &str, operation: &'static str, ) -> Result<String, CodecError>

Copies admitted text into session-retained storage.

Source

pub fn copy_retained( &self, bytes: &[u8], operation: &'static str, ) -> Result<Vec<u8>, CodecError>

Copies bytes into session-retained storage after charging and reserving safely.

Source

pub fn try_reserve_retained_text( &self, text: &mut String, additional: usize, operation: &'static str, ) -> Result<(), CodecError>

Reserves growth of a session-retained string after charging its bytes.

Source

pub fn copy_retained_lossy_utf8( &self, value: &[u8], operation: &'static str, ) -> Result<String, CodecError>

Copies source bytes as UTF-8 with replacement characters after charging the exact length of the retained text.

Source

pub fn alloc_filled<T: Clone>( &self, count: usize, value: T, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Allocates count copies of value after charging slots, backing bytes and fill work, with fallible storage admission.

Prefer this over vec![value; parsed_count] for attacker-influenced sizes.

Source

pub fn alloc_filled_admitted<T: Clone>( &self, count: usize, value: T, operation: &'static str, ) -> Result<Vec<T>, CodecError>

Allocates count copies of value whose backing bytes the caller has already admitted, as retained or scoped storage, under its own operation.

Charges collection items and fill work only, so the bytes are admitted exactly once. The caller must have admitted count * size_of::<T>() bytes before this call.

Source

pub fn charge_entities( &self, count: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges admitted entities.

Source

pub fn admit_entities( &self, current: u64, admitted: &mut u64, operation: &'static str, ) -> Result<(), CodecError>

Charges entities newly present since admitted, then advances admitted.

Codecs call this at admission boundaries so max_entities refuses further work instead of only reporting after a finished IR is built.

Source

pub fn charge_collection_items( &self, count: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges admitted collection items.

Source

pub fn try_collection<T>( &self, count: usize, operation: &'static str, allocate: impl FnOnce() -> Result<T, TryReserveError>, ) -> Result<T, CodecError>

Charges collection items before a fallible collection allocation.

Source

pub fn charge_collection_items_limit( &self, count: u64, operation: &'static str, ) -> Result<(), ResourceLimit>

Charges collection items and returns the typed refusal for resource-only callers.

Source

pub fn enter_nested( &self, operation: &'static str, ) -> Result<DepthGuard<'_>, CodecError>

Enters one recursive nesting level until the returned guard is dropped.

Source

pub fn enter_nested_limit( &self, operation: &'static str, ) -> Result<DepthGuard<'_>, ResourceLimit>

Enters one nesting level with a resource-only refusal.

Source

pub fn charge_work( &self, units: u64, operation: &'static str, ) -> Result<(), CodecError>

Charges session-global algorithm work, fusing on refusal.

Source

pub fn charge_work_limit( &self, units: u64, operation: &'static str, ) -> Result<(), ResourceLimit>

Charges work with a resource-only refusal channel.

Source

pub fn stable_sort_by<T>( &self, values: &mut [T], compare: impl FnMut(&T, &T) -> Ordering, key_bytes: impl Fn(&T) -> usize, operation: &'static str, ) -> Result<(), CodecError>

Sort admitted values stably using fallible index scratch.

key_bytes states the key bytes a comparison can read from each value. Equal values retain input order. Values move in place without cloning children.

Source

pub fn resource_refusal(&self) -> Option<ResourceLimit>

Returns the resource refusal that has fused this decode session.

Source

pub fn refuse_codec_limit( &self, operation: &'static str, limit: u64, requested: u64, ) -> CodecError

Permanently refuses a codec-local resource request.

Source

pub fn work_budget(&self, local_limit: u64) -> WorkBudget<'_>

Creates a local work slice that also draws from the session allowance.

Source

pub fn begin_expand( &self, spec: ExpandSpec, ) -> Result<ExpandWriter<'_, 'a>, CodecError>

Begins an expansion whose output is charged incrementally and becomes available only after successful finalization.

Source

pub fn concat_views(&self, inputs: &[View<'_>]) -> Result<View<'a>, CodecError>

Copies several input extents into one derived view.

Source

pub fn concat_retained( &self, inputs: &[Vec<u8>], operation: &'static str, ) -> Result<Vec<u8>, CodecError>

Concatenates owned chunks into one retained buffer without an arena copy.

Source

pub fn register_slice<'v>( &self, parent: View<'v>, range: ByteRange, ) -> Result<View<'v>, CodecError>

Registers a stored (uncompressed) child range as a space that borrows the parent bytes without copying.

range is expressed in the parent view’s own space coordinates and must lie within the parent window; a range that escapes the parent is refused here, at the request site, exactly as View::child refuses. No bytes are copied. It is the archive-entry counterpart of DecodeContext::begin_expand — stored ZIP entries take this path, compressed ones take the expander. Registration still refuses on a fused context so a stored entry cannot be admitted after a refusal.

Source

pub fn finish_session(self) -> Result<(), CodecError>

Closes a decode or inspection session, returning a fused resource error even when codec code swallowed the charge that caused it.

Source§

impl DecodeContext<'_>

Source

pub fn inflate_probe( &self, source: View<'_>, cap: usize, zlib: bool, ) -> Result<Option<(Vec<u8>, ScopedReservation<'_>)>, CodecError>

Inflates one raw or zlib member up to cap. An oversized or malformed member supplies no evidence. Resource refusals remain typed.

Source§

impl DecodeContext<'_>

Source

pub fn read_input_prefix( &self, reader: &mut dyn Read, length: usize, ) -> Result<Vec<u8>, CodecError>

Reads at most length bytes and admits each copied byte before growth. Input storage is governed by the input-byte dimension.

Source

pub fn extend_input_prefix( &self, reader: &mut dyn Read, bytes: &mut Vec<u8>, length: usize, ) -> Result<(), CodecError>

Extends admitted input storage up to a total bounded length.

Source

pub fn complete_input( &self, reader: &mut dyn Read, bytes: &mut Vec<u8>, ) -> Result<(), CodecError>

Acquires the remaining input without reading or charging the prefix twice.

Source

pub fn refuse_input_limit( &self, additional: u64, operation: &'static str, ) -> CodecError

Raises a typed input-byte refusal without changing its dimension.

Source§

impl DecodeContext<'_>

Source

pub fn sort_unstable_by<T>( &self, values: &mut [T], compare: impl FnMut(&T, &T) -> Ordering, key_bytes: impl Fn(&T) -> usize, operation: &'static str, ) -> Result<(), CodecError>

Sorts admitted values in place without allocating scratch.

key_bytes states the external bytes a comparison can read from each value.

Source§

impl DecodeContext<'_>

Source

pub fn parse_xml<'input>( &self, text: &'input str, operation: &'static str, ) -> Result<AdmittedXml<'input, '_>, CodecError>

Admits roxmltree 0.21.1 storage before parsing with DTD disabled. For N = 2 * ‘<’ + 2, A = ‘=’ and S = distinct raw namespace bindings + 1, growing vectors reserve 2 * count + their minimum capacity. Storage covers nodes, permanent and temporary attributes (minimum 16), namespace records and sorted indices. Namespace tree-order slots sum visible bindings at elements with declarations; other elements reuse their parent’s range. Index storage includes old and new allocations during vector growth. Node-sized scratch includes awaiting-subtree IDs, parent prefixes and text Cows. Eight input lengths cover normalization buffers, joined text, shared strings and transient copies; 32 bytes per string cover Arc headers. The fixed 1024 bytes cover initial scratch capacities and parser state. Work covers the scan, parser scans and quadratic attribute/namespace comparisons, including string comparisons and namespace insertion. Attribute comparisons use each tag’s name bytes and attribute count. Namespace work covers prefix lookups, expanded attribute names, inheritance only at tags with declarations, and sorted namespace insertion. Text outside tags and ordinary attribute values pay only scanning/normalization work. Temporary node-ID, prefix, text, attribute and namespace-index slots are admitted separately.

Source§

impl DecodeContext<'_>

Source

pub fn parse_json_value( &self, text: &str, operation: &'static str, ) -> Result<(Value, ScopedReservation<'_>), CodecError>

Parses a value tree under collection, work, scoped storage and depth admission. Keep the returned reservation alive with the returned Value. serde_json’s own 128-level recursion ceiling also applies.

Source

pub fn parse_json<T: DeserializeOwned>( &self, text: &str, operation: &'static str, ) -> Result<T, CodecError>

Parses types with derived Deserialize: structs, enums, vectors, maps, strings and scalars. Custom allocating deserializers are outside this bound. The retained typed result is admitted as twice the value-tree storage plus size_of::<T>(); conversion charges one work unit per value. Source validation with the derived deserializer preserves duplicate-field errors that Value maps erase. Its temporary result has a separate scoped admission of twice the tree bytes plus size_of::<T>(); scan and conversion work are charged before validation. Typed trees use ordinary map members rather than Value’s private raw-value carrier. The admission remains live.

Source§

impl DecodeContext<'_>

Source

pub fn unique_index<K: Eq + Hash, V>( &self, entries: impl IntoIterator<Item = (K, V)>, key_work: impl Fn(&K) -> Result<u64, CodecError>, operation: &'static str, ) -> Result<(HashMap<K, Option<V>>, ScopedReservation<'_>), CodecError>

Builds a scoped table. Repeated keys become tombstones until the final in-place removal, so a third occurrence cannot restore a duplicate. Surviving values are Some; no second table is allocated.

Source§

impl DecodeContext<'_>

Source

pub fn utf16le_text( &self, bytes: &[u8], units: usize, trim_nul: bool, operation: &'static str, ) -> Result<String, CodecError>

Validates a UTF-16LE window and retains its exact UTF-8 text size.

Source

pub fn utf16le_scoped_text<'ctx>( &'ctx self, bytes: &[u8], units: usize, trim_nul: bool, operation: &'static str, ) -> Result<(String, ScopedReservation<'ctx>), CodecError>

Decodes strict UTF-16LE into storage held by a scoped reservation.

Source

pub fn utf16le_lossy_text( &self, bytes: &[u8], units: usize, trim_nul: bool, operation: &'static str, ) -> Result<String, CodecError>

Retains exact UTF-8 text while replacing unpaired surrogates with U+FFFD.

Source

pub fn utf16le_lossy_scoped_text<'ctx>( &'ctx self, bytes: &[u8], units: usize, trim_nul: bool, operation: &'static str, ) -> Result<(String, ScopedReservation<'ctx>), CodecError>

Holds replacement UTF-8 text in an exact-byte scoped reservation.

Source§

impl<'input> DecodeContext<'input>

Source

pub fn open_zstd<'ctx>( &'ctx self, source: View<'input>, ) -> Result<ZstdDecoder<'ctx, 'input>, CodecError>

Inspects all frame windows before allocating a decoder. The largest frame window must fit the materialized-byte and per-expansion ceilings.

Trait Implementations§

Source§

impl<'a> Debug for DecodeContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for DecodeContext<'a>

§

impl<'a> !RefUnwindSafe for DecodeContext<'a>

§

impl<'a> !Send for DecodeContext<'a>

§

impl<'a> !Sync for DecodeContext<'a>

§

impl<'a> !UnwindSafe for DecodeContext<'a>

§

impl<'a> Unpin for DecodeContext<'a>

§

impl<'a> UnsafeUnpin for DecodeContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.