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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#[repr(transparent)]
#[derive(Clone, Copy)]
/// Client/Server Capability Flags: https://dev.mysql.com/doc/internals/en/capability-flags.html#packet-Protocol::CapabilityFlags
pub struct CapabilityFlags(pub u32);
impl CapabilityFlags {
/// Creates empty flags
pub const fn new() -> Self {
Self(0)
}
/// Transform 16-bit value as lower bits of flags
pub const fn from_lower_bits(lb: u16) -> Self {
Self(lb as _)
}
/// Combines passed 16-bit value as upper bits of flags
pub const fn combine_upper_bytes(self, ub: u16) -> Self {
Self(self.0 & 0xffff | ((ub as u32) << 16))
}
/// Use the improved version of Old Password Authentication.
pub const fn use_long_password(&self) -> bool {
(self.0 & 0x0000_0001) != 0
}
/// Sets to use the improved version of Old Password Authentication.
pub fn set_use_long_password(&mut self) -> &mut Self {
self.0 |= 0x0000_0001;
self
}
/// Send found rows instead of affected rows in EOF Packet
pub const fn send_found_rows_at_eof(&self) -> bool {
(self.0 & 0x0000_0002) != 0
}
/// Handshake Response packet contains database name
pub const fn support_connect_with_db(&self) -> bool {
(self.0 & 0x0000_0008) != 0
}
/// Set to Handshake Response packet contains database name
pub fn set_connect_with_db(&mut self) -> &mut Self {
self.0 |= 0x0000_0008;
self
}
/// Set to Handshake Response packet does not contains database name
pub fn clear_connect_with_db(&mut self) -> &mut Self {
self.0 &= !0x0000_0008;
self
}
/// Server does not permit `database.table.column` format
pub const fn no_schema(&self) -> bool {
(self.0 & 0x0000_0010) != 0
}
/// Client/Server supports Protocol 4.1
pub const fn support_41_protocol(&self) -> bool {
(self.0 & 0x0000_0200) != 0
}
/// Set Protocol 4.1 support
pub fn set_support_41_protocol(&mut self) -> &mut Self {
self.0 |= 0x0000_0200;
self
}
/// Server can be connected with SSL/Client will connect with SSL
pub const fn support_ssl(&self) -> bool {
(self.0 & 0x0000_0800) != 0
}
/// Set to client will connect with SSL
pub fn set_support_ssl(&mut self) -> &mut Self {
self.0 |= 0x0000_0800;
self
}
/// Expects client to receive status flags in EOF Packet
pub const fn support_transaction(&self) -> bool {
(self.0 & 0x0000_2000) != 0
}
/// Supports Native41 Authentication Method
pub const fn support_secure_connection(&self) -> bool {
(self.0 & 0x0000_8000) != 0
}
/// Set to support Native41 Authentication Method
pub fn set_support_secure_connection(&mut self) -> &mut Self {
self.0 |= 0x0000_8000;
self
}
/// Supports authentication plugin
pub const fn support_plugin_auth(&self) -> bool {
(self.0 & 0x0008_0000) != 0
}
/// Set to support authentication plugin
pub fn set_client_plugin_auth(&mut self) -> &mut Self {
self.0 |= 0x0008_0000;
self
}
/// Set to do not support authentication plugin
pub fn clear_plugin_auth(&mut self) -> &mut Self {
self.0 &= !0x0008_0000;
self
}
/// Connection Attributes included in Handshake Response packet
pub const fn support_connect_attrs(&self) -> bool {
(self.0 & 0x0010_0000) != 0
}
/// Set to include connection attributes in Handshake Response packet
pub fn set_client_connect_attrs(&mut self) -> &mut Self {
self.0 |= 0x0010_0000;
self
}
/// Set to do not include connection attributes in Handshake Response packet
pub fn clear_client_connect_attrs(&mut self) -> &mut Self {
self.0 &= !0x0010_0000;
self
}
/// Length of plugin auth response will be sent by Length-encoded integer
pub const fn support_plugin_auth_lenenc_client_data(&self) -> bool {
(self.0 & 0x0020_0000) != 0
}
/// Set to send Length of plugin auth response as Length-encoded integer
pub fn set_support_plugin_auth_lenenc_client_data(&mut self) -> &mut Self {
self.0 |= 0x0020_0000;
self
}
/// Supports to receive session state changes after a OK Packet
pub const fn support_session_track(&self) -> bool {
(self.0 & 0x0080_0000) != 0
}
/// Supports deprecated EOF Packets after Text resultset rows
pub const fn support_deprecate_eof(&self) -> bool {
(self.0 & 0x0100_0000) != 0
}
/// Set to support deprecated EOF Packets after Text resultset rows
pub fn set_support_deprecate_eof(&mut self) -> &mut Self {
self.0 |= 0x0100_0000;
self
}
}
impl std::fmt::Debug for CapabilityFlags {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:032b}", self.0)
}
}
impl std::ops::BitAnd for CapabilityFlags {
type Output = Self;
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}
impl std::ops::BitOr for CapabilityFlags {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}