pub struct Buffer { /* private fields */ }Expand description
A client packet payload under construction.
Holds only the payload; framing is added by frame when the connection
knows which sequence id the packet must carry.
Implementations§
Source§impl Buffer
impl Buffer
pub fn new() -> Self
pub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn u8(&mut self, value: u8) -> &mut Self
pub fn u16(&mut self, value: u16) -> &mut Self
pub fn u32(&mut self, value: u32) -> &mut Self
pub fn u64(&mut self, value: u64) -> &mut Self
pub fn raw(&mut self, value: &[u8]) -> &mut Self
Sourcepub fn lenenc_int(&mut self, value: u64) -> &mut Self
pub fn lenenc_int(&mut self, value: u64) -> &mut Self
A length-encoded integer: one byte for the small values that dominate a result set, and a marker byte plus 2, 3 or 8 bytes for the rest.
Sourcepub fn lenenc_bytes(&mut self, value: &[u8]) -> &mut Self
pub fn lenenc_bytes(&mut self, value: &[u8]) -> &mut Self
A length-encoded byte string.
Sourcepub fn ssl_request(&mut self, capabilities: u32) -> &mut Self
pub fn ssl_request(&mut self, capabilities: u32) -> &mut Self
The SSLRequest packet: the first 32 bytes of a handshake response, and
nothing else.
It is deliberately the same prefix as Buffer::handshake_response,
because that is what the protocol says it is — the server reads this
much, sees CLIENT_SSL, and starts a TLS handshake instead of reading
on. The credentials then go inside the tunnel, in a second packet that
repeats these 32 bytes and continues past them.
Sourcepub fn handshake_response(
&mut self,
capabilities: u32,
user: &str,
auth_response: &[u8],
database: Option<&str>,
plugin: &str,
attributes: &[(&str, &str)],
) -> &mut Self
pub fn handshake_response( &mut self, capabilities: u32, user: &str, auth_response: &[u8], database: Option<&str>, plugin: &str, attributes: &[(&str, &str)], ) -> &mut Self
The reply to the server’s handshake: capabilities, then credentials.
Sourcepub fn auth_response(&mut self, data: &[u8]) -> &mut Self
pub fn auth_response(&mut self, data: &[u8]) -> &mut Self
The reply to an AuthSwitchRequest, or the extra data a plugin needs.
It is a bare payload with no command byte: the server already knows what it asked for.
Sourcepub fn com_query(&mut self, sql: &str) -> &mut Self
pub fn com_query(&mut self, sql: &str) -> &mut Self
A statement executed as text. No parameters, so it is reserved for DDL and transaction control.
Sourcepub fn com_ping(&mut self) -> &mut Self
pub fn com_ping(&mut self) -> &mut Self
Ask the server whether it is still there. Used to check a pooled connection without the cost of a round trip through the parser.
pub fn com_quit(&mut self) -> &mut Self
Sourcepub fn com_stmt_prepare(&mut self, sql: &str) -> &mut Self
pub fn com_stmt_prepare(&mut self, sql: &str) -> &mut Self
Ask the server to parse a statement and hand back a handle for it.
Sourcepub fn com_stmt_execute(
&mut self,
statement_id: u32,
params: &[Value],
) -> &mut Self
pub fn com_stmt_execute( &mut self, statement_id: u32, params: &[Value], ) -> &mut Self
Run a prepared statement with values bound out of band.
The values travel as typed binary in their own section of the packet and are never spliced into the statement text, which is what makes injection structurally impossible rather than a matter of remembering to escape.
Sourcepub fn com_stmt_close(&mut self, statement_id: u32) -> &mut Self
pub fn com_stmt_close(&mut self, statement_id: u32) -> &mut Self
Release a prepared statement’s server-side resources.
The server sends nothing back, so a connection that skips this leaks a handle for the life of the session.