#[derive(Debug, Clone, PartialEq)]
pub struct MtMessage {
pub block1: Option<Block1>,
pub block2: Option<Block2>,
pub block3: Option<Block3>,
pub block4: Block4,
pub block5: Option<Block5>,
}
impl MtMessage {
pub fn message_type(&self) -> Option<&str> {
match &self.block2 {
Some(Block2::Input(b)) => Some(b.message_type.as_str()),
Some(Block2::Output(b)) => Some(b.message_type.as_str()),
None => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Block1 {
pub app_id: char,
pub service_id: String,
pub lt_address: String,
pub session_number: String,
pub sequence_number: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Block2 {
Input(Block2Input),
Output(Block2Output),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Block2Input {
pub message_type: String,
pub destination: String,
pub priority: Option<char>,
pub delivery_monitoring: Option<char>,
pub obsolescence_period: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Block2Output {
pub message_type: String,
pub input_time: String,
pub input_date: String,
pub mir: String,
pub output_date: String,
pub output_time: String,
pub priority: Option<char>,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Block3 {
pub tags: Vec<(String, String)>,
}
impl Block3 {
pub fn get(&self, tag: &str) -> Option<&str> {
self.tags
.iter()
.find(|(t, _)| t == tag)
.map(|(_, v)| v.as_str())
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Block4 {
pub fields: Vec<TagField>,
}
impl Block4 {
pub fn get(&self, tag: &str) -> Option<&TagField> {
self.fields.iter().find(|f| f.tag == tag)
}
pub fn get_all(&self, tag: &str) -> Vec<&TagField> {
self.fields.iter().filter(|f| f.tag == tag).collect()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TagField {
pub tag: String,
pub value: String,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Block5 {
pub tags: Vec<(String, String)>,
}
impl Block5 {
pub fn get(&self, tag: &str) -> Option<&str> {
self.tags
.iter()
.find(|(t, _)| t == tag)
.map(|(_, v)| v.as_str())
}
}