mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
Move deserialize into it's own file
This commit is contained in:
parent
d1d3ba6cb4
commit
1480bed73a
@ -1,2 +1,3 @@
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
pub mod deserialize;
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use failure::{Error, err_msg};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use crate::protocol::deserialize::*;
|
||||
|
||||
pub trait Deserialize: Sized {
|
||||
fn deserialize(buf: &mut Vec<u8>) -> Result<Self, Error>;
|
||||
@ -62,6 +63,15 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum SessionChangeType {
|
||||
SessionTrackSystemVariables = 0,
|
||||
SessionTrackSchema = 1,
|
||||
SessionTrackStateChange = 2,
|
||||
SessionTrackGTIDS = 3,
|
||||
SessionTrackTransactionCharacteristics = 4,
|
||||
SessionTrackTransactionState = 5,
|
||||
}
|
||||
|
||||
impl Default for Capabilities {
|
||||
fn default() -> Self {
|
||||
Capabilities::CLIENT_MYSQL
|
||||
@ -202,49 +212,6 @@ impl Deserialize for InitialHandshakePacket {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_int_lenenc(buf: &Vec<u8>, index: &usize) -> (Option<usize>, usize) {
|
||||
match buf[*index] {
|
||||
0xFB => (None, *index + 1),
|
||||
0xFC => (Some(LittleEndian::read_u16(&buf[*index + 1..]) as usize), *index + 2),
|
||||
0xFD => (Some((buf[*index + 1] + buf[*index + 2] << 8 + buf[*index + 3] << 16) as usize), *index + 3),
|
||||
0xFE => (Some(LittleEndian::read_u64(&buf[*index..]) as usize), *index + 8),
|
||||
0xFF => panic!("int<lenenc> unprocessable first byte 0xFF"),
|
||||
_ => (Some(buf[*index] as usize), *index + 1),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_int_3(buf: &Vec<u8>, index: &usize) -> (u32, usize) {
|
||||
((buf[*index] + buf[index + 1] << 8 + buf[*index + 2] << 16) as u32, index + 3)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_int_2(buf: &Vec<u8>, index: &usize) -> (u16, usize) {
|
||||
(LittleEndian::read_u16(&buf[*index..]), index + 2)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_int_1(buf: &Vec<u8>, index: &usize) -> (u8, usize) {
|
||||
(buf[*index], index + 1)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_string_lenenc(buf: &Vec<u8>, index: &usize) -> (Bytes, usize) {
|
||||
let (length, index) = deserialize_int_3(&buf, &index);
|
||||
(Bytes::from(&buf[index..index + length as usize]), index + length as usize)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_string_fix(buf: &Vec<u8>, index: &usize, length: usize) -> (Bytes, usize) {
|
||||
(Bytes::from(&buf[*index..index + length as usize]), index + length as usize)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn deserialize_string_eof(buf: &Vec<u8>, index: &usize) -> (Bytes, usize) {
|
||||
(Bytes::from(&buf[*index..]), buf.len())
|
||||
}
|
||||
|
||||
impl Deserialize for OkPacket {
|
||||
fn deserialize(buf: &mut Vec<u8>) -> Result<Self, Error> {
|
||||
let mut index = 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user