Skip to main content

Buffer

Struct Buffer 

Source
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

Source

pub fn new() -> Self

Source

pub fn into_bytes(self) -> Vec<u8>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn u8(&mut self, value: u8) -> &mut Self

Source

pub fn u16(&mut self, value: u16) -> &mut Self

Source

pub fn u32(&mut self, value: u32) -> &mut Self

Source

pub fn u64(&mut self, value: u64) -> &mut Self

Source

pub fn raw(&mut self, value: &[u8]) -> &mut Self

Source

pub fn cstr(&mut self, value: &str) -> &mut Self

A NUL-terminated string.

Source

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.

Source

pub fn lenenc_bytes(&mut self, value: &[u8]) -> &mut Self

A length-encoded byte string.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn com_quit(&mut self) -> &mut Self

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for Buffer

Source§

fn default() -> Buffer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.