memcached_protocal/command/
retrieval_command.rs

1use std::io::BufRead;
2
3use ::error::ErrorKind;
4use ::error::Result;
5use ::byte_utils::read_until;
6
7#[derive(Debug, PartialEq)]
8pub struct RetrievalCommand {
9    pub command_name: String,
10    pub keys: Vec<String>,
11}
12
13
14impl RetrievalCommand {
15    pub fn parse<R: BufRead>(reader: &mut R) -> Result<RetrievalCommand> {
16        let cmd_line = try!(read_until(reader, "\r\n"));
17        let cmd_str = try!(String::from_utf8(cmd_line));
18        let segments = cmd_str.split_whitespace().collect::<Vec<&str>>();
19        let length = segments.len();
20        if length < 2 {
21            return Err(ErrorKind::ClientError("wrong size of params".to_owned()).into());
22        }
23        let cmd = segments[0];
24        let keys = segments[1..].iter().map(|&s| s.to_owned()).collect();
25
26        Ok(RetrievalCommand {
27            command_name: cmd.to_owned(),
28            keys: keys,
29        })
30    }
31}