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
use super::Address;

/// Command `Connect`
/// ```plain
/// +----------+
/// |   ADDR   |
/// +----------+
/// | Variable |
/// +----------+
/// ```
///
/// where:
///
/// - `ADDR` - target address
#[derive(Clone, Debug)]
pub struct Connect {
    addr: Address,
}

impl Connect {
    const TYPE_CODE: u8 = 0x01;

    /// Creates a new `Connect` command
    pub const fn new(addr: Address) -> Self {
        Self { addr }
    }

    /// Returns the address
    pub fn addr(&self) -> &Address {
        &self.addr
    }

    /// Returns the command type code
    pub const fn type_code() -> u8 {
        Self::TYPE_CODE
    }

    /// Returns the serialized length of the command
    #[allow(clippy::len_without_is_empty)]
    pub fn len(&self) -> usize {
        self.addr.len()
    }
}

impl From<Connect> for (Address,) {
    fn from(conn: Connect) -> Self {
        (conn.addr,)
    }
}