Skip to main content

DecodeLimits

Struct DecodeLimits 

Source
#[non_exhaustive]
pub struct DecodeLimits { pub max_points: u64, pub max_faces: u64, pub max_decoded_bytes: u64, }
Expand description

Ceilings on one decode, applied to what the stream reconstructs.

Every field is a hard ceiling: exceeding one fails the decode with ErrorKind::LimitExceeded, which a caller can tell apart from ErrorKind::AllocationExceedsInput – its own policy refusing a large file, rather than the decoder refusing a malformed one.

The counts are the decoded ones, not the ones a source file was authored with. Draco splits a point wherever an attribute seam runs through it, and the growth is real: measured across ten assets it runs from zero to 7.7%, and one exporter’s 65,532-point primitive decodes to 76,742. A ceiling derived from what an exporter writes would refuse files that follow its own convention.

Install with DecoderBuffer::with_limits.

use draco_core::{DecodeLimits, DecoderBuffer};

let stream = [0u8; 0];
let buffer = DecoderBuffer::new(&stream)
    .with_limits(DecodeLimits::default().with_max_points(1_000_000));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§max_points: u64

Largest accepted decoded point count.

§max_faces: u64

Largest accepted decoded face count.

§max_decoded_bytes: u64

Largest accepted total size of decoded attribute values, in bytes.

This is the one that bounds memory. The other two are proxies whose relationship to bytes the attribute set moves around: of two measured assets, the one with a third fewer points held twice the bytes per primitive, because it carried tangents and five texture-coordinate sets against a position and a normal.

Implementations§

Source§

impl DecodeLimits

Source

pub fn permissive() -> Self

No ceiling at all, which is what this crate did before the type existed.

For a caller that decodes trusted local input and would rather have a scan loaded whole than a refusal.

Source

pub fn fuzzing() -> Self

Tight ceilings for fuzzing, so a reported allocation failure is a real bug rather than the fuzzer feeding a legitimately huge count.

Source§

impl DecodeLimits

Source

pub fn with_max_points(self, value: u64) -> Self

Source

pub fn with_max_faces(self, value: u64) -> Self

Source

pub fn with_max_decoded_bytes(self, value: u64) -> Self

Trait Implementations§

Source§

impl Clone for DecodeLimits

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DecodeLimits

Source§

impl Debug for DecodeLimits

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for DecodeLimits

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DecodeLimits

Source§

impl PartialEq for DecodeLimits

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecodeLimits

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.