Skip to content

Commit

Permalink
Remove Read and Write taits
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeam committed Nov 2, 2019
1 parent 9a3d317 commit b28a682
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 83 deletions.
3 changes: 2 additions & 1 deletion src/conn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use mysql_common::crypto;
use mysql_common::io::ReadMysqlExt;
use mysql_common::named_params::parse_named_params;
use mysql_common::packets::{
column_from_payload, parse_auth_switch_request, parse_err_packet, parse_handshake_packet,
Expand All @@ -21,7 +22,7 @@ use crate::conn::stmt::InnerStmt;
use crate::conn::stmt_cache::StmtCache;
use crate::conn::transaction::IsolationLevel;
use crate::consts::{CapabilityFlags, Command, StatusFlags, MAX_PAYLOAD_LEN};
use crate::io::{Read as MyRead, Stream};
use crate::io::Stream;
use crate::prelude::FromRow;
use crate::DriverError::{
CouldNotConnect, MismatchedStmtParams, NamedParamsForPositionalQuery, Protocol41NotSet,
Expand Down
82 changes: 0 additions & 82 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bufstream::BufStream;
use byteorder::{LittleEndian as LE, ReadBytesExt, WriteBytesExt};
use io_enum::*;
#[cfg(windows)]
use named_pipe as np;
Expand All @@ -20,87 +19,6 @@ use crate::SslOpts;

mod tcp;

pub trait Read: ReadBytesExt + io::BufRead {
fn read_lenenc_int(&mut self) -> io::Result<u64> {
let head_byte = self.read_u8()?;
let length = match head_byte {
0xfc => 2,
0xfd => 3,
0xfe => 8,
x => return Ok(u64::from(x)),
};
let out = self.read_uint::<LE>(length)?;
Ok(out)
}

fn read_lenenc_bytes(&mut self) -> io::Result<Vec<u8>> {
let len = self.read_lenenc_int()?;
let mut out = Vec::with_capacity(len as usize);
let count = if len > 0 {
self.take(len).read_to_end(&mut out)?
} else {
0
};
if count as u64 == len {
Ok(out)
} else {
Err(io::Error::new(
io::ErrorKind::Other,
"Unexpected EOF while reading length encoded string",
))
}
}

fn read_to_null(&mut self) -> io::Result<Vec<u8>> {
let mut out = Vec::new();
for c in self.bytes() {
let c = c?;
if c == 0 {
break;
}
out.push(c);
}
Ok(out)
}
}

impl<T: ReadBytesExt + io::BufRead> Read for T {}

pub trait Write: WriteBytesExt {
fn write_le_uint_n(&mut self, x: u64, len: usize) -> io::Result<()> {
let mut buf = [0u8; 8];
let mut offset = 0;
while offset < len {
buf[offset] = (((0xFF << (offset * 8)) & x) >> (offset * 8)) as u8;
offset += 1;
}
self.write_all(&buf[..len])
}

fn write_lenenc_int(&mut self, x: u64) -> io::Result<()> {
if x < 251 {
self.write_u8(x as u8)?;
Ok(())
} else if x < 65_536 {
self.write_u8(0xFC)?;
self.write_le_uint_n(x, 2)
} else if x < 16_777_216 {
self.write_u8(0xFD)?;
self.write_le_uint_n(x, 3)
} else {
self.write_u8(0xFE)?;
self.write_le_uint_n(x, 8)
}
}

fn write_lenenc_bytes(&mut self, bytes: &[u8]) -> io::Result<()> {
self.write_lenenc_int(bytes.len() as u64)?;
self.write_all(bytes)
}
}

impl<T: WriteBytesExt> Write for T {}

#[derive(Debug, Read, Write)]
pub enum Stream {
#[cfg(unix)]
Expand Down

0 comments on commit b28a682

Please sign in to comment.