Skip to main content

Envelope

Struct Envelope 

Source
#[repr(C)]
pub struct Envelope { pub message_id: u128, pub source: AddrHash, pub destination: AddrHash, pub type_tag: u64, pub payload_len: u32, pub flags: u32, pub correlation_id: u64, }
Expand description

Fixed-size #[repr(C)] message header used for routing and wire framing.

SIZE bytes on the wire: the envelope is always serialized as a little-endian byte array of exactly Envelope::SIZE bytes, followed by payload_len bytes of payload.

Fields§

§message_id: u128§source: AddrHash§destination: AddrHash§type_tag: u64§payload_len: u32§flags: u32§correlation_id: u64

Implementations§

Source§

impl Envelope

Source

pub const SIZE: usize = 80

In-memory and wire size of the envelope.

The struct fields occupy 72 bytes of meaningful data; #[repr(C)] pads to the next multiple of 16 (the alignment of u128) = 80 bytes. The final 8 bytes are padding zeros in the wire format.

Source

pub const WIRE_SIZE: usize = 41

Compact wire size for remote frames (destination, source, correlation, priority).

Source

pub const FLAG_RESPONSE: u32

Source

pub const FLAG_PRIORITY_MASK: u32

Source

pub fn new( source: AddrHash, destination: AddrHash, type_tag: u64, payload_len: u32, ) -> Self

Source

pub fn response(&self, payload_len: u32) -> Self

Construct a response envelope by swapping source/destination and setting the response flag and correlation id.

Source

pub fn with_priority(self, priority: u8) -> Self

Source

pub fn priority(&self) -> u8

Source

pub fn is_response(&self) -> bool

Source

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

Serialize to a fixed [u8; SIZE] array in little-endian byte order.

Bytes 72–79 are padding zeros (required by #[repr(C)] alignment).

Source

pub fn from_bytes(buf: &[u8; 80]) -> Self

Deserialize from a fixed [u8; SIZE] array. Bytes 72–79 are ignored.

Source

pub fn to_wire(&self) -> [u8; 41]

Serialize to a compact wire format (41 bytes) used for remote frames.

Layout (little-endian): [0..16] destination (u128) [16..32] source (u128) [32..40] correlation_id (u64) [40] priority (u8)

Source

pub fn from_wire(buf: &[u8; 41]) -> Self

Deserialize from a compact wire format (41 bytes).

Fields not present on the wire are set to defaults: message_id = 0, type_tag = 0, payload_len = 0.

Trait Implementations§

Source§

impl Clone for Envelope

Source§

fn clone(&self) -> Envelope

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Envelope

Source§

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

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

impl PartialEq for Envelope

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Copy for Envelope

Source§

impl Eq for Envelope

Source§

impl StructuralPartialEq for Envelope

Auto Trait Implementations§

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.