Update to bytes v0.5

Except for `multiaddr` which encapsulates its use of bytes v0.4 now.
This commit is contained in:
Toralf Wittner
2019-12-21 15:35:55 +01:00
parent 589fdafdda
commit 2bc8d9590d
25 changed files with 72 additions and 105 deletions

View File

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use bytes::{Bytes, BytesMut, BufMut};
use bytes::{Bytes, BytesMut, Buf, BufMut};
use futures::{try_ready, Async, Poll, Sink, StartSend, Stream, AsyncSink};
use std::{io, u16};
use tokio_io::{AsyncRead, AsyncWrite};
@ -136,7 +136,7 @@ impl<R> LengthDelimited<R> {
"Failed to write buffered frame."))
}
self.write_buffer.split_to(n);
self.write_buffer.advance(n);
}
Ok(Async::Ready(()))

View File

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use bytes::BytesMut;
use bytes::{BytesMut, Buf};
use crate::protocol::{Protocol, MessageReader, Message, Version, ProtocolError};
use futures::{prelude::*, Async, try_ready};
use log::debug;
@ -93,7 +93,7 @@ impl<TInner> Negotiated<TInner> {
}
if let State::Completed { remaining, .. } = &mut self.state {
let _ = remaining.take(); // Drop remaining data flushed above.
let _ = remaining.split_to(remaining.len()); // Drop remaining data flushed above.
return Ok(Async::Ready(()))
}
@ -232,7 +232,7 @@ where
if n == 0 {
return Err(io::ErrorKind::WriteZero.into())
}
remaining.split_to(n);
remaining.advance(n);
}
io.write(buf)
},
@ -251,7 +251,7 @@ where
io::ErrorKind::WriteZero,
"Failed to write remaining buffer."))
}
remaining.split_to(n);
remaining.advance(n);
}
io.flush()
},
@ -363,7 +363,7 @@ mod tests {
let cap = rem.len() + free as usize;
let step = u8::min(free, step) as usize + 1;
let buf = Capped { buf: Vec::with_capacity(cap), step };
let rem = BytesMut::from(rem);
let rem = BytesMut::from(&rem[..]);
let mut io = Negotiated::completed(buf, rem.clone());
let mut written = 0;
loop {

View File

@ -143,7 +143,7 @@ impl TryFrom<&[u8]> for Protocol {
type Error = ProtocolError;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
Self::try_from(Bytes::from(value))
Self::try_from(Bytes::copy_from_slice(value))
}
}
@ -208,7 +208,7 @@ impl Message {
out_msg.push(b'\n')
}
dest.reserve(out_msg.len());
dest.put(out_msg);
dest.put(out_msg.as_ref());
Ok(())
}
Message::NotAvailable => {
@ -254,7 +254,7 @@ impl Message {
if len == 0 || len > rem.len() || rem[len - 1] != b'\n' {
return Err(ProtocolError::InvalidMessage)
}
let p = Protocol::try_from(Bytes::from(&rem[.. len - 1]))?;
let p = Protocol::try_from(Bytes::copy_from_slice(&rem[.. len - 1]))?;
protocols.push(p);
remaining = &rem[len ..]
}