Drop byteorder dependency
We're only using it for read_u8 which is a bit silly
This commit is contained in:
parent
90c1279336
commit
599e5dbc69
@ -33,7 +33,6 @@ with-uuid = ["uuid"]
|
||||
|
||||
[dependencies]
|
||||
bufstream = "0.1"
|
||||
byteorder = "0.5"
|
||||
fallible-iterator = "0.1.3"
|
||||
hex = "0.2"
|
||||
log = "0.3"
|
||||
|
@ -43,7 +43,6 @@
|
||||
#![allow(unknown_lints, needless_lifetimes, doc_markdown)] // for clippy
|
||||
|
||||
extern crate bufstream;
|
||||
extern crate byteorder;
|
||||
extern crate fallible_iterator;
|
||||
extern crate hex;
|
||||
#[macro_use]
|
||||
|
@ -1,4 +1,3 @@
|
||||
use byteorder::ReadBytesExt;
|
||||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::fmt;
|
||||
@ -70,19 +69,21 @@ impl MessageStream {
|
||||
}
|
||||
|
||||
pub fn read_message(&mut self) -> io::Result<backend::Message> {
|
||||
let b = try!(self.stream.read_u8());
|
||||
self.inner_read_message(b)
|
||||
let mut b = [0; 1];
|
||||
try!(self.stream.read_exact(&mut b));
|
||||
self.inner_read_message(b[0])
|
||||
}
|
||||
|
||||
pub fn read_message_timeout(&mut self,
|
||||
timeout: Duration)
|
||||
-> io::Result<Option<backend::Message>> {
|
||||
try!(self.set_read_timeout(Some(timeout)));
|
||||
let b = self.stream.read_u8();
|
||||
let mut b = [0; 1];
|
||||
let r = self.stream.read_exact(&mut b);
|
||||
try!(self.set_read_timeout(None));
|
||||
|
||||
match b {
|
||||
Ok(b) => self.inner_read_message(b).map(Some),
|
||||
match r {
|
||||
Ok(()) => self.inner_read_message(b[0]).map(Some),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock ||
|
||||
e.kind() == io::ErrorKind::TimedOut => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
@ -91,11 +92,12 @@ impl MessageStream {
|
||||
|
||||
pub fn read_message_nonblocking(&mut self) -> io::Result<Option<backend::Message>> {
|
||||
try!(self.set_nonblocking(true));
|
||||
let b = self.stream.read_u8();
|
||||
let mut b = [0; 1];
|
||||
let r = self.stream.read_exact(&mut b);
|
||||
try!(self.set_nonblocking(false));
|
||||
|
||||
match b {
|
||||
Ok(b) => self.inner_read_message(b).map(Some),
|
||||
match r {
|
||||
Ok(()) => self.inner_read_message(b[0]).map(Some),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
@ -253,7 +255,9 @@ pub fn initialize_stream(params: &ConnectParams,
|
||||
try!(socket.write_all(&buf));
|
||||
try!(socket.flush());
|
||||
|
||||
if try!(socket.read_u8()) == b'N' {
|
||||
let mut b = [0; 1];
|
||||
try!(socket.read_exact(&mut b));
|
||||
if b[0] == b'N' {
|
||||
if tls_required {
|
||||
return Err(ConnectError::Tls("the server does not support TLS".into()));
|
||||
} else {
|
||||
|
@ -2,7 +2,6 @@ extern crate rustc_serialize;
|
||||
|
||||
use self::rustc_serialize::json;
|
||||
use std::io::{Cursor, Write};
|
||||
use byteorder::ReadBytesExt;
|
||||
use std::error::Error;
|
||||
|
||||
use types::{FromSql, ToSql, IsNull, Type, SessionInfo};
|
||||
@ -14,8 +13,10 @@ impl FromSql for json::Json {
|
||||
-> Result<json::Json, Box<Error + Sync + Send>> {
|
||||
let mut raw = Cursor::new(raw);
|
||||
if let Type::Jsonb = *ty {
|
||||
let mut b = [0; 1];
|
||||
try!(raw.read_exact(&mut b));
|
||||
// We only support version 1 of the jsonb binary format
|
||||
if try!(raw.read_u8()) != 1 {
|
||||
if b[0] != 1 {
|
||||
return Err("unsupported JSONB encoding version".into());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
extern crate serde_json;
|
||||
|
||||
use byteorder::ReadBytesExt;
|
||||
use self::serde_json::Value;
|
||||
use std::error::Error;
|
||||
use std::io::Write;
|
||||
@ -13,8 +12,10 @@ impl FromSql for Value {
|
||||
_: &SessionInfo)
|
||||
-> Result<Value, Box<Error + Sync + Send>> {
|
||||
if let Type::Jsonb = *ty {
|
||||
let mut b = [0; 1];
|
||||
try!(raw.read_exact(&mut b));
|
||||
// We only support version 1 of the jsonb binary format
|
||||
if try!(raw.read_u8()) != 1 {
|
||||
if b[0] != 1 {
|
||||
return Err("unsupported JSONB encoding version".into());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user