tramex_tools/
data.rs

1//! This module contains the data structures used to store the data of the application.
2use crate::interface::{layer::Layer, parser::parser_rrc::RRCInfos};
3use core::fmt::Debug;
4
5#[derive(Debug)]
6/// Data structure to store Trace of the application.
7pub struct Data {
8    /// Vector of Trace.
9    pub events: Vec<Trace>,
10    /// Current index of the vector.
11    pub current_index: usize,
12}
13
14impl Data {
15    /// return the current trace
16    pub fn get_current_trace(&self) -> Option<&Trace> {
17        self.events.get(self.current_index)
18    }
19
20    /// return if the index is different from the current index
21    pub fn is_different_index(&self, index: usize) -> bool {
22        if index == 0 {
23            return true;
24        }
25        self.current_index != index
26    }
27
28    /// clear the data
29    pub fn clear(&mut self) {
30        self.events.clear();
31        self.current_index = 0;
32    }
33}
34
35impl Default for Data {
36    fn default() -> Self {
37        let default_data_size = 2048;
38        Self {
39            events: Vec::with_capacity(default_data_size),
40            current_index: 0,
41        }
42    }
43}
44
45#[derive(Debug, Clone)]
46/// Data structure to store Trace of the application.
47pub struct Trace {
48    /// Message type.
49    /// Timestamp of the message.
50    pub timestamp: u64,
51
52    /// Layer of the message.
53    pub layer: Layer,
54
55    /// Message type.
56    pub additional_infos: AdditionalInfos,
57
58    /// Hexadecimal representation of the message.
59    pub hexa: Vec<u8>,
60
61    /// Text representation of the message from the API
62    pub text: Option<Vec<String>>,
63}
64
65/// Data structure to store custom messages (from the amarisoft API)
66#[derive(Debug, Clone)]
67pub enum AdditionalInfos {
68    /// RRC message
69    RRCInfos(RRCInfos),
70}