Skip to main content

RedPacket

Struct RedPacket 

Source
pub struct RedPacket { /* private fields */ }
Expand description

One RED payload: redundant blocks in header order, then the primary.

Always valid by construction: at most RED_MAX_BLOCKS blocks, the last and only the last one primary, payload types at most 127, redundant offsets at most 0x3FFF and lengths at most 0x3FF.

Implementations§

Source§

impl RedPacket

Source

pub fn new( primary_payload_type: u8, primary: Bytes, redundant: impl IntoIterator<Item = (u8, u16, Bytes)>, ) -> Result<Self>

A payload of redundant blocks (in header order, conventionally oldest first) followed by the primary.

§Errors

Fails on a payload type above 127, a redundant offset above 0x3FFF or length above 0x3FF, or more than RED_MAX_BLOCKS blocks in all.

Source

pub fn from_blocks(blocks: Vec<RedBlock>) -> Result<Self>

A payload from explicit blocks; the last must be the primary.

§Errors

As RedPacket::new, plus: no block, or a primary block anywhere but last.

Source

pub fn parse(payload: &Bytes) -> Result<Self>

Parses a RED payload (zero-copy: the blocks’ data are slices of payload).

§Errors

Fails on an empty payload, a truncated header, no primary header within RED_MAX_BLOCKS headers, or block lengths exceeding the payload.

Source

pub fn blocks(&self) -> &[RedBlock]

All blocks: redundant ones in header order, the primary last.

Source

pub fn redundant(&self) -> &[RedBlock]

The redundant blocks, in header order.

Source

pub fn primary(&self) -> &RedBlock

The primary block.

Source

pub fn into_blocks(self) -> Vec<RedBlock>

Takes the blocks out.

Trait Implementations§

Source§

impl Clone for RedPacket

Source§

fn clone(&self) -> Self

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 RedPacket

Source§

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

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

impl Eq for RedPacket

Source§

impl Marshal for RedPacket

Source§

fn marshal_to(&self, buf: &mut [u8]) -> Result<usize>

Writes the headers, F set on all but the primary’s, then the data blocks.

Source§

fn marshal(&self) -> Result<BytesMut, Error>

Encodes into a freshly allocated buffer sized by MarshalSize::marshal_size. Read more
Source§

impl MarshalSize for RedPacket

Source§

fn marshal_size(&self) -> usize

The number of bytes Marshal::marshal_to will write for this value.
Source§

impl PartialEq for RedPacket

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RedPacket

Source§

impl Unmarshal for RedPacket

Source§

fn unmarshal<B>(buf: &mut B) -> Result<Self>
where Self: Sized, B: Buf,

Parses all remaining bytes of buf as one RED payload (see RedPacket::parse).

Auto Trait Implementations§

§

impl Forget for RedPacket

§

impl Freeze for RedPacket

§

impl Move for RedPacket

§

impl RefUnwindSafe for RedPacket

§

impl Send for RedPacket
where RawVecInner: Send, Bytes: Send,

§

impl Sync for RedPacket
where RawVecInner: Sync, Bytes: Sync,

§

impl Unpin for RedPacket
where *const u8 is !null: Unpin, *const u8: Unpin, Align8<*mut ()>: Unpin, &'static Vtable: Unpin,

§

impl UnsafeUnpin for RedPacket

§

impl UnwindSafe for RedPacket
where RawVecInner: UnwindSafe, *const u8: UnwindSafe, Align8<*mut ()>: UnwindSafe, &'static Vtable: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.