Skip to main content

Shard

Struct Shard 

Source
pub struct Shard {
    pub file_hash: String,
    pub file_len: u64,
    pub xorb_hashes: Vec<String>,
    pub mdb_bytes: Vec<u8>,
}
Expand description

The reconstruction manifest for a single file: the .mdb bytes plus the derived metadata the protocol response carries (file hash, length, xorb hashes).

Fields§

§file_hash: String

Hex-encoded file merkle hash this shard reconstructs.

§file_len: u64

Total file length in bytes (sum of all segment byte lengths).

§xorb_hashes: Vec<String>

Hex-encoded xorb hashes the file was split across, in order.

§mdb_bytes: Vec<u8>

The raw .mdb shard bytes (the XET wire format).

Implementations§

Source§

impl Shard

Source

pub fn from_chunks(chunks: &[Chunk]) -> (Shard, Vec<(MerkleHash, Vec<u8>)>)

Build a shard from the file’s chunk list, grouping chunks into xorbs that respect the XET MAX_XORB_BYTES (64 MiB) and MAX_XORB_CHUNKS (8192) limits. Returns the shard plus, for each xorb in order, the xorb hash and the concatenated xorb bytes.

Chunk → xorb aggregation, xorb hashing (merklehash::xorb_hash), and file hashing (merklehash::file_hash) all match xet-core’s RawXorbData::from_chunks, so the hashes embedded in the produced shard are identical to an upstream client’s.

Source

pub fn from_chunks_with_cap( chunks: &[Chunk], xorb_byte_cap: usize, ) -> (Shard, Vec<(MerkleHash, Vec<u8>)>)

Like [from_chunks], but with a custom per-xorb byte cap. Used by tests to force multi-xorb aggregation without allocating 64 MiB. The chunk count cap (MAX_XORB_CHUNKS = 8192) still applies.

Source

pub fn to_bytes(&self) -> &[u8] ⓘ

Serialize the shard to its raw .mdb bytes for storage/transmission. This is the XET wire format — a stock xet-core MDBShardFile reader can parse it.

Source

pub fn segments( mdb_bytes: &[u8], file_hash: &MerkleHash, ) -> Result<Vec<Segment>>

Parse the reconstruction segments for this file out of a .mdb byte buffer. Each segment tells the reassembler which xorb to fetch and which local chunk range to slice out of it.

Trait Implementations§

Source§

impl Clone for Shard

Source§

fn clone(&self) -> Shard

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 Shard

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Shard

§

impl RefUnwindSafe for Shard

§

impl Send for Shard

§

impl Sync for Shard

§

impl Unpin for Shard

§

impl UnsafeUnpin for Shard

§

impl UnwindSafe for Shard

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

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

§

fn vzip(self) -> V