pub struct DecoderBuffer<'a> { /* private fields */ }decoder only.Expand description
Input buffer for reading compressed Draco data.
DecoderBuffer provides sequential byte and bit-level access to compressed data.
It supports both byte-aligned reads (integers, floats, strings) and bit-level
reads for entropy-coded data.
§Example
use draco_core::DecoderBuffer;
let data = &[0x44, 0x52, 0x41, 0x43, 0x4F]; // "DRACO" header
let mut buffer = DecoderBuffer::new(data);
assert_eq!(buffer.decode_u8().unwrap(), 0x44);
assert_eq!(buffer.remaining_size(), 4);Implementations§
Source§impl<'a> DecoderBuffer<'a>
impl<'a> DecoderBuffer<'a>
Sourcepub fn with_limits(self, limits: DecodeLimits) -> Self
pub fn with_limits(self, limits: DecodeLimits) -> Self
Decodes under limits rather than under
DecodeLimits::default.
use draco_core::{DecodeLimits, DecoderBuffer};
let stream = [0u8; 0];
let buffer = DecoderBuffer::new(&stream).with_limits(DecodeLimits::permissive());Sourcepub fn set_version(&mut self, major: u8, minor: u8)
pub fn set_version(&mut self, major: u8, minor: u8)
Sets the Draco bitstream version for version-dependent decoding.
Sourcepub fn version_major(&self) -> u8
pub fn version_major(&self) -> u8
Returns the major version number.
Sourcepub fn version_minor(&self) -> u8
pub fn version_minor(&self) -> u8
Returns the minor version number.
Sourcepub fn bitstream_version(&self) -> u16
pub fn bitstream_version(&self) -> u16
Returns the packed 0xMMmm bitstream version for ordered comparisons.
Sourcepub fn set_position(&mut self, pos: usize) -> Result<(), DracoError>
pub fn set_position(&mut self, pos: usize) -> Result<(), DracoError>
Sets the read position.
§Errors
Returns an ErrorKind::Buffer error if:
- Bit decoding is currently active
- Position is beyond the buffer length
Sourcepub fn remaining_size(&self) -> usize
pub fn remaining_size(&self) -> usize
Returns the number of bytes remaining in the buffer.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the total size of the buffer, read or not.
The decode allocation budget measures against this rather than against
remaining_size: an attribute decoded last has
a legitimately tiny payload left in front of it while its value count is
no smaller than the first attribute’s, so charging it only for what
follows would refuse valid streams.
Sourcepub fn peek_bytes(&self, len: usize) -> Vec<u8> ⓘ
pub fn peek_bytes(&self, len: usize) -> Vec<u8> ⓘ
Peeks at the next len bytes without advancing the position.
Sourcepub fn start_bit_decoding(
&mut self,
decode_size: bool,
) -> Result<u64, DracoError>
pub fn start_bit_decoding( &mut self, decode_size: bool, ) -> Result<u64, DracoError>
Starts bit-level decoding mode.
When decode_size is true, reads the bit sequence size from the buffer.
Returns the size in bytes.
§Errors
Returns an ErrorKind::Buffer error if bit decoding is already active.
Sourcepub fn end_bit_decoding(&mut self)
pub fn end_bit_decoding(&mut self)
Ends bit-level decoding mode and advances the byte position.
Sourcepub fn decode_least_significant_bits32(
&mut self,
nbits: u32,
) -> Result<u32, DracoError>
pub fn decode_least_significant_bits32( &mut self, nbits: u32, ) -> Result<u32, DracoError>
Decodes nbits least significant bits as a u32.
§Errors
Returns an ErrorKind::Buffer error if bit decoding is not active or end of stream.
Sourcepub fn decode_least_significant_bits32_fast(
&mut self,
nbits: u32,
) -> Result<u32, DracoError>
pub fn decode_least_significant_bits32_fast( &mut self, nbits: u32, ) -> Result<u32, DracoError>
Optimized version for hot paths - reads multiple bytes at once.
Sourcepub fn decode<T: Copy + Pod>(&mut self) -> Result<T, DracoError>
pub fn decode<T: Copy + Pod>(&mut self) -> Result<T, DracoError>
Decodes a value of type T using raw memory copy.
§Errors
Returns an ErrorKind::Buffer error if:
- Bit decoding is active
- Not enough bytes remaining
Sourcepub fn decode_u8(&mut self) -> Result<u8, DracoError>
pub fn decode_u8(&mut self) -> Result<u8, DracoError>
Decodes a single byte.
Sourcepub fn decode_u16(&mut self) -> Result<u16, DracoError>
pub fn decode_u16(&mut self) -> Result<u16, DracoError>
Decodes a little-endian u16.
Sourcepub fn decode_u32(&mut self) -> Result<u32, DracoError>
pub fn decode_u32(&mut self) -> Result<u32, DracoError>
Decodes a little-endian u32.
Sourcepub fn decode_u64(&mut self) -> Result<u64, DracoError>
pub fn decode_u64(&mut self) -> Result<u64, DracoError>
Decodes a little-endian u64.
Sourcepub fn decode_f32(&mut self) -> Result<f32, DracoError>
pub fn decode_f32(&mut self) -> Result<f32, DracoError>
Decodes a little-endian f32.
Sourcepub fn decode_f64(&mut self) -> Result<f64, DracoError>
pub fn decode_f64(&mut self) -> Result<f64, DracoError>
Decodes a little-endian f64.
Sourcepub fn decode_string(&mut self) -> Result<String, DracoError>
pub fn decode_string(&mut self) -> Result<String, DracoError>
Decodes a null-terminated string.
Sourcepub fn decode_bytes(&mut self, out: &mut [u8]) -> Result<(), DracoError>
pub fn decode_bytes(&mut self, out: &mut [u8]) -> Result<(), DracoError>
Decodes bytes into the provided buffer.
§Errors
Returns an ErrorKind::Buffer error if not enough bytes remaining.
Sourcepub fn decode_varint(&mut self) -> Result<u64, DracoError>
pub fn decode_varint(&mut self) -> Result<u64, DracoError>
Decodes a variable-length unsigned integer (varint).
Sourcepub fn decode_varint_signed_i32(&mut self) -> Result<i32, DracoError>
pub fn decode_varint_signed_i32(&mut self) -> Result<i32, DracoError>
Decodes a Draco-compatible signed varint.
Uses unsigned varint encoding with ConvertSymbolToSignedInt transformation.
Sourcepub fn remaining_data(&self) -> &'a [u8] ⓘ
pub fn remaining_data(&self) -> &'a [u8] ⓘ
Returns a slice of the remaining data without advancing.
Sourcepub fn try_advance(&mut self, n: usize) -> Result<(), DracoError>
pub fn try_advance(&mut self, n: usize) -> Result<(), DracoError>
Advances the position by n bytes without reading.
§Errors
Returns an ErrorKind::Buffer error if the requested advance would move
beyond the end of the input buffer.
Sourcepub fn decode_slice(&mut self, size: usize) -> Result<&'a [u8], DracoError>
pub fn decode_slice(&mut self, size: usize) -> Result<&'a [u8], DracoError>
Decodes and returns a slice of the specified size.
§Errors
Returns an ErrorKind::Buffer error if not enough bytes remaining.