Skip to main content

manycastr/cli/writer/
catchment_row.rs

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