From f40c17ec504b617907c11a54cd9d8fe1731f01f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Bary=C5=82a?= Date: Fri, 6 Dec 2024 21:06:06 +0100 Subject: [PATCH] raw_batch: Fix RawBatchValuesIteratorAdapter length The length of this iterator should be equal to the length of its internal `BatchValuesIter`. In other words, the amount of serialization contexts should not affect this length. Otherwise, the caller is not able to detect a situation when value count is different than statement count. --- scylla-cql/src/types/serialize/raw_batch.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scylla-cql/src/types/serialize/raw_batch.rs b/scylla-cql/src/types/serialize/raw_batch.rs index eb3252e08..b59ba88ed 100644 --- a/scylla-cql/src/types/serialize/raw_batch.rs +++ b/scylla-cql/src/types/serialize/raw_batch.rs @@ -145,19 +145,26 @@ where { #[inline] fn serialize_next(&mut self, writer: &mut RowWriter) -> Option> { - let ctx = self.contexts.next()?; + // We do `unwrap_or` because we want the iterator length to be the same + // as the amount of values. Limiting to length of the amount of + // statements (contexts) causes the caller to not be able to correctly + // detect that amount of statements and values is different. + let ctx = self + .contexts + .next() + .unwrap_or(RowSerializationContext::empty()); self.batch_values_iterator.serialize_next(&ctx, writer) } fn is_empty_next(&mut self) -> Option { - self.contexts.next()?; + let _ = self.contexts.next(); let ret = self.batch_values_iterator.is_empty_next()?; Some(ret) } #[inline] fn skip_next(&mut self) -> Option<()> { - self.contexts.next()?; + let _ = self.contexts.next(); self.batch_values_iterator.skip_next()?; Some(()) }