Skip to main content

simple_someip/e2e/
state.rs

1//! State tracking structures for E2E profiles.
2
3/// State for E2E Profile 4 protection/checking.
4#[derive(Debug, Clone)]
5pub struct Profile4State {
6    /// Counter for protection (incremented on each protect call).
7    pub(crate) protect_counter: u16,
8    /// Last received counter for checking.
9    pub(crate) last_counter: Option<u16>,
10}
11
12impl Profile4State {
13    /// Create a new Profile 4 state with initial counter value of 0.
14    #[must_use]
15    pub fn new() -> Self {
16        Self {
17            protect_counter: 0,
18            last_counter: None,
19        }
20    }
21
22    /// Create a new Profile 4 state with a specific initial counter.
23    #[must_use]
24    pub fn with_initial_counter(counter: u16) -> Self {
25        Self {
26            protect_counter: counter,
27            last_counter: None,
28        }
29    }
30
31    /// Reset the state to initial values.
32    pub fn reset(&mut self) {
33        self.protect_counter = 0;
34        self.last_counter = None;
35    }
36}
37
38impl Default for Profile4State {
39    fn default() -> Self {
40        Self::new()
41    }
42}
43
44/// State for E2E Profile 5 protection/checking.
45#[derive(Debug, Clone)]
46pub struct Profile5State {
47    /// Counter for protection (incremented on each protect call).
48    pub(crate) protect_counter: u8,
49    /// Last received counter for checking.
50    pub(crate) last_counter: Option<u8>,
51}
52
53impl Profile5State {
54    /// Create a new Profile 5 state with initial counter value of 0.
55    #[must_use]
56    pub fn new() -> Self {
57        Self {
58            protect_counter: 0,
59            last_counter: None,
60        }
61    }
62
63    /// Create a new Profile 5 state with a specific initial counter.
64    #[must_use]
65    pub fn with_initial_counter(counter: u8) -> Self {
66        Self {
67            protect_counter: counter,
68            last_counter: None,
69        }
70    }
71
72    /// Reset the state to initial values.
73    pub fn reset(&mut self) {
74        self.protect_counter = 0;
75        self.last_counter = None;
76    }
77}
78
79impl Default for Profile5State {
80    fn default() -> Self {
81        Self::new()
82    }
83}