Skip to content

Commit 7a1ece7

Browse files
Prefer byteorder in place of bincode (#607)
1 parent ad037c3 commit 7a1ece7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

timely/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ getopts = ["getopts-dep", "timely_communication/getopts"]
2121
[dependencies]
2222
getopts-dep = { package = "getopts", version = "0.2.21", optional = true }
2323
bincode = { version = "1.0" }
24+
byteorder = "1.5"
2425
serde = { version = "1.0", features = ["derive"] }
2526
timely_bytes = { path = "../bytes", version = "0.12" }
2627
timely_logging = { path = "../logging", version = "0.12" }

timely/src/dataflow/channels/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ where
6464
C: ContainerBytes,
6565
{
6666
fn from_bytes(mut bytes: crate::bytes::arc::Bytes) -> Self {
67+
use byteorder::ReadBytesExt;
6768
let mut slice = &bytes[..];
68-
let from: usize = ::bincode::deserialize_from(&mut slice).expect("bincode::deserialize() failed");
69-
let seq: usize = ::bincode::deserialize_from(&mut slice).expect("bincode::deserialize() failed");
69+
let from: usize = slice.read_u64::<byteorder::LittleEndian>().unwrap().try_into().unwrap();
70+
let seq: usize = slice.read_u64::<byteorder::LittleEndian>().unwrap().try_into().unwrap();
7071
let time: T = ::bincode::deserialize_from(&mut slice).expect("bincode::deserialize() failed");
7172
let bytes_read = bytes.len() - slice.len();
7273
bytes.extract_to(bytes_read);
@@ -75,15 +76,16 @@ where
7576
}
7677

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

8485
fn into_bytes<W: ::std::io::Write>(&self, writer: &mut W) {
85-
::bincode::serialize_into(&mut *writer, &self.from).expect("bincode::serialize_into() failed");
86-
::bincode::serialize_into(&mut *writer, &self.seq).expect("bincode::serialize_into() failed");
86+
use byteorder::WriteBytesExt;
87+
writer.write_u64::<byteorder::LittleEndian>(self.from.try_into().unwrap()).unwrap();
88+
writer.write_u64::<byteorder::LittleEndian>(self.seq.try_into().unwrap()).unwrap();
8789
::bincode::serialize_into(&mut *writer, &self.time).expect("bincode::serialize_into() failed");
8890
self.data.into_bytes(&mut *writer);
8991
}

0 commit comments

Comments
 (0)