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>
<..>
Fields§
§info: XorbObjectInfoV1XorbObjectInfo block see [XorbObjectInfo] for details.
info_length: u32Length 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
impl XorbObject
Sourcepub fn get_info_length<R: Read + Seek>(reader: &mut R) -> Result<u32, CoreError>
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::
Sourcepub fn deserialize<R: Read + Seek>(reader: &mut R) -> Result<Self, CoreError>
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.
Sourcepub async fn deserialize_async<R: AsyncRead + Unpin>(
reader: &mut R,
version: u8,
) -> Result<Self, CoreError>
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.
pub fn serialize_given_info<W: Write>( w: &mut W, info: XorbObjectInfoV1, ) -> Result<(Self, usize), CoreError>
pub fn from_info(info: XorbObjectInfoV1) -> Self
Sourcepub fn validate_xorb_object<R: Read + Seek>(
reader: &mut R,
hash: &MerkleHash,
) -> Result<Option<XorbObject>, CoreError>
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.
Sourcepub fn generate_chunk_range_hash(
&self,
chunk_start_index: u32,
chunk_end_index: u32,
) -> Result<DataHash, CoreError>
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.
Sourcepub fn get_contents_length(&self) -> Result<u32, CoreError>
pub fn get_contents_length(&self) -> Result<u32, CoreError>
Return end offset of all physical chunk contents (byte index at the beginning of footer)
Sourcepub fn get_all_bytes<R: Read + Seek>(
&self,
reader: &mut R,
) -> Result<Vec<u8>, CoreError>
pub fn get_all_bytes<R: Read + Seek>( &self, reader: &mut R, ) -> Result<Vec<u8>, CoreError>
Get all the content bytes from a Xorb
Sourcepub 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>
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
Sourcepub fn get_byte_offset(
&self,
chunk_index_start: u32,
chunk_index_end: u32,
) -> Result<(u32, u32), CoreError>
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.
Sourcepub fn uncompressed_chunk_length(
&self,
chunk_index: u32,
) -> Result<u32, CoreError>
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
Sourcepub fn uncompressed_range_length(
&self,
chunk_index_start: u32,
chunk_index_end: u32,
) -> Result<u32, CoreError>
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
impl Clone for XorbObject
Source§fn clone(&self) -> XorbObject
fn clone(&self) -> XorbObject
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for XorbObject
impl Debug for XorbObject
Source§impl Default for XorbObject
impl Default for XorbObject
Source§impl PartialEq for XorbObject
impl PartialEq for XorbObject
Source§impl Serialize for XorbObject
impl Serialize for XorbObject
impl Eq for XorbObject
impl StructuralPartialEq for XorbObject
Auto Trait Implementations§
impl Freeze for XorbObject
impl RefUnwindSafe for XorbObject
impl Send for XorbObject
impl Sync for XorbObject
impl Unpin for XorbObject
impl UnsafeUnpin for XorbObject
impl UnwindSafe for XorbObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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