Skip to content

Commit

Permalink
Update bytes to 0.6
Browse files Browse the repository at this point in the history
This change updates the `bytes` crate dependencies to version 0.6.

Fixes https://github.com/danburkert/prost/issues/380
  • Loading branch information
olix0r committed Nov 7, 2020
1 parent 4ded4a9 commit 41c2aa3
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ no-recursion-limit = []
std = []

[dependencies]
bytes = { version = "0.5", default-features = false }
bytes = { version = "0.6", default-features = false }
prost-derive = { version = "0.6.1", path = "prost-derive", optional = true }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion conformance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false
edition = "2018"

[dependencies]
bytes = "0.5"
bytes = "0.6"
env_logger = { version = "0.7", default-features = false }
log = "0.4"
prost = { path = ".." }
Expand Down
2 changes: 1 addition & 1 deletion prost-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "A Protocol Buffers implementation for the Rust Language."
edition = "2018"

[dependencies]
bytes = { version = "0.5", default-features = false }
bytes = { version = "0.6", default-features = false }
heck = "0.3"
itertools = "0.9"
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion prost-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default = ["std"]
std = ["prost/std"]

[dependencies]
bytes = { version = "0.5", default-features = false }
bytes = { version = "0.6", default-features = false }
prost = { version = "0.6.1", path = "..", default-features = false, features = ["prost-derive"] }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion protobuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false
edition = "2018"

[dependencies]
bytes = { version = "0.5", default-features = false }
bytes = { version = "0.6", default-features = false }
prost = { path = ".." }
prost-types = { path = "../prost-types" }

Expand Down
40 changes: 9 additions & 31 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::str;
use core::u32;
use core::usize;

use ::bytes::{buf::ext::BufExt, Buf, BufMut, Bytes};
use ::bytes::{Buf, BufMut, Bytes};

use crate::DecodeError;
use crate::Message;
Expand All @@ -27,34 +27,14 @@ pub fn encode_varint<B>(mut value: u64, buf: &mut B)
where
B: BufMut,
{
// Safety notes:
//
// - advance_mut is unsafe because it could cause uninitialized memory to be
// advanced over. The use here is safe since each byte which is advanced over
// has been written to in the previous loop iteration.
let mut i;
'outer: loop {
i = 0;

for byte in buf.bytes_mut() {
i += 1;
if value < 0x80 {
*byte = mem::MaybeUninit::new(value as u8);
break 'outer;
} else {
*byte = mem::MaybeUninit::new(((value & 0x7F) | 0x80) as u8);
value >>= 7;
}
}

unsafe {
buf.advance_mut(i);
while buf.remaining_mut() > 0 {
if value < 0x80 {
buf.put_u8(value as u8);
return;
} else {
buf.put_u8(((value & 0x7F) | 0x80) as u8);
value >>= 7;
}
debug_assert!(buf.has_remaining_mut());
}

unsafe {
buf.advance_mut(i);
}
}

Expand Down Expand Up @@ -907,9 +887,7 @@ impl sealed::BytesAdapter for Bytes {
where
B: Buf,
{
// TODO(tokio-rs/bytes#374): use a get_bytes(..)-like API to enable zero-copy merge
// when possible.
*self = buf.to_bytes();
*self = buf.copy_to_bytes(buf.remaining());
}

fn append_to<B>(&self, buf: &mut B)
Expand Down
2 changes: 1 addition & 1 deletion tests-2015/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std = []

[dependencies]
anyhow = "1"
bytes = "0.5"
bytes = "0.6"
cfg-if = "0.1"
prost = { path = ".." }
prost-types = { path = "../prost-types" }
Expand Down
2 changes: 1 addition & 1 deletion tests-no-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "../tests/src/lib.rs"

[dependencies]
anyhow = { version = "1", default-features = false }
bytes = { version = "0.5", default-features = false }
bytes = { version = "0.6", default-features = false }
cfg-if = "0.1"
prost = { path = "..", default-features = false, features = ["prost-derive"] }
prost-types = { path = "../prost-types", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std = []

[dependencies]
anyhow = "1"
bytes = "0.5"
bytes = "0.6"
cfg-if = "0.1"
prost = { path = ".." }
prost-types = { path = "../prost-types" }
Expand Down

0 comments on commit 41c2aa3

Please sign in to comment.