REdis Serialization Protocol
add resp-protocol
to Cargo.toml
toml
[dependencies]
resp-protocol = "0.0.4"
rust
use resp_protocol;
text
"+OK\r\n"
``` rust use resp_protocol::SimpleString;
let simple_string: SimpleString = SimpleString::new(b"OK"); ```
``` rust use resp_protocol::SimpleString;
let string: &str = "+OK\r\n"; let simplestring: SimpleString = SimpleString::parse(string.asbytes(), &mut 0, &string.len()).unwrap(); ```
text
"-ERROR\r\n"
``` rust use resp_protocol::Error;
let error: Error = Error::new(b"ERROR"); ```
``` rust use resp_protocol::Error;
let string: &str = "-ERROR\r\n"; let error: Error = Error::parse(string.as_bytes(), &mut 0, &string.len()).unwrap(); ```
text
":100\r\n"
``` rust use resp_protocol::Integer;
let integer: Integer = Integer::new(-100i64); ```
``` rust use resp_protocol::Integer;
let string: &str = ":-100\r\n"; let integer: Integer = Integer::parse(string.as_bytes(), &mut 0, &string.len()).unwrap(); ```
text
"$6\r\nfoobar\r\n"
``` rust use resp_protocol::BulkString;
let bulk_string: BulkString = BulkString::new(b"foobar"); ```
``` rust use resp_protocol::BulkString;
let string: &str = "$6\r\nfoobar\r\n"; let bulkstring: BulkString = BulkString::parse(string.asbytes(), &mut 0, &string.len()).unwrap(); ```