Skip to main content

PacketReader

Struct PacketReader 

Source
pub struct PacketReader<'a> { /* private fields */ }
Expand description

A reader for MySQL protocol data.

Implementations§

Source§

impl<'a> PacketReader<'a>

Source

pub fn new(data: &'a [u8]) -> Self

Create a new reader from a byte slice.

Source

pub fn remaining(&self) -> usize

Get remaining bytes in the buffer.

Source

pub fn is_empty(&self) -> bool

Check if we’ve reached the end of the data.

Source

pub fn peek(&self) -> Option<u8>

Peek at the next byte without advancing.

Source

pub fn read_u8(&mut self) -> Option<u8>

Read a single byte.

Source

pub fn read_u16_le(&mut self) -> Option<u16>

Read a u16 (little-endian).

Source

pub fn read_u24_le(&mut self) -> Option<u32>

Read a u24 (little-endian, 3 bytes).

Source

pub fn read_u32_le(&mut self) -> Option<u32>

Read a u32 (little-endian).

Source

pub fn read_u64_le(&mut self) -> Option<u64>

Read a u64 (little-endian).

Source

pub fn read_lenenc_int(&mut self) -> Option<u64>

Read a length-encoded integer.

MySQL uses a variable-length integer encoding:

  • 0x00-0xFA: 1-byte value
  • 0xFC: 2-byte value follows
  • 0xFD: 3-byte value follows
  • 0xFE: 8-byte value follows
  • 0xFB: NULL (special case for length-encoded strings)
Source

pub fn read_lenenc_string(&mut self) -> Option<String>

Read a length-encoded string.

Source

pub fn read_lenenc_bytes(&mut self) -> Option<Vec<u8>>

Read a length-encoded byte slice.

Source

pub fn read_null_string(&mut self) -> Option<String>

Read a null-terminated string.

Source

pub fn read_string(&mut self, len: usize) -> Option<String>

Read a fixed-length string.

Source

pub fn read_rest_string(&mut self) -> String

Read remaining data as a string.

Source

pub fn read_bytes(&mut self, len: usize) -> Option<&'a [u8]>

Read a fixed number of bytes.

Source

pub fn read_rest(&mut self) -> &'a [u8]

Read remaining bytes.

Source

pub fn skip(&mut self, n: usize) -> bool

Skip a number of bytes.

Source

pub fn read_packet_header(&mut self) -> Option<PacketHeader>

Read a packet header from raw bytes.

Source

pub fn parse_ok_packet(&mut self) -> Option<OkPacket>

Parse an OK packet from the current position.

OK packet format (protocol 4.1+):

  • 0x00 header (already consumed)
  • affected_rows: lenenc int
  • last_insert_id: lenenc int
  • status_flags: 2 bytes
  • warnings: 2 bytes
  • info: rest of packet (optional)
Source

pub fn parse_err_packet(&mut self) -> Option<ErrPacket>

Parse an Error packet from the current position.

ERR packet format (protocol 4.1+):

  • 0xFF header (already consumed)
  • error_code: 2 bytes
  • ‘#’ marker
  • sql_state: 5 bytes
  • error_message: rest of packet
Source

pub fn parse_eof_packet(&mut self) -> Option<EofPacket>

Parse an EOF packet from the current position.

EOF packet format:

  • 0xFE header (already consumed)
  • warnings: 2 bytes
  • status_flags: 2 bytes

Trait Implementations§

Source§

impl<'a> Debug for PacketReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PacketReader<'a>

§

impl<'a> RefUnwindSafe for PacketReader<'a>

§

impl<'a> Send for PacketReader<'a>

§

impl<'a> Sync for PacketReader<'a>

§

impl<'a> Unpin for PacketReader<'a>

§

impl<'a> UnwindSafe for PacketReader<'a>

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> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more