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>
impl<const BODY_SIZE: usize> StampedChunk<BODY_SIZE>
Sourcepub const fn new(chunk: AnyChunk<BODY_SIZE>, stamp: Stamp) -> Self
pub const fn new(chunk: AnyChunk<BODY_SIZE>, stamp: Stamp) -> Self
Pair a chunk with its stamp.
Sourcepub fn address(&self) -> &ChunkAddress
pub fn address(&self) -> &ChunkAddress
The chunk’s address (delegates to the chunk).
Sourcepub fn into_parts(self) -> (AnyChunk<BODY_SIZE>, Stamp)
pub fn into_parts(self) -> (AnyChunk<BODY_SIZE>, Stamp)
Split into the chunk and its stamp.
Sourcepub fn to_typed_bytes(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn from_typed_bytes(
address: &ChunkAddress,
bytes: &[u8],
) -> Result<Self, StampError>
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.
Sourcepub fn reconstruct(
expected: ChunkAddress,
data: Bytes,
stamp: Stamp,
) -> Result<Self, StampError>
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.
Sourcepub fn batch_id(typed_bytes: &[u8]) -> Result<BatchId, StampError>
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>
impl<const BODY_SIZE: usize> Clone for StampedChunk<BODY_SIZE>
Source§fn clone(&self) -> StampedChunk<BODY_SIZE>
fn clone(&self) -> StampedChunk<BODY_SIZE>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const BODY_SIZE: usize> Debug for StampedChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Debug for StampedChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> Eq for StampedChunk<BODY_SIZE>
Source§impl<const BODY_SIZE: usize> PartialEq for StampedChunk<BODY_SIZE>
impl<const BODY_SIZE: usize> PartialEq for StampedChunk<BODY_SIZE>
Source§fn eq(&self, other: &StampedChunk<BODY_SIZE>) -> bool
fn eq(&self, other: &StampedChunk<BODY_SIZE>) -> bool
self and other values to be equal, and is used by ==.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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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