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
impl RedPacket
Sourcepub fn new(
primary_payload_type: u8,
primary: Bytes,
redundant: impl IntoIterator<Item = (u8, u16, Bytes)>,
) -> Result<Self>
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.
Sourcepub fn from_blocks(blocks: Vec<RedBlock>) -> Result<Self>
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.
Sourcepub fn parse(payload: &Bytes) -> Result<Self>
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.
Sourcepub fn blocks(&self) -> &[RedBlock]
pub fn blocks(&self) -> &[RedBlock]
All blocks: redundant ones in header order, the primary last.
Sourcepub fn into_blocks(self) -> Vec<RedBlock>
pub fn into_blocks(self) -> Vec<RedBlock>
Takes the blocks out.
Trait Implementations§
impl Eq for RedPacket
Source§impl MarshalSize for RedPacket
impl MarshalSize for RedPacket
Source§fn marshal_size(&self) -> usize
fn marshal_size(&self) -> usize
Marshal::marshal_to will write for this value.