Struct resol_vbus::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§

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§

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

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§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.