pub struct DictionaryHandle { /* private fields */ }Expand description
Shared pre-parsed dictionary handle for repeated decoding.
Uses Arc on targets with atomics and falls back to Rc otherwise.
Implementations§
Source§impl DictionaryHandle
impl DictionaryHandle
Sourcepub fn from_dictionary(dict: Dictionary) -> Self
pub fn from_dictionary(dict: Dictionary) -> Self
Wrap an already-parsed dictionary in a shared handle.
Sourcepub fn heap_size(&self) -> usize
pub fn heap_size(&self) -> usize
Heap bytes the handle keeps alive: the shared allocation the dictionary lives in and the dictionary’s own content and tables. Clones share all of it.
§Examples
use structured_zstd::decoding::{Dictionary, DictionaryHandle};
let handle = DictionaryHandle::from_dictionary(
Dictionary::from_raw_content(0, vec![7u8; 1024]).unwrap(),
);
assert!(handle.heap_size() > handle.as_dict().heap_bytes());
assert!(handle.heap_size() <= DictionaryHandle::max_heap_size(1024));Sourcepub fn max_heap_size(content_len: usize) -> usize
pub fn max_heap_size(content_len: usize) -> usize
Most Self::heap_size a handle over a dictionary of content_len
bytes can report, serialized header included, for budgeting before
the dictionary is parsed.
Sourcepub fn exclusive_heap_size<'a, I>(handles: I) -> usize
pub fn exclusive_heap_size<'a, I>(handles: I) -> usize
Heap bytes that handles alone keep alive: each distinct dictionary
among them once, and only when no handle outside them shares it. For an
owner holding several handles, such as a decoding context that keeps a
dictionary attached and its decoder keeps the last frame’s.
§Examples
use structured_zstd::decoding::{Dictionary, DictionaryHandle};
let handle = DictionaryHandle::from_dictionary(
Dictionary::from_raw_content(0, vec![7u8; 64]).unwrap(),
);
let copy = handle.clone();
// Both handles are in the set: counted once.
assert_eq!(
DictionaryHandle::exclusive_heap_size([&handle, ©]),
handle.heap_size()
);
// `copy` is held elsewhere: nothing is this set's alone.
assert_eq!(DictionaryHandle::exclusive_heap_size([&handle]), 0);Sourcepub fn decode_dict(raw: &[u8]) -> Result<Self, DictionaryDecodeError>
pub fn decode_dict(raw: &[u8]) -> Result<Self, DictionaryDecodeError>
Parse a serialized dictionary and return a reusable shared handle.
With the legacy feature a dictionary in the v0.5 or v0.6 layout is
taken too, whole as content with no ID: frames of its format parse
its tables from it, as libzstd’s ZSTD_decompress_usingDict does.
Sourcepub fn from_serialized_or_raw_content(
raw: &[u8],
) -> Result<Self, DictionaryDecodeError>
pub fn from_serialized_or_raw_content( raw: &[u8], ) -> Result<Self, DictionaryDecodeError>
Load whichever kind of dictionary raw holds, as ZSTD_createDDict
does: a serialized dictionary, or raw
content. See
Dictionary::from_serialized_or_raw_content.