Skip to main content

BlockHeader

Struct BlockHeader 

Source
pub struct BlockHeader {
    pub header_size: u16,
    pub flags: u32,
    pub compression: [u8; 4],
    pub allocated_size: u64,
    pub used_size: u64,
    pub data_size: u64,
    pub checksum: [u8; 16],
}
Expand description

A decoded block header.

Fields§

§header_size: u16

The header size as recorded in the file, excluding the magic and this field. Preserved so a re-emitted block keeps any padding it had.

§flags: u32

Flag bits; see FLAG_STREAMED.

§compression: [u8; 4]

The compression name, \0-padded to four bytes in the file.

§allocated_size: u64

Space reserved for the block’s data, excluding the header.

§used_size: u64

Bytes actually used on disk, excluding the header.

§data_size: u64

Size of the data once decoded. Equal to used_size when uncompressed.

§checksum: [u8; 16]

MD5 of the used data. All-zero means “do not verify”.

Implementations§

Source§

impl BlockHeader

Source

pub fn parse(buf: &[u8]) -> Result<(Self, usize)>

Decode a header from a buffer positioned at the block magic.

Returns the header and the number of bytes it occupied, so the caller can find the data that follows.

Source

pub fn write(&self, out: &mut Vec<u8>)

Encode the header, including magic, into out.

Any header_size beyond the fields is written as zero padding, so a block that was read with an enlarged header re-emits at the same size.

Source

pub fn on_disk_size(&self) -> usize

The number of bytes this header occupies in the file.

Source

pub fn is_streamed(&self) -> bool

Whether the streamed flag is set.

Source

pub fn compression_name(&self) -> &str

The compression name with its \0 padding removed.

An empty name means the block is uncompressed.

Source

pub fn set_compression(&mut self, name: &str) -> Result<()>

Set the compression name, which must fit in four bytes.

Source

pub fn has_checksum(&self) -> bool

Whether a checksum is recorded. All-zero means “do not verify”.

Trait Implementations§

Source§

impl Clone for BlockHeader

Source§

fn clone(&self) -> BlockHeader

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 Debug for BlockHeader

Source§

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

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

impl Default for BlockHeader

Source§

fn default() -> Self

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

impl Eq for BlockHeader

Source§

impl PartialEq for BlockHeader

Source§

fn eq(&self, other: &BlockHeader) -> 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 BlockHeader

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.