Skip to main content

manycastr/cli/writer/
latency_row.rs

1use crate::SINGLE_ORIGIN;
2use crate::cli::writer::format_rtt;
3use crate::custom_module::manycastr::MeasurementReply;
4use bimap::BiHashMap;
5
6/// Get the result (csv row) from a Reply message
7///
8/// # Arguments
9/// * `reply` - The Reply that is being written to this row
10/// * `rx_worker_id` - The worker ID of the receiver
11/// * `worker_map` - A map of worker IDs to hostnames, used to convert worker IDs to hostnames in the results
12/// * `origin_id` - origin ID associated with the reply
13///
14/// # Returns
15/// A vector of strings representing the row in the CSV file
16pub fn get_latency_row(
17    reply: MeasurementReply,
18    rx_worker_id: &u32,
19    worker_map: &BiHashMap<u32, String>,
20    origin_id: u32,
21) -> Vec<String> {
22    // convert the worker ID to hostname
23    let rx_hostname = worker_map
24        .get_by_left(rx_worker_id)
25        .unwrap_or(&String::from("Unknown"))
26        .to_string();
27
28    let mut row = vec![
29        rx_hostname,
30        reply.src.unwrap().to_string(),
31        reply.ttl.to_string(),
32        format_rtt(reply.rtt),
33    ];
34
35    // Optional fields
36    if origin_id != SINGLE_ORIGIN {
37        row.push(origin_id.to_string());
38    }
39
40    row
41}