Skip to content

Commit

Permalink
deser_rows: use DeserializeRow impl for Row
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
wprzytula committed Jun 12, 2024
1 parent f7bcf33 commit 17c84ac
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use crate::frame::value::{
Counter, CqlDate, CqlDecimal, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
};
use crate::frame::{frame_errors::ParseError, types};
use crate::types::deserialize::result::{RowIterator, TypedRowIterator};
use crate::types::deserialize::value::{DeserializeValue, MapIterator, UdtIterator};
use crate::types::deserialize::FrameSlice;
use crate::types::deserialize::{DeserializationError, FrameSlice};
use bytes::{Buf, Bytes};
use std::borrow::Cow;
use std::{convert::TryInto, net::IpAddr, result::Result as StdResult, str};
Expand Down Expand Up @@ -820,19 +821,16 @@ fn deser_rows(

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

let mut rows = Vec::with_capacity(rows_count);
for _ in 0..rows_count {
let mut columns = Vec::with_capacity(metadata.col_count);
for i in 0..metadata.col_count {
let v = if let Some(mut b) = types::read_bytes_opt(buf)? {
Some(deser_cql_value(&metadata.col_specs[i].typ, &mut b)?)
} else {
None
};
columns.push(v);
}
rows.push(Row { columns });
}
let raw_rows_iter = RowIterator::new(
rows_count,
&metadata.col_specs,
FrameSlice::new_borrowed(buf),
);
let rows_iter = TypedRowIterator::<Row>::new(raw_rows_iter)
.map_err(|err| DeserializationError::new(err.0))?;

let rows = rows_iter.collect::<StdResult<_, _>>()?;

Ok(Rows {
metadata,
rows_count,
Expand Down

0 comments on commit 17c84ac

Please sign in to comment.