memcached_protocal/command/
deletion_command.rs1use std::io::BufRead;
2
3use ::error::ErrorKind;
4use ::error::Result;
5use ::byte_utils::read_until;
6
7#[derive(Debug, PartialEq)]
8pub struct DeletionCommand {
9 pub command_name: String,
10 pub key: String,
11 pub noreply: Option<String>,
12}
13
14
15impl DeletionCommand {
16 pub fn parse<R: BufRead>(reader: &mut R) -> Result<DeletionCommand> {
17 let cmd_line = try!(read_until(reader, "\r\n"));
18 let cmd_str = try!(String::from_utf8(cmd_line));
19 let segments = cmd_str.split_whitespace().collect::<Vec<&str>>();
20 let length = segments.len();
21 if length < 2 {
22 return Err(ErrorKind::ClientError("wrong size of params".to_owned()).into());
23 }
24 let cmd = segments[0];
25 let key = segments[1];
26 let noreply = if length > 2 {
27 Some(segments[2].to_string())
28 } else {
29 None
30 };
31
32 Ok(DeletionCommand {
33 command_name: cmd.to_owned(),
34 key: key.to_owned(),
35 noreply: noreply,
36 })
37 }
38}