Skip to content

Commit f40c17e

Browse files
committed
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.
1 parent 4b6ad84 commit f40c17e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scylla-cql/src/types/serialize/raw_batch.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,26 @@ where
145145
{
146146
#[inline]
147147
fn serialize_next(&mut self, writer: &mut RowWriter) -> Option<Result<(), SerializationError>> {
148-
let ctx = self.contexts.next()?;
148+
// We do `unwrap_or` because we want the iterator length to be the same
149+
// as the amount of values. Limiting to length of the amount of
150+
// statements (contexts) causes the caller to not be able to correctly
151+
// detect that amount of statements and values is different.
152+
let ctx = self
153+
.contexts
154+
.next()
155+
.unwrap_or(RowSerializationContext::empty());
149156
self.batch_values_iterator.serialize_next(&ctx, writer)
150157
}
151158

152159
fn is_empty_next(&mut self) -> Option<bool> {
153-
self.contexts.next()?;
160+
let _ = self.contexts.next();
154161
let ret = self.batch_values_iterator.is_empty_next()?;
155162
Some(ret)
156163
}
157164

158165
#[inline]
159166
fn skip_next(&mut self) -> Option<()> {
160-
self.contexts.next()?;
167+
let _ = self.contexts.next();
161168
self.batch_values_iterator.skip_next()?;
162169
Some(())
163170
}

0 commit comments

Comments
 (0)