Skip to main content

Header

Struct Header 

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

Decoded wire header. magic and header_crc32 are not stored: magic is always b"WEIR" after a successful decode (storing it invites confusion about validity), and CRC is computed on encode rather than held as state.

Fields are private and read-only (accessors below): a header is only ever produced by Header::new (which pins version to WIRE_VERSION) or by Header::decode (which validates every field). This makes it impossible for a caller to desync payload_len from the real payload or set version off WIRE_VERSION after construction.

Implementations§

Source§

impl Header

Source

pub fn new(message_type: MessageType, durability: Durability, flags: u8) -> Self

Constructs a header for outbound frames. Version is always WIRE_VERSION.

payload_len is NOT a parameter: it is set to 0 here and becomes authoritative only when the header is wrapped in an Envelope, which derives it from the actual payload (see Envelope::new). This makes a header whose declared length disagrees with its payload unrepresentable — a bare Header::encode always declares payload_len = 0, so it is only valid for the genuinely-empty-payload frames (Ack / HealthCheck) that use it (F50).

In wire v1 flags MUST be 0. Any other value encodes a frame that Header::decode rejects with DecodeError::ReservedFlagsSet (and the daemon Nacks then closes the connection); the parameter is kept non-zero- capable only so the codec can construct reject-path test frames.

Source

pub fn version(&self) -> u8

Wire protocol version. Always WIRE_VERSION for a header built by Header::new; a decoded header only exists if its version matched.

Source

pub fn message_type(&self) -> MessageType

The frame’s MessageType.

Source

pub fn durability(&self) -> Durability

The frame’s Durability tier.

Source

pub fn flags(&self) -> u8

Reserved flags byte (zero in v1; preserved verbatim through the codec).

Source

pub fn payload_len(&self) -> u32

Declared payload length in bytes. For an Envelope this always equals the actual payload length (see Envelope::new); on a bare decoded header it is the wire-declared length used to read the payload.

Source

pub fn encode(&self) -> [u8; 16]

Serialises the header to exactly HEADER_LEN bytes. CRC is computed here; the caller does not need to know the CRC coverage range.

Source

pub fn decode(buf: &[u8; 16]) -> Result<Self, DecodeError>

Decodes and validates a 16-byte header buffer.

Validation order is deliberate:

  1. Magic — cheapest check; eliminates non-weir traffic before any further work.
  2. Version — before CRC, so a version-mismatched frame from a v2 client receives VersionMismatch (with the daemon’s version in the Nack payload) rather than a confusing HeaderCrcMismatch if the frame layout shifted between versions.
  3. Header CRC — validates the remaining bytes are uncorrupted before parsing them.
  4. Typed field parsing — only after all integrity checks pass.

Trait Implementations§

Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

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 Copy for Header

Source§

impl Debug for Header

Source§

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

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

impl Eq for Header

Source§

impl PartialEq for Header

Source§

fn eq(&self, other: &Header) -> 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 Header

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

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.