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
use {
    super::types::AuthPlugin,
    crate::{bitflags::CapabilityFlags, TimeoutFuture},
    std::fmt,
};

pub struct ConnectionData {
    pub(super) id: u32,
    pub(super) is_mariadb: bool,
    pub(super) version: (u16, u16, u16),
    pub(super) capabilities: CapabilityFlags,
    pub(super) nonce: Vec<u8>,
    pub(super) auth_plugin: AuthPlugin,
    pub(super) auth_switched: bool,
    pub(super) max_allowed_packet: usize,
    pub(super) sleep: &'static dyn Fn(std::time::Duration) -> TimeoutFuture,
}

impl ConnectionData {
    pub fn id(&self) -> u32 {
        self.id
    }

    pub fn is_mariadb(&self) -> bool {
        self.is_mariadb
    }

    pub fn version(&self) -> (u16, u16, u16) {
        self.version
    }

    pub fn capabilities(&self) -> CapabilityFlags {
        self.capabilities
    }

    pub fn auth_plugin(&self) -> AuthPlugin {
        self.auth_plugin
    }

    pub fn max_allowed_packet(&self) -> usize {
        self.max_allowed_packet
    }
}

impl fmt::Debug for ConnectionData {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("ConnectionData")
            .field("id", &self.id)
            .field("is_mariadb", &self.is_mariadb)
            .field("version", &self.version)
            .field("capabilities", &self.capabilities)
            .field("nonce", &self.nonce)
            .field("auth_plugin", &self.auth_plugin)
            .field("auth_switched", &self.auth_switched)
            .field("max_allowed_packet", &self.max_allowed_packet)
            .finish()
    }
}