Skip to content

Commit

Permalink
WIP: bytes 0.5 compat
Browse files Browse the repository at this point in the history
captured.rs is still broken, see NLnetLabs#42

Signed-off-by: Fabian Grünbichler <[email protected]>
  • Loading branch information
Fabian Grünbichler authored and Fabian-Gruenbichler committed Mar 5, 2020
1 parent d968e40 commit 4f2ca86
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "BSD-3-Clause"

[dependencies]
backtrace = { version = "^0.3.15", optional = true }
bytes = "^0.4"
bytes = "^0.5"
smallvec = "^0.6.10"
unwrap = "^1.2.1"

Expand Down
6 changes: 3 additions & 3 deletions src/decode/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Source for Bytes {
Err(Error::Malformed)
}
else {
self.advance(len);
bytes::Buf::advance(self, len);
Ok(())
}
}
Expand All @@ -135,7 +135,7 @@ impl Source for Bytes {
}

fn bytes(&self, start: usize, end: usize) -> Bytes {
self.slice(start, end)
self.slice(start..end)
}
}

Expand All @@ -161,7 +161,7 @@ impl<'a> Source for &'a [u8] {
}

fn bytes(&self, start: usize, end: usize) -> Bytes {
Bytes::from(&self[start..end])
Bytes::copy_from_slice(&self[start..end])
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/encode/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//! parent.
use std::io;
use bytes::{BufMut, Bytes, BytesMut};
use bytes::{Bytes, BytesMut};
use bytes::buf::ext::BufMutExt;
use crate::length::Length;
use crate::mode::Mode;
use crate::tag::Tag;
Expand Down
7 changes: 4 additions & 3 deletions src/string/octet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ impl decode::Source for OctetStringSource {
fn request(&mut self, len: usize) -> Result<usize, decode::Error> {
if self.current.len() < len && !self.remainder.is_empty() {
// Make a new current that is at least `len` long.
let mut current = BytesMut::from(self.current.clone());
let mut current = BytesMut::with_capacity(self.current.len());
current.extend_from_slice(&self.current.clone());
while current.len() < len {
if let Some(bytes) = self.next_primitive() {
current.extend_from_slice(bytes.as_ref())
Expand All @@ -554,7 +555,7 @@ impl decode::Source for OctetStringSource {
}
}
}
self.current.advance(len);
self.current.advance(len)?;
Ok(())
}

Expand All @@ -563,7 +564,7 @@ impl decode::Source for OctetStringSource {
}

fn bytes(&self, start: usize, end: usize) -> Bytes {
self.current.slice(start, end)
self.current.slice(start..end)
}
}

Expand Down

0 comments on commit 4f2ca86

Please sign in to comment.