sqlx_core/mysql/protocol/response/
eof.rs

1use bytes::{Buf, Bytes};
2
3use crate::error::Error;
4use crate::io::Decode;
5use crate::mysql::protocol::response::Status;
6use crate::mysql::protocol::Capabilities;
7
8/// Marks the end of a result set, returning status and warnings.
9///
10/// # Note
11///
12/// The EOF packet is deprecated as of MySQL 5.7.5. SQLx only uses this packet for MySQL
13/// prior MySQL versions.
14#[derive(Debug)]
15pub struct EofPacket {
16    pub warnings: u16,
17    pub status: Status,
18}
19
20impl Decode<'_, Capabilities> for EofPacket {
21    fn decode_with(mut buf: Bytes, _: Capabilities) -> Result<Self, Error> {
22        let header = buf.get_u8();
23        if header != 0xfe {
24            return Err(err_protocol!(
25                "expected 0xfe (EOF_Packet) but found 0x{:x}",
26                header
27            ));
28        }
29
30        let warnings = buf.get_u16_le();
31        let status = Status::from_bits_truncate(buf.get_u16_le());
32
33        Ok(Self { status, warnings })
34    }
35}