Skip to main content

XorbObject

Struct XorbObject 

Source
pub struct XorbObject {
    pub info: XorbObjectInfoV1,
    pub info_length: u32,
}
Expand description

XORB: 16MB data block for storing chunks.

Has Info footer, and a set of functions that interact directly with XORB.

Physical layout of this object is as follows: [START OF XORB] <CHUNK 0> <CHUNK 1> <..> XorbObjectInfo length: u32 [END OF XORB]

Fields§

§info: XorbObjectInfoV1

XorbObjectInfo block see [XorbObjectInfo] for details.

§info_length: u32

Length of entire info block.

This is required to be at the end of the XorbObject, so readers can read the final 4 bytes and know the full length of the info block.

Implementations§

Source§

impl XorbObject

Source

pub fn get_info_length<R: Read + Seek>(reader: &mut R) -> Result<u32, CoreError>

Deserializes only the info length field of the footer to tell the user how many bytes make up the info portion of the xorb.

Assumes reader has at least size_of::() bytes, otherwise returns an error.

Source

pub fn deserialize<R: Read + Seek>(reader: &mut R) -> Result<Self, CoreError>

Deserialize the XorbObjectInfo struct, the metadata for this Xorb.

This allows the XorbObject to be partially constructed, allowing for range reads inside the XorbObject.

Source

pub async fn deserialize_async<R: AsyncRead + Unpin>( reader: &mut R, version: u8, ) -> Result<Self, CoreError>

Construct XorbObject object from AsyncRead. assumes that the ident and version have already been read and verified.

Source

pub fn serialize_given_info<W: Write>( w: &mut W, info: XorbObjectInfoV1, ) -> Result<(Self, usize), CoreError>

Source

pub fn from_info(info: XorbObjectInfoV1) -> Self

Source

pub fn validate_xorb_object<R: Read + Seek>( reader: &mut R, hash: &MerkleHash, ) -> Result<Option<XorbObject>, CoreError>

Validate XorbObject. Verifies each chunk is valid and correctly represented in XorbObjectInfo, along with recomputing the hash and validating it matches XorbObjectInfo.

Returns Ok(Some(xorb object)) if recomputed hash matches what is passed in.

Source

pub fn generate_chunk_range_hash( &self, chunk_start_index: u32, chunk_end_index: u32, ) -> Result<DataHash, CoreError>

Generate a hash for securing a chunk range.

chunk_start_index, chunk_end_index: indices for chunks in XorbObject. The indices should be [start, end) - meaning start is inclusive and end is exclusive. Ex. For specifying the 1st chunk: chunk_start_index: 0, chunk_end_index: 1

key: additional key incorporated into generating hash.

This hash ensures validity of the knowledge of chunks, since ranges are public, this ensures that only users that actually have access to chunks can claim them in a file reconstruction entry.

Source

pub fn get_contents_length(&self) -> Result<u32, CoreError>

Return end offset of all physical chunk contents (byte index at the beginning of footer)

Source

pub fn get_all_bytes<R: Read + Seek>( &self, reader: &mut R, ) -> Result<Vec<u8>, CoreError>

Get all the content bytes from a Xorb

Source

pub fn get_bytes_by_chunk_range<R: Read + Seek>( &self, reader: &mut R, chunk_index_start: u32, chunk_index_end: u32, ) -> Result<Vec<u8>, CoreError>

Convenient function to get content bytes by chunk range, mainly for internal testing

Source

pub fn get_byte_offset( &self, chunk_index_start: u32, chunk_index_end: u32, ) -> Result<(u32, u32), CoreError>

Helper function to translate a range of chunk indices to physical byte offset range.

Source

pub fn uncompressed_chunk_length( &self, chunk_index: u32, ) -> Result<u32, CoreError>

given a valid chunk_index, returns the uncompressed chunk length for the chunk at the given index, chunk_index must be less than the number of chunks in the xorb

Source

pub fn uncompressed_range_length( &self, chunk_index_start: u32, chunk_index_end: u32, ) -> Result<u32, CoreError>

given a valid start and end, returns the uncompressed end-exclusive range length meaning the length of the chunk range [chunk_index_start, chunk_index_end) the following conditions must be valid: chunk_index_start <= chunk_index_end && chunk_index_end <= num_chunks && chunk_index_start < num_chunks

Trait Implementations§

Source§

impl Clone for XorbObject

Source§

fn clone(&self) -> XorbObject

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for XorbObject

Source§

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

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

impl Default for XorbObject

Source§

fn default() -> Self

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

impl PartialEq for XorbObject

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for XorbObject

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for XorbObject

Source§

impl StructuralPartialEq for XorbObject

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> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<E> ResultError for E
where E: Send + Debug + Sync,

Source§

impl<T> ResultType for T
where T: Send + Clone + Sync + Debug,