Skip to main content

Container

Struct Container 

Source
pub struct Container<'a> { /* private fields */ }
Expand description

A parsed container, borrowing the bytes it was parsed from.

Parsing does not copy the payload and does not read it. A container of a hundred gigabytes parses in the time it takes to hash a footer, and the sections are read when somebody asks for them.

Implementations§

Source§

impl<'a> Container<'a>

Source

pub fn parse(bytes: &'a [u8]) -> Result<Self>

Parses a container and checks that the footer is the footer that was written.

The root digest covers the header and the footer, so a container that parses has metadata nobody has edited since it was written. Section contents are not read here. Call Container::verify for that, which is the expensive one and is a separate decision.

§Errors

Returns Error describing the first thing that was wrong. It never panics, whatever the input is, and there is a fuzz target that exists to keep that true.

Source

pub fn parse_without_root_digest(bytes: &'a [u8]) -> Result<Self>

Parses a container without checking the root digest.

This exists for the fuzzer. Checking the digest first would mean essentially every generated input is rejected in the trailer, and the parser behind it would never be reached, which is the part that needs the fuzzing. It is public because the fuzz target lives outside this crate, and it is named at length so that nobody reaches for it by accident.

§Errors

The same as Container::parse, minus the digest mismatch.

Source

pub const fn directory(&self) -> &Directory<'a>

The metadata, without the payload.

This is what a host hands on to anything that does not need the bytes, which is most of what sits above this crate.

Source

pub const fn header(&self) -> FileHeader

The format version this container was written at.

Source

pub const fn root_digest(&self) -> Digest

The digest that covers the header and the footer.

Source

pub const fn dataset(&self) -> &Dataset

What the dataset is.

Source

pub const fn schema(&self) -> Option<&Schema<'a>>

The schema, if there is one.

Source

pub const fn decoder(&self) -> Option<&DecoderRef<'a>>

The decoder reference, if there is one.

Source

pub fn sections(&self) -> &[Section]

Every section, in the order the footer listed them.

Source

pub fn section(&self, id: u32) -> Option<&Section>

The section with this id.

Source

pub fn section_bytes(&self, section: &Section) -> &'a [u8]

The bytes of a section.

The bounds were checked during parsing, so this cannot be out of range for a section that came from this container. It takes a &Section rather than an id so that the only way to call it is with one that did.

Source

pub fn decoder_bytes(&self) -> Option<&'a [u8]>

The bytes of the embedded decoder module, if the decoder is embedded and the section it names exists.

Source

pub fn verify(&self) -> Result<()>

Hashes every section and checks it against the footer.

This reads the whole file, so it is a decision rather than something that happens on every open. The honest place for it is once when a dataset arrives and then never again.

§Errors

Returns Error::DigestMismatch naming the first section whose bytes do not hash to what the footer says they should.

Trait Implementations§

Source§

impl<'a> Clone for Container<'a>

Source§

fn clone(&self) -> Container<'a>

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<'a> Debug for Container<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Container<'a>

§

impl<'a> RefUnwindSafe for Container<'a>

§

impl<'a> Send for Container<'a>

§

impl<'a> Sync for Container<'a>

§

impl<'a> Unpin for Container<'a>

§

impl<'a> UnsafeUnpin for Container<'a>

§

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