diff --git a/vortex-array/src/data/viewed.rs b/vortex-array/src/data/viewed.rs index cc195316f..32f53ffa5 100644 --- a/vortex-array/src/data/viewed.rs +++ b/vortex-array/src/data/viewed.rs @@ -5,7 +5,7 @@ use enum_iterator::all; use itertools::Itertools; use vortex_buffer::Buffer; use vortex_dtype::{DType, Nullability, PType}; -use vortex_error::{vortex_err, VortexExpect as _, VortexResult, VortexUnwrap}; +use vortex_error::{vortex_err, VortexExpect as _, VortexResult}; use vortex_scalar::{Scalar, ScalarValue}; use crate::encoding::opaque::OpaqueEncoding; @@ -108,9 +108,9 @@ impl ViewedArrayData { .buffers() .and_then(|buffers| { assert!(buffers.len() <= 1, "Array: expected at most one buffer"); - (buffers.len() > 0).then(|| buffers.get(0) as usize) + (!buffers.is_empty()).then(|| buffers.get(0) as usize) }) - .map(|idx| &self.buffers[usize::try_from(idx).vortex_unwrap()]) + .map(|idx| &self.buffers[idx]) } } diff --git a/vortex-dtype/src/serde/flatbuffers/mod.rs b/vortex-dtype/src/serde/flatbuffers/mod.rs index 49f8fa949..6236982b3 100644 --- a/vortex-dtype/src/serde/flatbuffers/mod.rs +++ b/vortex-dtype/src/serde/flatbuffers/mod.rs @@ -265,7 +265,7 @@ mod test { use crate::{flatbuffers as fb, DType, PType, StructDType}; fn roundtrip_dtype(dtype: DType) { - let bytes = dtype.with_flatbuffer_bytes(|bytes| bytes.to_vec()); + let bytes = dtype.write_flatbuffer_bytes(); let deserialized = DType::try_from(root::(&bytes).unwrap()).unwrap(); assert_eq!(dtype, deserialized); } diff --git a/vortex-flatbuffers/src/lib.rs b/vortex-flatbuffers/src/lib.rs index b45a50c18..118825603 100644 --- a/vortex-flatbuffers/src/lib.rs +++ b/vortex-flatbuffers/src/lib.rs @@ -149,11 +149,6 @@ pub trait FlatBufferToBytes { /// Write the flatbuffer to a byte vector and return the vector along with the starting /// position of the flatbuffer in the vector. fn write_flatbuffer_bytes(&self) -> Buffer; - - #[deprecated( - note = "Use `write_flatbuffer_bytes` instead. This method will be removed in a future release." - )] - fn with_flatbuffer_bytes R>(&self, f: Fn) -> R; } impl FlatBufferToBytes for F { @@ -166,11 +161,4 @@ impl FlatBufferToBytes for F { let end = vec.len(); Buffer::from(vec).slice(start..end) } - - fn with_flatbuffer_bytes R>(&self, f: Fn) -> R { - let mut fbb = FlatBufferBuilder::new(); - let root_offset = self.write_flatbuffer(&mut fbb); - fbb.finish_minimal(root_offset); - f(fbb.finished_data()) - } } diff --git a/vortex-ipc/src/messages/mod.rs b/vortex-ipc/src/messages/mod.rs index 2f30d81a7..dd00afa7a 100644 --- a/vortex-ipc/src/messages/mod.rs +++ b/vortex-ipc/src/messages/mod.rs @@ -38,7 +38,7 @@ impl WriteFlatBuffer for IPCMessage { fbb, &fba::BufferArgs { length: buffer.len() as u64, - padding: padding as u16, + padding: padding.try_into().vortex_expect("padding must fit in u16"), }, ) .as_union_value() @@ -82,12 +82,12 @@ impl WriteFlatBuffer for ArrayDataWriter<'_> { for array_data in self.array.depth_first_traversal() { if let Some(buffer) = array_data.buffer() { let aligned_size = buffer.len().next_multiple_of(ALIGNMENT); - let padding = (aligned_size - buffer.len()) as u16; + let padding = aligned_size - buffer.len(); buffers.push(fba::Buffer::create( fbb, &fba::BufferArgs { length: buffer.len() as u64, - padding, + padding: padding.try_into().vortex_expect("padding must fit in u16"), }, )); } @@ -154,7 +154,7 @@ impl WriteFlatBuffer for ArrayWriter<'_> { .array .buffer() .is_some() - .then(|| self.buffer_idx) + .then_some(self.buffer_idx) .map(|buffer_idx| fbb.create_vector_from_iter(std::iter::once(buffer_idx))); let stats = Some(self.array.statistics().write_flatbuffer(fbb)); diff --git a/vortex-ipc/src/messages/reader.rs b/vortex-ipc/src/messages/reader.rs index 242b1fae9..2a4d72abb 100644 --- a/vortex-ipc/src/messages/reader.rs +++ b/vortex-ipc/src/messages/reader.rs @@ -114,13 +114,13 @@ impl MessageReader { ctx: Arc, dtype: DType, ) -> VortexResult> { - let all_buffers_size: usize = match self.peek().and_then(|m| m.header_as_array_data()) { + let all_buffers_size = match self.peek().and_then(|m| m.header_as_array_data()) { None => return Ok(None), Some(array_data) => array_data .buffers() .unwrap_or_default() .iter() - .map(|b| b.length() as usize + (b.padding() as usize)) + .map(|b| b.length() + (b.padding() as u64)) .sum(), }; @@ -129,7 +129,7 @@ impl MessageReader { )); // Issue a single read to grab all buffers - let all_buffers = self.read.read_bytes(all_buffers_size as u64).await?; + let all_buffers = self.read.read_bytes(all_buffers_size).await?; if array_reader.read(all_buffers)?.is_some() { unreachable!("This is an implementation bug") @@ -285,7 +285,11 @@ impl ArrayMessageReader { self.fb_msg = Some(Buffer::from(bytes)); self.state = ReadState::ReadingBuffers; - Ok(Some(buffers_size as usize)) + Ok(Some( + buffers_size + .try_into() + .vortex_expect("Cannot cast to usize"), + )) } ReadState::ReadingBuffers => { // Split out into individual buffers @@ -298,7 +302,12 @@ impl ArrayMessageReader { .iter() .map(|buffer| { // Grab the buffer - let data_buffer = bytes.split_to(buffer.length() as usize); + let data_buffer = bytes.split_to( + buffer + .length() + .try_into() + .vortex_expect("Buffer size does not fit into usize"), + ); // Strip off any padding from the previous buffer bytes.advance(buffer.padding() as usize); Buffer::from(data_buffer)