Created
March 25, 2020 17:00
-
-
Save qingant/e3eb6e828afafccb129ad8ef1d36b093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, Clone)] | |
pub enum RValue { | |
RStr(String), | |
// RBulkString(ByteString), | |
RNumber(f64), | |
Error(String), | |
RList(Vec<RValue>), | |
Nil, | |
} | |
impl RValue { | |
pub fn encode(&self) -> String { | |
match self { | |
RValue::Nil => String::from("*-1\r\n"), | |
RValue::RStr(s) => format!("+{}\r\n", s), | |
RValue::RNumber(n) => format!(":{}\r\n", n), | |
RValue::Error(e) => format!("-{}\r\n", e), | |
RValue::RList(list) => { | |
let mut r = format!("*{}\r\n", list.len()); | |
for s in list { | |
r += &s.encode(); | |
} | |
r | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment