From 23cf9edf905c88ab0ded89bb156f4eda6e122337 Mon Sep 17 00:00:00 2001 From: Frank McSherry Date: Thu, 5 Dec 2024 12:32:05 -0500 Subject: [PATCH] Prefer byteorder in place of bincode --- timely/Cargo.toml | 1 + timely/src/dataflow/channels/mod.rs | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/timely/Cargo.toml b/timely/Cargo.toml index 861cac8b9..8e45aefa6 100644 --- a/timely/Cargo.toml +++ b/timely/Cargo.toml @@ -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" } diff --git a/timely/src/dataflow/channels/mod.rs b/timely/src/dataflow/channels/mod.rs index b51daf33f..7b5919a94 100644 --- a/timely/src/dataflow/channels/mod.rs +++ b/timely/src/dataflow/channels/mod.rs @@ -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::().unwrap().try_into().unwrap(); + let seq: usize = slice.read_u64::().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); @@ -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(&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::(self.from.try_into().unwrap()).unwrap(); + writer.write_u64::(self.seq.try_into().unwrap()).unwrap(); ::bincode::serialize_into(&mut *writer, &self.time).expect("bincode::serialize_into() failed"); self.data.into_bytes(&mut *writer); }