Skip to content

Commit ff37535

Browse files
committedJun 13, 2024
deser_rows: use DeserializeRow impl for Row
In a manner similar to the previous commit, old imperative logic in `deser_row` is replaced with new iterator-based one, which uses the new deserialization framework. As a bonus, we get more descriptive error messages (as compared to old `ParseError::BadIncomingData` ones).
1 parent 802e683 commit ff37535

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed
 

‎scylla-cql/src/frame/response/result.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use crate::frame::value::{
44
Counter, CqlDate, CqlDecimal, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
55
};
66
use crate::frame::{frame_errors::ParseError, types};
7+
use crate::types::deserialize::result::{RowIterator, TypedRowIterator};
78
use crate::types::deserialize::value::{DeserializeValue, MapIterator, UdtIterator};
8-
use crate::types::deserialize::FrameSlice;
9+
use crate::types::deserialize::{DeserializationError, FrameSlice};
910
use bytes::{Buf, Bytes};
1011
use std::borrow::Cow;
1112
use std::{convert::TryInto, net::IpAddr, result::Result as StdResult, str};
@@ -820,19 +821,16 @@ fn deser_rows(
820821

821822
let rows_count: usize = types::read_int(buf)?.try_into()?;
822823

823-
let mut rows = Vec::with_capacity(rows_count);
824-
for _ in 0..rows_count {
825-
let mut columns = Vec::with_capacity(metadata.col_count);
826-
for i in 0..metadata.col_count {
827-
let v = if let Some(mut b) = types::read_bytes_opt(buf)? {
828-
Some(deser_cql_value(&metadata.col_specs[i].typ, &mut b)?)
829-
} else {
830-
None
831-
};
832-
columns.push(v);
833-
}
834-
rows.push(Row { columns });
835-
}
824+
let raw_rows_iter = RowIterator::new(
825+
rows_count,
826+
&metadata.col_specs,
827+
FrameSlice::new_borrowed(buf),
828+
);
829+
let rows_iter = TypedRowIterator::<Row>::new(raw_rows_iter)
830+
.map_err(|err| DeserializationError::new(err.0))?;
831+
832+
let rows = rows_iter.collect::<StdResult<_, _>>()?;
833+
836834
Ok(Rows {
837835
metadata,
838836
rows_count,

‎scylla-cql/src/types/deserialize/row.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ make_error_replace_rust_name!(
138138
// legacy/dynamic deserialization as Row
139139
//
140140
/// While no longer encouraged (because the new framework encourages deserializing
141-
/// directly into desired types, entirely bypassing CqlValue), this can be indispensable
141+
/// directly into desired types, entirely bypassing [CqlValue]), this can be indispensable
142142
/// for some use cases, i.e. those involving dynamic parsing (ORMs?).
143143
impl<'frame> DeserializeRow<'frame> for Row {
144144
#[inline]

0 commit comments

Comments
 (0)