a653rs_linux_core/
channel.rs

1//! The channels used in combination with the related *sampling* module
2// TODO: Consider merging this module with sampling, as having a module only
3// providing structs might be weird.
4use std::collections::HashSet;
5
6use bytesize::ByteSize;
7use serde::{Deserialize, Deserializer, Serialize};
8
9#[derive(Debug, Serialize, Deserialize, Clone)]
10pub struct SamplingChannelConfig {
11    #[serde(deserialize_with = "de_size_str")]
12    pub msg_size: ByteSize,
13    pub source: PortConfig,
14    pub destination: HashSet<PortConfig>,
15}
16
17impl SamplingChannelConfig {
18    pub fn name(&self) -> &str {
19        &self.source.port
20    }
21}
22
23#[derive(Debug, Serialize, Deserialize, Clone)]
24pub struct QueuingChannelConfig {
25    #[serde(deserialize_with = "de_size_str")]
26    pub msg_size: ByteSize,
27    pub msg_num: usize,
28    pub source: PortConfig,
29    pub destination: PortConfig,
30}
31
32impl QueuingChannelConfig {
33    pub fn name(&self) -> &str {
34        &self.source.port
35    }
36}
37
38#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
39pub struct PortConfig {
40    pub partition: String,
41    pub port: String,
42}
43
44impl PortConfig {
45    pub fn name(&self) -> String {
46        format!("{}:{}", self.partition, self.port)
47    }
48}
49
50fn de_size_str<'de, D>(de: D) -> Result<ByteSize, D::Error>
51where
52    D: Deserializer<'de>,
53{
54    String::deserialize(de)?
55        .parse::<ByteSize>()
56        .map_err(serde::de::Error::custom)
57}