Skip to main content

StampedChunk

Struct StampedChunk 

Source
pub struct StampedChunk<const BODY_SIZE: usize = DEFAULT_BODY_SIZE> { /* private fields */ }
Expand description

A chunk together with its postage stamp.

AnyChunk holds the chunk bytes but carries no stamp, so this pairing is the always-stamped currency on the network paths (pushsync, upload, the stamped reserve). The address is the chunk’s own address; address delegates to it.

§Equality

PartialEq/Eq are derived. The chunk component therefore inherits AnyChunk’s own equality, which compares chunks by address only (a chunk’s address is the cryptographic commitment to its bytes, so equal addresses mean equal chunks), and the stamp component compares all stamp fields. Two stamped chunks are equal when their chunks share an address and their stamps are field-for-field identical. This matches the semantics of the original vertex StampedChunk, which also derived equality over the same two fields.

Implementations§

Source§

impl<const BODY_SIZE: usize> StampedChunk<BODY_SIZE>

Source

pub const fn new(chunk: AnyChunk<BODY_SIZE>, stamp: Stamp) -> Self

Pair a chunk with its stamp.

Source

pub const fn chunk(&self) -> &AnyChunk<BODY_SIZE>

The chunk.

Source

pub const fn stamp(&self) -> &Stamp

The postage stamp.

Source

pub fn address(&self) -> &ChunkAddress

The chunk’s address (delegates to the chunk).

Source

pub fn into_parts(self) -> (AnyChunk<BODY_SIZE>, Stamp)

Split into the chunk and its stamp.

Source

pub fn to_typed_bytes(&self) -> Vec<u8>

Encode to a self-describing byte string: the stamp followed by the type-tagged chunk.

The layout is [stamp: STAMP_SIZE][type_id: 1][chunk wire bytes], the stamp’s fixed-size encoding (Stamp::to_bytes, STAMP_SIZE = 113 bytes) followed by the chunk’s type-tagged encoding (AnyChunk::to_typed_bytes). Decode with from_typed_bytes.

Source

pub fn from_typed_bytes( address: &ChunkAddress, bytes: &[u8], ) -> Result<Self, StampError>

Decode a stamped chunk produced by to_typed_bytes.

The first STAMP_SIZE bytes are the stamp (Stamp::from_bytes); the remainder is the type-tagged chunk (AnyChunk::from_typed_bytes), verified against address.

§Errors

Returns an error (and never panics) when the input is shorter than a stamp, the stamp bytes are invalid, the chunk payload cannot be decoded, or the chunk’s computed address does not match address.

Source

pub fn reconstruct( expected: ChunkAddress, data: Bytes, stamp: Stamp, ) -> Result<Self, StampError>

Rebuild a stamped chunk from the bare chunk wire bytes, its expected address, and a separately-carried stamp.

data is the bare chunk wire bytes (no type tag), as carried in a Delivery { data, stamp } wire message; the address disambiguates the chunk variant (see AnyChunk::from_wire_bytes).

§Errors

Returns an error (and never panics) when data does not hash to expected as either a content or a single-owner chunk.

Source

pub fn batch_id(typed_bytes: &[u8]) -> Result<BatchId, StampError>

Read the batch id from a to_typed_bytes value without a full decode.

The stamp leads the encoding and Stamp::to_bytes places the batch id in its first 32 bytes, so the batch id is typed_bytes[0..32]. This lets a store index a stamped chunk by batch without decoding the chunk.

§Errors

Returns an error (and never panics) when typed_bytes is shorter than 32 bytes.

Trait Implementations§

Source§

impl<const BODY_SIZE: usize> Clone for StampedChunk<BODY_SIZE>

Source§

fn clone(&self) -> StampedChunk<BODY_SIZE>

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<const BODY_SIZE: usize> Debug for StampedChunk<BODY_SIZE>

Source§

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

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

impl<const BODY_SIZE: usize> Eq for StampedChunk<BODY_SIZE>

Source§

impl<const BODY_SIZE: usize> PartialEq for StampedChunk<BODY_SIZE>

Source§

fn eq(&self, other: &StampedChunk<BODY_SIZE>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<const BODY_SIZE: usize> StructuralPartialEq for StampedChunk<BODY_SIZE>

Auto Trait Implementations§

§

impl<const BODY_SIZE: usize = DEFAULT_BODY_SIZE> !Freeze for StampedChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> RefUnwindSafe for StampedChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Send for StampedChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Sync for StampedChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> Unpin for StampedChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> UnsafeUnpin for StampedChunk<BODY_SIZE>

§

impl<const BODY_SIZE: usize> UnwindSafe for StampedChunk<BODY_SIZE>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = 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