Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bytes to 0.6 #387

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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.8", 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
48 changes: 24 additions & 24 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 @@ -29,31 +29,33 @@ where
{
// 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;
// - ptr::write is an unsafe raw pointer write. The use here is safe since the length of the
// uninit slice is checked.
// - 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.
unsafe {
let mut i;
'outer: loop {
i = 0;

let uninit_slice = buf.bytes_mut();
for offset in 0..uninit_slice.len() {
i += 1;
let ptr = uninit_slice.as_mut_ptr().add(offset);
if value < 0x80 {
ptr.write(value as u8);
break 'outer;
} else {
ptr.write(((value & 0x7F) | 0x80) as u8);
value >>= 7;
}
}
}

unsafe {
buf.advance_mut(i);
debug_assert!(buf.has_remaining_mut());
}
debug_assert!(buf.has_remaining_mut());
}

unsafe {
buf.advance_mut(i);
}
}
Expand Down Expand Up @@ -915,9 +917,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