in src/protocol/admin/src/admin.rs [37:73]
fn parse(&self, buffer: &[u8]) -> Result<ParseOk<AdminRequest>> {
// check if we got a CRLF
if let Some(command_end) = buffer
.windows(CRLF.len())
.position(|w| w == CRLF.as_bytes())
{
let trimmed_buffer = &buffer[0..command_end].trim();
// single-byte windowing to find spaces
let mut single_byte_windows = trimmed_buffer.windows(1);
if let Some(command_verb_end) = single_byte_windows.position(|w| w == b" ") {
let command_verb = &trimmed_buffer[0..command_verb_end];
// TODO(bmartin): 'stats slab' will go here eventually which will
// remove the need for ignoring this lint.
#[allow(clippy::match_single_binding)]
match command_verb {
_ => Err(Error::from(ErrorKind::InvalidInput)),
}
} else {
match &trimmed_buffer[0..] {
b"flush_all" => Ok(ParseOk::new(
AdminRequest::FlushAll,
command_end + CRLF.len(),
)),
b"stats" => Ok(ParseOk::new(AdminRequest::Stats, command_end + CRLF.len())),
b"quit" => Ok(ParseOk::new(AdminRequest::Quit, command_end + CRLF.len())),
b"version" => Ok(ParseOk::new(
AdminRequest::Version,
command_end + CRLF.len(),
)),
_ => Err(Error::from(ErrorKind::InvalidInput)),
}
}
} else {
Err(Error::from(ErrorKind::WouldBlock))
}
}