pub struct DataSet {
pub timestamp: DateTime<Utc>,
/* private fields */
}
Expand description
A DataSet
contains a set of unique (non-identical) Data
values.
§Examples
use std::io::Read;
use resol_vbus::{DataSet, RecordingReader, Result};
fn print_data_ids<R: Read>(r: R) -> Result<()> {
let mut rr = RecordingReader::new(r);
let mut cumultative_data_set = DataSet::new();
while let Some(data_set) = rr.read_data_set()? {
let timestamp = data_set.timestamp;
cumultative_data_set.add_data_set(data_set);
println!("{}:", timestamp);
for data in cumultative_data_set.iter() {
println!(" - {}", data.id_string());
}
}
Ok(())
}
Fields§
§timestamp: DateTime<Utc>
The timestamp that corresponds to the contained set of Data
values.
Implementations§
Source§impl DataSet
impl DataSet
Sourcepub fn new() -> DataSet
pub fn new() -> DataSet
Construct an empty DataSet
.
Examples found in repository?
9fn main() -> Result<()> {
10 async_std::task::block_on(async {
11 // Create an recording file and hand it to a `RecordingWriter`
12 let file = File::create("test.vbus")?;
13 let mut rw = RecordingWriter::new(file);
14
15 // Parse the address of the DL2 to connect to
16 let addr = "192.168.5.217:7053".parse::<SocketAddr>()?;
17
18 let stream = TcpStream::connect(addr).await?;
19
20 let mut hs = TcpClientHandshake::start(stream).await?;
21 hs.send_pass_command("vbus").await?;
22 let stream = hs.send_data_command().await?;
23
24 let (reader, writer) = (&stream, &stream);
25
26 let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);
27
28 while let Some(data) = stream.receive_any_data(60000).await? {
29 println!("{}", data.id_string());
30
31 // Add `Data` value into `DataSet` to be stored
32 let mut data_set = DataSet::new();
33 data_set.timestamp = data.as_ref().timestamp;
34 data_set.add_data(data);
35
36 // Write the `DataSet` into the `RecordingWriter` for permanent storage
37 rw.write_data_set(&data_set)
38 .expect("Unable to write data set");
39 }
40
41 Ok(())
42 })
43}
Sourcepub fn from_data(timestamp: DateTime<Utc>, set: Vec<Data>) -> DataSet
pub fn from_data(timestamp: DateTime<Utc>, set: Vec<Data>) -> DataSet
Construct a DataSet
from a list of Data
values.
Sourcepub fn as_data_slice(&self) -> &[Data]
pub fn as_data_slice(&self) -> &[Data]
Return the Data
values contained in this DataSet
.
Sourcepub fn add_data(&mut self, data: Data)
pub fn add_data(&mut self, data: Data)
Add a Data
value, replacing any identical existing one.
Examples found in repository?
9fn main() -> Result<()> {
10 async_std::task::block_on(async {
11 // Create an recording file and hand it to a `RecordingWriter`
12 let file = File::create("test.vbus")?;
13 let mut rw = RecordingWriter::new(file);
14
15 // Parse the address of the DL2 to connect to
16 let addr = "192.168.5.217:7053".parse::<SocketAddr>()?;
17
18 let stream = TcpStream::connect(addr).await?;
19
20 let mut hs = TcpClientHandshake::start(stream).await?;
21 hs.send_pass_command("vbus").await?;
22 let stream = hs.send_data_command().await?;
23
24 let (reader, writer) = (&stream, &stream);
25
26 let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);
27
28 while let Some(data) = stream.receive_any_data(60000).await? {
29 println!("{}", data.id_string());
30
31 // Add `Data` value into `DataSet` to be stored
32 let mut data_set = DataSet::new();
33 data_set.timestamp = data.as_ref().timestamp;
34 data_set.add_data(data);
35
36 // Write the `DataSet` into the `RecordingWriter` for permanent storage
37 rw.write_data_set(&data_set)
38 .expect("Unable to write data set");
39 }
40
41 Ok(())
42 })
43}
Sourcepub fn add_data_set(&mut self, data_set: DataSet)
pub fn add_data_set(&mut self, data_set: DataSet)
Add all Data
values from one DataSet
into another.
Sourcepub fn remove_all_data(&mut self)
pub fn remove_all_data(&mut self)
Remove all Data
values.
Sourcepub fn remove_data_older_than(&mut self, min_timestamp: DateTime<Utc>)
pub fn remove_data_older_than(&mut self, min_timestamp: DateTime<Utc>)
Remove Data
values with timestamps older than min_timestamp
.
Sourcepub fn clear_all_packets(&mut self)
pub fn clear_all_packets(&mut self)
Find all Packet
values and set their frame_count
to zero effectively hiding
their frame_data
payload.
Sourcepub fn clear_packets_older_than(&mut self, min_timestamp: DateTime<Utc>)
pub fn clear_packets_older_than(&mut self, min_timestamp: DateTime<Utc>)
Find all Packet
values with timestamps older than min_timestamp
and set their
frame_count
to zero effectively hiding their frame_data
payload.
Sourcepub fn sort_by_id_slice(&mut self, ids: &[PacketId])
pub fn sort_by_id_slice(&mut self, ids: &[PacketId])
Sort the Data
values contained in this DataSet
by a list of known PacketId
values.