Skip to content

Commit

Permalink
{frame,transport}: propagate frame contents as Bytes
Browse files Browse the repository at this point in the history
The new deserialization API will need to receive ownership of the
serialized frame for two reasons:

- To be able to deserialize to types that borrow from the frame
  (e.g. `text` as &str),
- To be able to deserialize to types that share ownership of the bytes
  (e.g. `blob` -> bytes::Bytes).
  • Loading branch information
piodul authored and wprzytula committed Aug 22, 2024
1 parent 925ddb9 commit e65f760
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions scylla-cql/src/frame/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ impl Response {
pub fn deserialize(
features: &ProtocolFeatures,
opcode: ResponseOpcode,
buf: &mut &[u8],
buf_bytes: bytes::Bytes,
cached_metadata: Option<&ResultMetadata>,
) -> Result<Response, CqlResponseParseError> {
let buf = &mut &*buf_bytes;
let response = match opcode {
ResponseOpcode::Error => Response::Error(Error::deserialize(features, buf)?),
ResponseOpcode::Ready => Response::Ready,
ResponseOpcode::Authenticate => {
Response::Authenticate(authenticate::Authenticate::deserialize(buf)?)
}
ResponseOpcode::Supported => Response::Supported(Supported::deserialize(buf)?),
ResponseOpcode::Result => Response::Result(result::deserialize(buf, cached_metadata)?),
ResponseOpcode::Result => {
Response::Result(result::deserialize(buf_bytes, cached_metadata)?)
}
ResponseOpcode::Event => Response::Event(event::Event::deserialize(buf)?),
ResponseOpcode::AuthChallenge => {
Response::AuthChallenge(authenticate::AuthChallenge::deserialize(buf)?)
Expand Down
8 changes: 5 additions & 3 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,10 @@ pub fn deser_cql_value(
}

fn deser_rows(
buf: &mut &[u8],
buf_bytes: Bytes,
cached_metadata: Option<&ResultMetadata>,
) -> StdResult<Rows, RowsParseError> {
let buf = &mut &*buf_bytes;
let server_metadata = deser_result_metadata(buf)?;

let metadata = match cached_metadata {
Expand Down Expand Up @@ -929,16 +930,17 @@ fn deser_schema_change(buf: &mut &[u8]) -> StdResult<SchemaChange, SchemaChangeE
}

pub fn deserialize(
buf: &mut &[u8],
buf_bytes: Bytes,
cached_metadata: Option<&ResultMetadata>,
) -> StdResult<Result, CqlResultParseError> {
let buf = &mut &*buf_bytes;
use self::Result::*;
Ok(
match types::read_int(buf)
.map_err(|err| CqlResultParseError::ResultIdParseError(err.into()))?
{
0x0001 => Void,
0x0002 => Rows(deser_rows(buf, cached_metadata)?),
0x0002 => Rows(deser_rows(buf_bytes.slice_ref(buf), cached_metadata)?),
0x0003 => SetKeyspace(deser_set_keyspace(buf)?),
0x0004 => Prepared(deser_prepared(buf)?),
0x0005 => SchemaChange(deser_schema_change(buf)?),
Expand Down
2 changes: 1 addition & 1 deletion scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ impl Connection {
let response = Response::deserialize(
features,
task_response.opcode,
&mut &*body_with_ext.body,
body_with_ext.body,
cached_metadata,
)?;

Expand Down

0 comments on commit e65f760

Please sign in to comment.