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

Prefer byteorder in place of bincode #607

Merged
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
1 change: 1 addition & 0 deletions timely/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ getopts = ["getopts-dep", "timely_communication/getopts"]
[dependencies]
getopts-dep = { package = "getopts", version = "0.2.21", optional = true }
bincode = { version = "1.0" }
byteorder = "1.5"
serde = { version = "1.0", features = ["derive"] }
timely_bytes = { path = "../bytes", version = "0.12" }
timely_logging = { path = "../logging", version = "0.12" }
Expand Down
14 changes: 8 additions & 6 deletions timely/src/dataflow/channels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ where
C: ContainerBytes,
{
fn from_bytes(mut bytes: crate::bytes::arc::Bytes) -> Self {
use byteorder::ReadBytesExt;
let mut slice = &bytes[..];
let from: usize = ::bincode::deserialize_from(&mut slice).expect("bincode::deserialize() failed");
let seq: usize = ::bincode::deserialize_from(&mut slice).expect("bincode::deserialize() failed");
let from: usize = slice.read_u64::<byteorder::LittleEndian>().unwrap().try_into().unwrap();
let seq: usize = slice.read_u64::<byteorder::LittleEndian>().unwrap().try_into().unwrap();
let time: T = ::bincode::deserialize_from(&mut slice).expect("bincode::deserialize() failed");
let bytes_read = bytes.len() - slice.len();
bytes.extract_to(bytes_read);
Expand All @@ -75,15 +76,16 @@ where
}

fn length_in_bytes(&self) -> usize {
::bincode::serialized_size(&self.from).expect("bincode::serialized_size() failed") as usize +
::bincode::serialized_size(&self.seq).expect("bincode::serialized_size() failed") as usize +
// 16 comes from the two `u64` fields: `from` and `seq`.
16 +
::bincode::serialized_size(&self.time).expect("bincode::serialized_size() failed") as usize +
self.data.length_in_bytes()
}

fn into_bytes<W: ::std::io::Write>(&self, writer: &mut W) {
::bincode::serialize_into(&mut *writer, &self.from).expect("bincode::serialize_into() failed");
::bincode::serialize_into(&mut *writer, &self.seq).expect("bincode::serialize_into() failed");
use byteorder::WriteBytesExt;
writer.write_u64::<byteorder::LittleEndian>(self.from.try_into().unwrap()).unwrap();
writer.write_u64::<byteorder::LittleEndian>(self.seq.try_into().unwrap()).unwrap();
::bincode::serialize_into(&mut *writer, &self.time).expect("bincode::serialize_into() failed");
self.data.into_bytes(&mut *writer);
}
Expand Down
Loading