Parses RESP data and extracts commands.
(data: &[u8])
| 175 | impl RespParser { |
| 176 | /// Parses RESP data and extracts commands. |
| 177 | pub fn parse_commands(data: &[u8]) -> Result<Vec<RedisCommand>, &'static str> { |
| 178 | let mut commands = Vec::new(); |
| 179 | let mut pos = 0; |
| 180 | |
| 181 | while pos < data.len() { |
| 182 | match Self::parse_resp_value(data, pos) { |
| 183 | Ok((value, new_pos)) => { |
| 184 | if let Some(cmd) = Self::resp_to_command(value) { |
| 185 | commands.push(cmd); |
| 186 | } |
| 187 | pos = new_pos; |
| 188 | } |
| 189 | Err(_) => { |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | Ok(commands) |
| 196 | } |
| 197 | |
| 198 | /// Parses a single RESP value starting at the given position. |
| 199 | pub fn parse_resp_value(data: &[u8], pos: usize) -> Result<(RespValue, usize), &'static str> { |