pub struct Decoder<'a> { /* private fields */ }Expand description
Decoder that reads Crous binary data and produces values.
§Example
use crous_core::{Encoder, Decoder, Value};
let mut enc = Encoder::new();
enc.encode_value(&Value::Str("hello".into())).unwrap();
let bytes = enc.finish().unwrap();
let mut dec = Decoder::new(&bytes);
let val = dec.decode_next().unwrap();
assert_eq!(val.to_owned_value(), Value::Str("hello".into()));Implementations§
Source§impl<'a> Decoder<'a>
impl<'a> Decoder<'a>
Sourcepub fn with_limits(data: &'a [u8], limits: Limits) -> Self
pub fn with_limits(data: &'a [u8], limits: Limits) -> Self
Create a decoder with custom limits.
Sourcepub fn skip_value_at(&mut self, block_end: usize) -> Result<()>
pub fn skip_value_at(&mut self, block_end: usize) -> Result<()>
Skip a value at the current block_pos without allocating. Used for forward-compatible skipping of unknown fields.
All branches are bounds-checked against block_end and enforce
the decoder’s Limits to prevent denial-of-service via crafted
counts or deeply nested structures.
Sourcepub fn header(&mut self) -> Result<&FileHeader>
pub fn header(&mut self) -> Result<&FileHeader>
Get the parsed file header.
Sourcepub fn decode_next(&mut self) -> Result<CrousValue<'a>>
pub fn decode_next(&mut self) -> Result<CrousValue<'a>>
Decode the next value from the input. Automatically reads blocks as needed.
Returns a zero-copy CrousValue that borrows from the input data.
Note: Zero-copy decoding requires uncompressed blocks. If a compressed
block is encountered, this method returns DecompressionError because
borrowed CrousValue<'a> cannot reference decompressed (owned) data.
Use decode_all_owned() or decode_next_owned() for compressed data.
Sourcepub fn decode_next_owned(&mut self) -> Result<Value>
pub fn decode_next_owned(&mut self) -> Result<Value>
Decode the next value as an owned Value.
Unlike decode_next(), this works transparently with both compressed
and uncompressed blocks.
Sourcepub fn decode_all(&mut self) -> Result<Vec<CrousValue<'a>>>
pub fn decode_all(&mut self) -> Result<Vec<CrousValue<'a>>>
Decode all remaining values from the input.
Sourcepub fn decode_all_owned(&mut self) -> Result<Vec<Value>>
pub fn decode_all_owned(&mut self) -> Result<Vec<Value>>
Decode all remaining values as owned Values.
This works transparently with both compressed and uncompressed blocks.
Sourcepub fn memory_used(&self) -> usize
pub fn memory_used(&self) -> usize
Cumulative bytes tracked as allocated during this decode session.