Skip to content

Commit e65f760

Browse files
piodulwprzytula
authored andcommitted
{frame,transport}: propagate frame contents as Bytes
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).
1 parent 925ddb9 commit e65f760

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

scylla-cql/src/frame/response/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,20 @@ impl Response {
6565
pub fn deserialize(
6666
features: &ProtocolFeatures,
6767
opcode: ResponseOpcode,
68-
buf: &mut &[u8],
68+
buf_bytes: bytes::Bytes,
6969
cached_metadata: Option<&ResultMetadata>,
7070
) -> Result<Response, CqlResponseParseError> {
71+
let buf = &mut &*buf_bytes;
7172
let response = match opcode {
7273
ResponseOpcode::Error => Response::Error(Error::deserialize(features, buf)?),
7374
ResponseOpcode::Ready => Response::Ready,
7475
ResponseOpcode::Authenticate => {
7576
Response::Authenticate(authenticate::Authenticate::deserialize(buf)?)
7677
}
7778
ResponseOpcode::Supported => Response::Supported(Supported::deserialize(buf)?),
78-
ResponseOpcode::Result => Response::Result(result::deserialize(buf, cached_metadata)?),
79+
ResponseOpcode::Result => {
80+
Response::Result(result::deserialize(buf_bytes, cached_metadata)?)
81+
}
7982
ResponseOpcode::Event => Response::Event(event::Event::deserialize(buf)?),
8083
ResponseOpcode::AuthChallenge => {
8184
Response::AuthChallenge(authenticate::AuthChallenge::deserialize(buf)?)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,10 @@ pub fn deser_cql_value(
853853
}
854854

855855
fn deser_rows(
856-
buf: &mut &[u8],
856+
buf_bytes: Bytes,
857857
cached_metadata: Option<&ResultMetadata>,
858858
) -> StdResult<Rows, RowsParseError> {
859+
let buf = &mut &*buf_bytes;
859860
let server_metadata = deser_result_metadata(buf)?;
860861

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

931932
pub fn deserialize(
932-
buf: &mut &[u8],
933+
buf_bytes: Bytes,
933934
cached_metadata: Option<&ResultMetadata>,
934935
) -> StdResult<Result, CqlResultParseError> {
936+
let buf = &mut &*buf_bytes;
935937
use self::Result::*;
936938
Ok(
937939
match types::read_int(buf)
938940
.map_err(|err| CqlResultParseError::ResultIdParseError(err.into()))?
939941
{
940942
0x0001 => Void,
941-
0x0002 => Rows(deser_rows(buf, cached_metadata)?),
943+
0x0002 => Rows(deser_rows(buf_bytes.slice_ref(buf), cached_metadata)?),
942944
0x0003 => SetKeyspace(deser_set_keyspace(buf)?),
943945
0x0004 => Prepared(deser_prepared(buf)?),
944946
0x0005 => SchemaChange(deser_schema_change(buf)?),

scylla/src/transport/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ impl Connection {
12461246
let response = Response::deserialize(
12471247
features,
12481248
task_response.opcode,
1249-
&mut &*body_with_ext.body,
1249+
body_with_ext.body,
12501250
cached_metadata,
12511251
)?;
12521252

0 commit comments

Comments
 (0)