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:
- Fields that are used to identify the
Header
and (for concrete VBus data types) its payload:channel
source_address
destination_address
protocol_version
- 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
impl Header
sourcepub fn id_string(&self) -> String
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 IdHash for Header
impl IdHash for Header
source§fn id_hash<H: Hasher>(&self, h: &mut H)
fn id_hash<H: Hasher>(&self, h: &mut H)
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));