From b35346bec58cdc780a5f992d0150ffb829ffa291 Mon Sep 17 00:00:00 2001 From: samuel orji Date: Fri, 13 Oct 2023 18:13:16 +0100 Subject: [PATCH] review feedback --- scylla-cql/src/frame/request/batch.rs | 2 +- scylla-cql/src/frame/response/result.rs | 4 ++-- scylla-cql/src/frame/types.rs | 15 ++------------- scylla-cql/src/frame/value.rs | 2 +- .../src/transport/large_batch_statements_test.rs | 4 ++-- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/scylla-cql/src/frame/request/batch.rs b/scylla-cql/src/frame/request/batch.rs index 3c0bad3931..35dd8c3c3b 100644 --- a/scylla-cql/src/frame/request/batch.rs +++ b/scylla-cql/src/frame/request/batch.rs @@ -190,7 +190,7 @@ impl<'b> DeserializableRequest for Batch<'b, BatchStatement<'b>, Vec Result { let batch_type = buf.get_u8().try_into()?; - let statements_count: usize = types::read_short(buf)?.try_into()?; + let statements_count: usize = types::read_short(buf)?.into(); let statements_with_values = (0..statements_count) .map(|_| { let batch_statement = BatchStatement::deserialize(buf)?; diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 288baf91eb..5ade677343 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -437,7 +437,7 @@ fn deser_type(buf: &mut &[u8]) -> StdResult { 0x0030 => { let keyspace_name: String = types::read_string(buf)?.to_string(); let type_name: String = types::read_string(buf)?.to_string(); - let fields_size: usize = types::read_short(buf)?.try_into()?; + let fields_size: usize = types::read_short(buf)?.into(); let mut field_types: Vec<(String, ColumnType)> = Vec::with_capacity(fields_size); @@ -455,7 +455,7 @@ fn deser_type(buf: &mut &[u8]) -> StdResult { } } 0x0031 => { - let len: usize = types::read_short(buf)?.try_into()?; + let len: usize = types::read_short(buf)?.into(); let mut types = Vec::with_capacity(len); for _ in 0..len { types.push(deser_type(buf)?); diff --git a/scylla-cql/src/frame/types.rs b/scylla-cql/src/frame/types.rs index 1c004e07cf..672fe2f97e 100644 --- a/scylla-cql/src/frame/types.rs +++ b/scylla-cql/src/frame/types.rs @@ -5,8 +5,8 @@ use byteorder::{BigEndian, ReadBytesExt}; use bytes::{Buf, BufMut}; use num_enum::TryFromPrimitive; use std::collections::HashMap; +use std::convert::TryFrom; use std::convert::TryInto; -use std::convert::{Infallible, TryFrom}; use std::net::IpAddr; use std::net::SocketAddr; use std::str; @@ -98,12 +98,6 @@ impl From for ParseError { } } -impl From for ParseError { - fn from(_: Infallible) -> Self { - ParseError::BadIncomingData("Unexpected Infallible Error".to_string()) - } -} - impl From for ParseError { fn from(_err: std::array::TryFromSliceError) -> Self { ParseError::BadIncomingData("array try from slice failed".to_string()) @@ -180,18 +174,13 @@ pub fn read_short(buf: &mut &[u8]) -> Result { Ok(v) } -pub fn read_u16(buf: &mut &[u8]) -> Result { - let v = buf.read_u16::()?; - Ok(v) -} - pub fn write_short(v: u16, buf: &mut impl BufMut) { buf.put_u16(v); } pub(crate) fn read_short_length(buf: &mut &[u8]) -> Result { let v = read_short(buf)?; - let v: usize = v.try_into()?; + let v: usize = v.into(); Ok(v) } diff --git a/scylla-cql/src/frame/value.rs b/scylla-cql/src/frame/value.rs index 617dce4820..17b75ea855 100644 --- a/scylla-cql/src/frame/value.rs +++ b/scylla-cql/src/frame/value.rs @@ -77,7 +77,7 @@ pub struct CqlDuration { #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum SerializeValuesError { - #[error("Too many values to add, max 32 767 values can be sent in a request")] + #[error("Too many values to add, max 65,535 values can be sent in a request")] TooManyValues, #[error("Mixing named and not named values is not allowed")] MixingNamedAndNotNamedValues, diff --git a/scylla/src/transport/large_batch_statements_test.rs b/scylla/src/transport/large_batch_statements_test.rs index 252f1d8f4a..0bbd06dfc9 100644 --- a/scylla/src/transport/large_batch_statements_test.rs +++ b/scylla/src/transport/large_batch_statements_test.rs @@ -20,7 +20,7 @@ async fn test_large_batch_statements() { let max_queries = u16::MAX as usize; let batch_insert_result = write_batch(&session, max_queries, &ks).await; - assert!(batch_insert_result.is_ok()); + batch_insert_result.unwrap(); let too_many_queries = u16::MAX as usize + 1; let batch_insert_result = write_batch(&session, too_many_queries, &ks).await; @@ -51,7 +51,7 @@ async fn create_test_session(session: Session, ks: &String) -> Session { } async fn write_batch(session: &Session, n: usize, ks: &String) -> Result { - let mut batch_query = Batch::new(BatchType::Logged); + let mut batch_query = Batch::new(BatchType::Unlogged); let mut batch_values = Vec::new(); for i in 0..n { let mut key = vec![0];