Skip to main content

DecoderBuffer

Struct DecoderBuffer 

Source
pub struct DecoderBuffer<'a> { /* private fields */ }
Available on crate feature 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>

Source

pub fn new(data: &'a [u8]) -> Self

Creates a new DecoderBuffer from a byte slice.

Source

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());
Source

pub fn set_version(&mut self, major: u8, minor: u8)

Sets the Draco bitstream version for version-dependent decoding.

Source

pub fn version_major(&self) -> u8

Returns the major version number.

Source

pub fn version_minor(&self) -> u8

Returns the minor version number.

Source

pub fn bitstream_version(&self) -> u16

Returns the packed 0xMMmm bitstream version for ordered comparisons.

Source

pub fn position(&self) -> usize

Returns the current read position in bytes.

Source

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
Source

pub fn remaining_size(&self) -> usize

Returns the number of bytes remaining in the buffer.

Source

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.

Source

pub fn peek_bytes(&self, len: usize) -> Vec<u8> ⓘ

Peeks at the next len bytes without advancing the position.

Source

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.

Source

pub fn end_bit_decoding(&mut self)

Ends bit-level decoding mode and advances the byte position.

Source

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.

Source

pub fn decode_least_significant_bits32_fast( &mut self, nbits: u32, ) -> Result<u32, DracoError>

Optimized version for hot paths - reads multiple bytes at once.

Source

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
Source

pub fn decode_u8(&mut self) -> Result<u8, DracoError>

Decodes a single byte.

Source

pub fn decode_u16(&mut self) -> Result<u16, DracoError>

Decodes a little-endian u16.

Source

pub fn decode_u32(&mut self) -> Result<u32, DracoError>

Decodes a little-endian u32.

Source

pub fn decode_u64(&mut self) -> Result<u64, DracoError>

Decodes a little-endian u64.

Source

pub fn decode_f32(&mut self) -> Result<f32, DracoError>

Decodes a little-endian f32.

Source

pub fn decode_f64(&mut self) -> Result<f64, DracoError>

Decodes a little-endian f64.

Source

pub fn decode_string(&mut self) -> Result<String, DracoError>

Decodes a null-terminated string.

Source

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.

Source

pub fn decode_varint(&mut self) -> Result<u64, DracoError>

Decodes a variable-length unsigned integer (varint).

Source

pub fn decode_varint_signed_i32(&mut self) -> Result<i32, DracoError>

Decodes a Draco-compatible signed varint.

Uses unsigned varint encoding with ConvertSymbolToSignedInt transformation.

Source

pub fn remaining_data(&self) -> &'a [u8] ⓘ

Returns a slice of the remaining data without advancing.

Source

pub fn advance(&mut self, n: usize)

Advances the position by n bytes without reading.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a> Freeze for DecoderBuffer<'a>

§

impl<'a> RefUnwindSafe for DecoderBuffer<'a>

§

impl<'a> Send for DecoderBuffer<'a>

§

impl<'a> Sync for DecoderBuffer<'a>

§

impl<'a> Unpin for DecoderBuffer<'a>

§

impl<'a> UnsafeUnpin for DecoderBuffer<'a>

§

impl<'a> UnwindSafe for DecoderBuffer<'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.