From 6f8b2edead7581c7ee90efab2188045c22f6938b Mon Sep 17 00:00:00 2001 From: Daniel Akhterov Date: Tue, 6 Aug 2019 18:13:35 -0700 Subject: [PATCH] WIP: Test --- src/mariadb/connection/establish.rs | 5 +- src/mariadb/connection/mod.rs | 1 + src/mariadb/protocol/packets/result_set.rs | 94 +++++++++++++++++++++- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/mariadb/connection/establish.rs b/src/mariadb/connection/establish.rs index 942c583c..c793586e 100644 --- a/src/mariadb/connection/establish.rs +++ b/src/mariadb/connection/establish.rs @@ -6,7 +6,7 @@ use crate::{ }, options::ConnectOptions, }; -use bytes::{BufMut, Bytes}; +use bytes::Bytes; use failure::{err_msg, Error}; use std::ops::BitAnd; @@ -166,6 +166,9 @@ mod test { ctx.columns = Some(prepared.ok.columns as u64); ctx.column_defs = prepared.res_columns; + println!("{:?}", ctx.columns); + println!("{:?}", ctx.column_defs); + match ctx.decoder.peek_tag() { 0xFF => { ErrPacket::decode(&mut ctx)?; diff --git a/src/mariadb/connection/mod.rs b/src/mariadb/connection/mod.rs index dcbaca73..4a39f255 100644 --- a/src/mariadb/connection/mod.rs +++ b/src/mariadb/connection/mod.rs @@ -197,6 +197,7 @@ impl Framed { let mut packet_headers: Vec = Vec::new(); loop { + println!("BUF: {:?}: ", self.buf); // If we don't have a packet header or the last packet header had a length of // 0xFF_FF_FF (the max possible length); then we must continue receiving packets // because the entire message hasn't been received. diff --git a/src/mariadb/protocol/packets/result_set.rs b/src/mariadb/protocol/packets/result_set.rs index 42001a78..e9c77437 100644 --- a/src/mariadb/protocol/packets/result_set.rs +++ b/src/mariadb/protocol/packets/result_set.rs @@ -121,7 +121,7 @@ mod test { }; #[runtime::test] - async fn it_decodes_result_set_packet() -> Result<(), Error> { + async fn it_decodes_result_set_text_packet() -> Result<(), Error> { // TODO: Use byte string as input for test; this is a valid return from a mariadb. #[rustfmt::skip] let buf = __bytes_builder!( @@ -339,4 +339,96 @@ mod test { Ok(()) } + + #[runtime::test] + fn it_decodes_result_set_binary_packet() -> Result<(), Error> { + #[rustfmt::skip] + let buf = __bytes_builder!( + // ------------------- // + // Column Count packet // + // ------------------- // + // int<3> length + 1u8, 0u8, 0u8, + // int<1> seq_no + 1u8, + // int tag code or length + 4u8, + + // ------------------------ // + // Column Definition packet // + // ------------------------ // + // int<3> length + 40u8, 0u8, 0u8, + // int<1> seq_no + 5u8, + // string catalog (always 'def') + 3u8, b"def", + // string schema + 4u8, b"test", + // string table alias + 5u8, b"users", + // string table + 5u8, b"users", + // string column alias + 2u8, b"id", + // string column + 2u8, b"id", + // int length of fixed fields (=0xC) + 0x0C_u8, + // int<2> character set number + 8u8, 0u8, + // int<4> max. column size + 0x80, 0u8, 0u8, 0u8, + // int<1> Field types + 0xFD_u8, + // int<2> Field detail flag + 3u8, 64u8, + // int<1> decimals + 0u8, + // int<2> - unused - + 0u8, 0u8, + + // ---------- // + // EOF Packet // + // ---------- // + // int<3> length + 5u8, 0u8, 0u8, + // int<1> seq_no + 3u8, + // int<1> 0xfe : EOF header + 0xFE_u8, + // int<2> warning count + 0u8, 0u8, + // int<2> server status + 34u8, 0u8, + + // ----------------- // + // Result Row Packet // + // ----------------- // + // int<3> length + 39u8, 0u8, 0u8, + // int<1> seq_no + 4u8, + // byte<1> 0x00 header + 0u8, + // byte<(number_of_columns + 9) / 8> NULL-Bitmap + 0u8, + // byte encoded result + 36u8, b"d83dd1c4-ada9-11e9-96bc-0242ac110003", + + // ---------- // + // EOF Packet // + // ---------- // + // int<3> length + 5u8, 0u8, 0u8, + // int<1> seq_no + 5u8, + // int<1> 0xfe : EOF header + 0xFE_u8, + // int<2> warning count + 0u8, 0u8, + // int<2> server status + 34u8, 0u8 + ); + } }