pub struct Envelope {
pub kind: u32,
pub flags: u32,
pub generation: u64,
pub sequence: u64,
/* private fields */
}Expand description
Caller-provided metadata for a newly encoded message.
Fields§
§kind: u32Numeric message kind; interpretation belongs to the protocol.
flags: u32Numeric flags; unknown required bits must be rejected by the protocol.
generation: u64Nonzero connection generation.
sequence: u64Nonzero per-direction sequence.
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub const fn new(kind: u32, flags: u32, generation: u64, sequence: u64) -> Self
pub const fn new(kind: u32, flags: u32, generation: u64, sequence: u64) -> Self
Creates envelope metadata. The encoder fills the payload length.
Examples found in repository?
examples/bounded_codec.rs (line 40)
38fn main() -> Result<(), Box<dyn std::error::Error>> {
39 let mut wire = [0_u8; 128];
40 let written = encode_message::<CounterProtocol>(Envelope::new(1, 0, 7, 1), &42, &mut wire)?;
41
42 let limits = Limits::new(128, 16, 1, 16);
43 let decoded = decode_message::<CounterProtocol>(&wire[..written], &limits)?;
44
45 assert_eq!(decoded.message, 42);
46 assert_eq!(decoded.envelope.generation, 7);
47 println!(
48 "decoded counter {} from {} bounded bytes",
49 decoded.message, written
50 );
51 Ok(())
52}Sourcepub const fn payload_len(self) -> u32
pub const fn payload_len(self) -> u32
Returns the encoded payload size.
Sourcepub fn total_len(self) -> Result<usize, EncodeError>
pub fn total_len(self) -> Result<usize, EncodeError>
Returns the total encoded size after checked conversion.
Trait Implementations§
impl Copy for Envelope
impl Eq for Envelope
impl StructuralPartialEq for Envelope
Auto Trait Implementations§
impl Freeze for Envelope
impl RefUnwindSafe for Envelope
impl Send for Envelope
impl Sync for Envelope
impl Unpin for Envelope
impl UnsafeUnpin for Envelope
impl UnwindSafe for Envelope
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
Mutably borrows from an owned value. Read more