mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Established connection!
This commit is contained in:
parent
89b89eaec7
commit
3679593f63
4 changed files with 13 additions and 19 deletions
|
@ -28,16 +28,14 @@ pub async fn establish<'a, 'b: 'a>(
|
|||
Err(failure::err_msg("Failed to connect"))
|
||||
}?;
|
||||
|
||||
// println!("{:?}", init_packet);
|
||||
|
||||
let handshake = HandshakeResponsePacket {
|
||||
server_capabilities: init_packet.capabilities,
|
||||
sequence_number: 0,
|
||||
capabilities: init_packet.capabilities,
|
||||
sequence_number: 1,
|
||||
capabilities: Capabilities::CLIENT_PROTOCOL_41,
|
||||
max_packet_size: 1024,
|
||||
collation: 0,
|
||||
extended_capabilities: Some(Capabilities::from_bits_truncate(0)),
|
||||
username: Bytes::from("username"),
|
||||
username: Bytes::from("root"),
|
||||
auth_data: None,
|
||||
auth_response_len: None,
|
||||
auth_response: None,
|
||||
|
@ -49,7 +47,6 @@ pub async fn establish<'a, 'b: 'a>(
|
|||
conn.send(handshake).await?;
|
||||
|
||||
if let Some(message) = conn.incoming.next().await {
|
||||
println!("{:?}", message);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(failure::err_msg("Handshake Failed"))
|
||||
|
|
|
@ -105,8 +105,6 @@ async fn receiver(
|
|||
break;
|
||||
}
|
||||
|
||||
println!("{:?}", rbuf);
|
||||
|
||||
while len > 0 {
|
||||
let size = rbuf.len();
|
||||
let message = if first_packet {
|
||||
|
|
|
@ -39,8 +39,8 @@ pub fn deserialize_int_lenenc(buf: &Bytes, index: &mut usize) -> Option<usize> {
|
|||
}
|
||||
0xFF => panic!("int<lenenc> unprocessable first byte 0xFF"),
|
||||
_ => {
|
||||
let value = Some(buf[*index + 1] as usize);
|
||||
*index += 2;
|
||||
let value = Some(buf[*index] as usize);
|
||||
*index += 1;
|
||||
value
|
||||
}
|
||||
}
|
||||
|
@ -198,12 +198,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn it_decodes_int_lenenc_0x_fa() {
|
||||
let buf = BytesMut::from(b"\xFA\x01".to_vec());
|
||||
let buf = BytesMut::from(b"\xFA".to_vec());
|
||||
let mut index = 0;
|
||||
let int: Option<usize> = deserialize_int_lenenc(&buf.freeze(), &mut index);
|
||||
|
||||
assert_eq!(int, Some(1));
|
||||
assert_eq!(index, 2);
|
||||
assert_eq!(int, Some(0xfA));
|
||||
assert_eq!(index, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -195,13 +195,11 @@ impl Message {
|
|||
let serial_number = [3];
|
||||
let tag = buf[4];
|
||||
|
||||
println!("{:?}", buf);
|
||||
|
||||
Ok(Some(match tag {
|
||||
0xFF => {
|
||||
Message::ErrPacket(ErrPacket::deserialize(&buf)?)
|
||||
}
|
||||
0x00 => {
|
||||
0x00 | 0xFE => {
|
||||
Message::OkPacket(OkPacket::deserialize(&buf)?)
|
||||
}
|
||||
_ => {
|
||||
|
@ -215,7 +213,6 @@ impl Message {
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
println!("length: {:?}", length);
|
||||
match InitialHandshakePacket::deserialize(&buf.split_to(length + 4).freeze()) {
|
||||
Ok(v) => Ok(Some(Message::InitialHandshakePacket(v))),
|
||||
Err(_) => Ok(None),
|
||||
|
@ -305,12 +302,14 @@ impl Deserialize for OkPacket {
|
|||
fn deserialize(buf: &Bytes) -> Result<Self, Error> {
|
||||
let mut index = 0;
|
||||
|
||||
// Packet header
|
||||
let length = deserialize_length(&buf, &mut index)?;
|
||||
let _sequence_number = deserialize_int_1(&buf, &mut index);
|
||||
|
||||
// Packet body
|
||||
let packet_header = deserialize_int_1(&buf, &mut index);
|
||||
if packet_header != 0 {
|
||||
panic!("Packet header is not 0 for OkPacket");
|
||||
if packet_header != 0 && packet_header != 0xFE {
|
||||
panic!("Packet header is not 0 or 0xFE for OkPacket");
|
||||
}
|
||||
|
||||
let affected_rows = deserialize_int_lenenc(&buf, &mut index);
|
||||
|
|
Loading…
Reference in a new issue