From 1480bed73acf1c1d0d099c3054c9c8e688024429 Mon Sep 17 00:00:00 2001 From: Daniel Akhterov Date: Fri, 14 Jun 2019 19:11:05 -0700 Subject: [PATCH] Move deserialize into it's own file --- mason-mariadb/src/protocol/mod.rs | 1 + mason-mariadb/src/protocol/server.rs | 53 ++++++---------------------- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/mason-mariadb/src/protocol/mod.rs b/mason-mariadb/src/protocol/mod.rs index c07f47e0..85fb3773 100644 --- a/mason-mariadb/src/protocol/mod.rs +++ b/mason-mariadb/src/protocol/mod.rs @@ -1,2 +1,3 @@ pub mod client; pub mod server; +pub mod deserialize; diff --git a/mason-mariadb/src/protocol/server.rs b/mason-mariadb/src/protocol/server.rs index ab67a9c5..f5824a04 100644 --- a/mason-mariadb/src/protocol/server.rs +++ b/mason-mariadb/src/protocol/server.rs @@ -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) -> Result; @@ -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, index: &usize) -> (Option, 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 unprocessable first byte 0xFF"), - _ => (Some(buf[*index] as usize), *index + 1), - } -} - -#[inline] -fn deserialize_int_3(buf: &Vec, 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, index: &usize) -> (u16, usize) { - (LittleEndian::read_u16(&buf[*index..]), index + 2) -} - -#[inline] -fn deserialize_int_1(buf: &Vec, index: &usize) -> (u8, usize) { - (buf[*index], index + 1) -} - -#[inline] -fn deserialize_string_lenenc(buf: &Vec, 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, 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, index: &usize) -> (Bytes, usize) { - (Bytes::from(&buf[*index..]), buf.len()) -} - impl Deserialize for OkPacket { fn deserialize(buf: &mut Vec) -> Result { let mut index = 1;