1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! This module contains the data structures used to store the data of the application.
use crate::interface::{layer::Layer, parser::parser_rrc::RRCInfos};
use core::fmt::Debug;

#[derive(Debug)]
/// Data structure to store Trace of the application.
pub struct Data {
    /// Vector of Trace.
    pub events: Vec<Trace>,
    /// Current index of the vector.
    pub current_index: usize,
}

impl Data {
    /// return the current trace
    pub fn get_current_trace(&self) -> Option<&Trace> {
        return self.events.get(self.current_index);
    }

    /// return if the index is different from the current index
    pub fn is_different_index(&self, index: usize) -> bool {
        if index == 0 {
            return true;
        }
        self.current_index != index
    }

    /// clear the data
    pub fn clear(&mut self) {
        self.events.clear();
        self.current_index = 0;
    }
}

impl Default for Data {
    fn default() -> Self {
        let default_data_size = 2048;
        Self {
            events: Vec::with_capacity(default_data_size),
            current_index: 0,
        }
    }
}

#[derive(Debug, Clone)]
/// Data structure to store Trace of the application.
pub struct Trace {
    /// Message type.
    /// Timestamp of the message.
    pub timestamp: u64,

    /// Layer of the message.
    pub layer: Layer,

    /// Message type.
    pub additional_infos: AdditionalInfos,

    /// Hexadecimal representation of the message.
    pub hexa: Vec<u8>,

    /// Text representation of the message from the API
    pub text: Option<Vec<String>>,
}

/// Data structure to store custom messages (from the amarisoft API)
#[derive(Debug, Clone)]
pub enum AdditionalInfos {
    /// RRC message
    RRCInfos(RRCInfos),
}