@@ -12,7 +12,6 @@ use bytes::{Bytes, BytesMut};
1212
1313// ! CURRENTLY, only ascii unicode(0-127) is supported
1414const FILE_PREFIX : char = '\u{0066}' ;
15- const SIMPLE_STRING_PREFIX : char = '+' ;
1615const BULK_STRING_PREFIX : char = '$' ;
1716const ARRAY_PREFIX : char = '*' ;
1817const APPEND_ENTRY_RPC_PREFIX : char = '^' ;
@@ -40,7 +39,6 @@ macro_rules! write_array {
4039pub enum QueryIO {
4140 #[ default]
4241 Null ,
43- SimpleString ( BinBytes ) ,
4442 BulkString ( BinBytes ) ,
4543 Array ( Vec < QueryIO > ) ,
4644
@@ -63,14 +61,7 @@ impl QueryIO {
6361 pub fn serialize ( self ) -> BinBytes {
6462 match self {
6563 QueryIO :: Null => BinBytes ( NULL_PREFIX . to_string ( ) . into ( ) ) ,
66- QueryIO :: SimpleString ( s) => {
67- let mut buffer =
68- BytesMut :: with_capacity ( SIMPLE_STRING_PREFIX . len_utf8 ( ) + s. len ( ) + 2 ) ;
69- buffer. extend_from_slice ( & [ SIMPLE_STRING_PREFIX as u8 ] ) ;
70- buffer. extend_from_slice ( & s) ;
71- buffer. extend_from_slice ( b"\r \n " ) ;
72- buffer. freeze ( ) . into ( )
73- } ,
64+
7465 QueryIO :: BulkString ( s) => {
7566 let mut byte_mut = BytesMut :: with_capacity ( 1 + 1 + s. len ( ) + 4 ) ;
7667 byte_mut. extend_from_slice ( BULK_STRING_PREFIX . encode_utf8 ( & mut [ 0 ; 4 ] ) . as_bytes ( ) ) ;
@@ -202,7 +193,7 @@ impl QueryIO {
202193 }
203194
204195 pub ( crate ) fn convert_str_res ( res : & str , index : u64 ) -> Self {
205- QueryIO :: SimpleString ( BinBytes :: new ( IndexedValueCodec :: encode ( res, index) ) )
196+ QueryIO :: BulkString ( BinBytes :: new ( IndexedValueCodec :: encode ( res, index) ) )
206197 }
207198
208199 pub ( crate ) fn convert_str_vec_res ( values : Vec < String > , index : u64 ) -> Self {
@@ -220,7 +211,7 @@ pub(crate) fn serialized_len_with_bincode<T: bincode::Encode>(prefix: char, arg:
220211fn estimate_serialized_size ( query : & QueryIO ) -> usize {
221212 match query {
222213 QueryIO :: Null => 1 ,
223- QueryIO :: SimpleString ( s ) => 1 + s . len ( ) + 2 ,
214+
224215 QueryIO :: BulkString ( s) => 1 + s. len ( ) . to_string ( ) . len ( ) + 2 + s. len ( ) + 2 ,
225216 QueryIO :: Array ( array) => {
226217 let header = 1 + array. len ( ) . to_string ( ) . len ( ) + 2 ;
@@ -286,10 +277,6 @@ pub fn deserialize(buffer: impl Into<Bytes>) -> Result<(QueryIO, usize)> {
286277
287278fn deserialize_by_prefix ( buffer : Bytes , prefix : char ) -> Result < ( QueryIO , usize ) > {
288279 match prefix {
289- SIMPLE_STRING_PREFIX => {
290- let ( bytes, len) = parse_simple_string ( buffer) ?;
291- Ok ( ( QueryIO :: SimpleString ( BinBytes ( bytes) ) , len) )
292- } ,
293280 ARRAY_PREFIX => parse_array ( buffer) ,
294281
295282 BULK_STRING_PREFIX => {
@@ -323,13 +310,6 @@ fn deserialize_by_prefix(buffer: Bytes, prefix: char) -> Result<(QueryIO, usize)
323310 }
324311}
325312
326- // +PING\r\n
327- pub ( crate ) fn parse_simple_string ( buffer : Bytes ) -> Result < ( Bytes , usize ) > {
328- let ( line, len) = read_until_crlf_exclusive ( & buffer. slice ( 1 ..) )
329- . ok_or ( anyhow:: anyhow!( "Invalid simple string" ) ) ?;
330- Ok ( ( line. into ( ) , len + 1 ) )
331- }
332-
333313fn parse_array ( buffer : Bytes ) -> Result < ( QueryIO , usize ) > {
334314 // Skip the array type indicator (first byte)
335315 let mut offset = 1 ;
@@ -523,32 +503,6 @@ mod test {
523503 use chrono:: DateTime ;
524504 use uuid:: Uuid ;
525505
526- #[ test]
527- fn test_deserialize_simple_string ( ) {
528- // GIVEN
529- let buffer = Bytes :: from ( "+OK\r \n " ) ;
530-
531- // WHEN
532- let ( value, len) = parse_simple_string ( buffer) . unwrap ( ) ;
533-
534- // THEN
535- assert_eq ! ( len, 5 ) ;
536- assert_eq ! ( value, Bytes :: from( "OK" ) ) ;
537- }
538-
539- #[ test]
540- fn test_deserialize_simple_string_ping ( ) {
541- // GIVEN
542- let buffer = Bytes :: from ( "+PING\r \n " ) ;
543-
544- // WHEN
545- let ( value, len) = deserialize ( buffer) . unwrap ( ) ;
546-
547- // THEN
548- assert_eq ! ( len, 7 ) ;
549- assert_eq ! ( value, QueryIO :: SimpleString ( BinBytes ( Bytes :: from( "PING" ) ) ) ) ;
550- }
551-
552506 #[ test]
553507 fn test_deserialize_bulk_string ( ) {
554508 // GIVEN
0 commit comments