diff options
| author | omagdy <omar.professional8777@gmail.com> | 2025-07-24 06:04:32 +0300 |
|---|---|---|
| committer | omagdy <omar.professional8777@gmail.com> | 2025-07-24 06:04:32 +0300 |
| commit | 30e6b478d7cd286b68da21d7a5aa5426c588cd02 (patch) | |
| tree | 719096c1bd3975e192bc5d6608f9f27f98e10e16 /src/resp_parser.rs | |
| parent | 561fb8d783cc000b7b9cc204e10618464c092e18 (diff) | |
| download | redis-rust-30e6b478d7cd286b68da21d7a5aa5426c588cd02.tar.xz redis-rust-30e6b478d7cd286b68da21d7a5aa5426c588cd02.zip | |
refactor: Refactor how I model the state and config and cache of the server with sepraration of concerns
Diffstat (limited to 'src/resp_parser.rs')
| -rw-r--r-- | src/resp_parser.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/resp_parser.rs b/src/resp_parser.rs index 952176c..646d2b1 100644 --- a/src/resp_parser.rs +++ b/src/resp_parser.rs @@ -380,18 +380,17 @@ pub fn parse_bulk_strings(bytes: &[u8]) -> Result<(RespType, &[u8]), RespError> return Err(RespError::UnexpectedEnd); } - let mut bulk_string: Vec<u8> = Vec::with_capacity(length as usize); + let bulk_string = remained[..length as usize].to_vec(); + let remaining_after_string = &remained[length as usize..]; - for i in 0..length { - bulk_string.push(remained[i as usize]); - } - - let consumed = RespType::BulkString(bulk_string); - - if !(&remained[length as usize..]).starts_with(b"\r\n") { + if !remaining_after_string.starts_with(b"\r\n") { return Err(RespError::UnexpectedEnd); } - return Ok((consumed, &remained[length as usize + 2..])); + + Ok(( + RespType::BulkString(bulk_string), + &remaining_after_string[2..], + )) } [] => Err(RespError::Custom(String::from("Empty data"))), } |
