|
| 1 | +use bytes::Bytes; |
1 | 2 | use itertools::Itertools; |
2 | 3 | use lazy_static::lazy_static; |
3 | 4 | use scylla_cql::cql_to_rust::FromCqlVal; |
@@ -52,10 +53,10 @@ const CUSTOM_PAYLOAD_TABLETS_V1_KEY: &str = "tablets-routing-v1"; |
52 | 53 |
|
53 | 54 | impl RawTablet { |
54 | 55 | pub(crate) fn from_custom_payload( |
55 | | - payload: &HashMap<String, Vec<u8>>, |
| 56 | + payload: &HashMap<String, Bytes>, |
56 | 57 | ) -> Option<Result<RawTablet, TabletParsingError>> { |
57 | 58 | let payload = payload.get(CUSTOM_PAYLOAD_TABLETS_V1_KEY)?; |
58 | | - let cql_value = match deser_cql_value(&RAW_TABLETS_CQL_TYPE, &mut payload.as_slice()) { |
| 59 | + let cql_value = match deser_cql_value(&RAW_TABLETS_CQL_TYPE, &mut payload.as_ref()) { |
59 | 60 | Ok(r) => r, |
60 | 61 | Err(e) => return Some(Err(e.into())), |
61 | 62 | }; |
@@ -590,6 +591,7 @@ mod tests { |
590 | 591 | use std::collections::{HashMap, HashSet}; |
591 | 592 | use std::sync::Arc; |
592 | 593 |
|
| 594 | + use bytes::Bytes; |
593 | 595 | use scylla_cql::frame::response::result::{ColumnType, CqlValue, TableSpec}; |
594 | 596 | use scylla_cql::types::serialize::value::SerializeValue; |
595 | 597 | use scylla_cql::types::serialize::CellWriter; |
@@ -618,8 +620,10 @@ mod tests { |
618 | 620 |
|
619 | 621 | #[test] |
620 | 622 | fn test_raw_tablet_deser_trash() { |
621 | | - let custom_payload = |
622 | | - HashMap::from([(CUSTOM_PAYLOAD_TABLETS_V1_KEY.to_string(), vec![1, 2, 3])]); |
| 623 | + let custom_payload = HashMap::from([( |
| 624 | + CUSTOM_PAYLOAD_TABLETS_V1_KEY.to_string(), |
| 625 | + Bytes::from_static(&[1, 2, 3]), |
| 626 | + )]); |
623 | 627 | assert_matches::assert_matches!( |
624 | 628 | RawTablet::from_custom_payload(&custom_payload), |
625 | 629 | Some(Err(TabletParsingError::Deserialization(_))) |
@@ -648,7 +652,7 @@ mod tests { |
648 | 652 | SerializeValue::serialize(&value, &col_type, CellWriter::new(&mut data)).unwrap(); |
649 | 653 | debug!("{:?}", data); |
650 | 654 |
|
651 | | - custom_payload.insert(CUSTOM_PAYLOAD_TABLETS_V1_KEY.to_string(), data); |
| 655 | + custom_payload.insert(CUSTOM_PAYLOAD_TABLETS_V1_KEY.to_string(), Bytes::from(data)); |
652 | 656 |
|
653 | 657 | assert_matches::assert_matches!( |
654 | 658 | RawTablet::from_custom_payload(&custom_payload), |
@@ -688,7 +692,7 @@ mod tests { |
688 | 692 | // Skipping length because `SerializeValue::serialize` adds length at the |
689 | 693 | // start of serialized value while Scylla sends the value without initial |
690 | 694 | // length. |
691 | | - data[4..].to_vec(), |
| 695 | + Bytes::copy_from_slice(&data[4..]), |
692 | 696 | ); |
693 | 697 |
|
694 | 698 | let tablet = RawTablet::from_custom_payload(&custom_payload) |
|
0 commit comments