-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathlocal_infile.rs
More file actions
37 lines (29 loc) · 1020 Bytes
/
local_infile.rs
File metadata and controls
37 lines (29 loc) · 1020 Bytes
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
use bytes::{Buf, Bytes};
use sqlx_core::io::{BufExt, ProtocolDecode};
use crate::error::Error;
/// Requests the client to send a file to the server, following a LOCAL INFILE statement
///
/// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_query_response_local_infile_request.html
#[derive(Debug)]
pub struct LocalInfilePacket {
pub filename: Vec<u8>,
}
impl ProtocolDecode<'_> for LocalInfilePacket {
fn decode_with(mut buf: Bytes, _: ()) -> Result<Self, Error> {
let header = buf.get_u8();
if header != 0xfb {
return Err(err_protocol!(
"expected 0xfb (LocalInfileRequest) but found 0x{:02x}",
header
));
}
let filename = buf.get_bytes(buf.len()).to_vec();
Ok(Self { filename })
}
}
#[test]
fn test_decode_localinfile_packet() {
const DATA: &[u8] = b"\xfb\x64\x75\x6d\x6d\x79";
let p = LocalInfilePacket::decode(DATA.into()).unwrap();
assert_eq!(p.filename, b"dummy");
}