Skip to content

📇A RESP (REdis Serialization Protocol) parser for Rust

License

Notifications You must be signed in to change notification settings

DavidCai1111/resp.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

resp.rs

Build Status

A RESP (REdis Serialization Protocol) parser for Rust.

Usage

extern crate resp;

use resp::encode;
use resp::Data;
use resp::decode;

fn main() {
    let encoded_string = encode(&Data::String("test".to_string()));
    assert_eq!(String::from_utf8(encoded_string).unwrap(), "+test\r\n");

    let array = Data::Array(vec![Data::String("s1".to_string()),
                                 Data::String("s2".to_string()),
                                 Data::String("s3".to_string())]);

    assert_eq!(String::from_utf8(encode(&array)).unwrap(),
               "*3\r\n+s1\r\n+s2\r\n+s3\r\n");
    assert_eq!(decode(&encode(&array)).ok().unwrap(), array);
}

API

pub fn encode(data: &Data) -> Vec<u8>

Encode given data to RESP buffer.

pub fn decode(bytes: &Vec<u8>) -> Result<Data, &str>

Decode the RESP buffer to real data.

About

📇A RESP (REdis Serialization Protocol) parser for Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages