Struct Header

Source
pub struct Header {
    pub timestamp: DateTime<Utc>,
    pub channel: u8,
    pub destination_address: u16,
    pub source_address: u16,
    pub protocol_version: u8,
}
Expand description

All VBus data types consist of a Header element.

Just like the fact that the first 6 bytes of each VBus live byte stream are the same (SYNC to protocol version), the Header struct is the common type for all concrete VBus data types.

In addition to the information stored within the first 6 bytes of the VBus header (destination and source addresses as well as the protocol version), the Header type also stores the VBus channel associated with this data as well as the point in time the data was received.

§The “identity” of Header values

The fields in the Header struct can be separated into two categories:

  1. Fields that are used to identify the Header and (for concrete VBus data types) its payload:
    • channel
    • source_address
    • destination_address
    • protocol_version
  2. Fields that are not used to identify the Header:
    • timestamp

Two Header values with different timestamp fields are considered identical, if all of their other fields match.

This is also respected by the id_hash and id_string functions. They return the same result for VBus data values that are considered “identical”, allowing some fields to differ.

Fields§

§timestamp: DateTime<Utc>

The timestamp when this Header was received.

§channel: u8

The channel number on which this Header was received.

§destination_address: u16

The destination address of this Header.

§source_address: u16

The source address of this Header.

§protocol_version: u8

The VBus protocol version of this Header.

Implementations§

Source§

impl Header

Source

pub fn id_string(&self) -> String

Creates the common identification string prefix for this Header.

The string contains all fields that count towards the “identity” of the Header:

  • channel
  • destination_address
  • source_address
  • protocol_version
§Examples
use resol_vbus::{Header};
use resol_vbus::utils::utc_timestamp;

let header = Header {
    timestamp: utc_timestamp(1485688933),
    channel: 0x11,
    destination_address: 0x1213,
    source_address: 0x1415,
    protocol_version: 0x16,
};

assert_eq!("11_1213_1415_16", header.id_string());

Trait Implementations§

Source§

impl AsRef<Header> for Data

Source§

fn as_ref(&self) -> &Header

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Header> for Datagram

Source§

fn as_ref(&self) -> &Header

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Header> for Packet

Source§

fn as_ref(&self) -> &Header

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Header> for Telegram

Source§

fn as_ref(&self) -> &Header

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Header

Source§

fn clone(&self) -> Header

Returns a copy 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 Header

Source§

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

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

impl Default for Header

Source§

fn default() -> Header

Returns the “default value” for a type. Read more
Source§

impl IdHash for Header

Source§

fn id_hash<H>(&self, h: &mut H)
where H: Hasher,

Returns an identification hash for this Header.

The hash contains all fields that count towards the “identity” of the Header:

  • channel
  • destination_address
  • source_address
  • protocol_version
§Examples
use resol_vbus::{Header, id_hash};
use resol_vbus::utils::utc_timestamp;

let header = Header {
    timestamp: utc_timestamp(1485688933),
    channel: 0x11,
    destination_address: 0x1213,
    source_address: 0x1415,
    protocol_version: 0x16,
};

assert_eq!(8369676560183260683, id_hash(&header));

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

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.