Skip to main content

Crate resp_rs

Crate resp_rs 

Source
Expand description

Zero-copy RESP2 and RESP3 protocol parser and serializer.

resp-rs provides high-performance parsing and serialization for the Redis Serialization Protocol (RESP), supporting both RESP2 and RESP3.

§Features

  • Zero-copy parsing using bytes::Bytes for efficient memory management
  • RESP2 and RESP3 support with separate frame types
  • Streaming parser for incremental data (handles partial reads and pipelining)
  • High performance: 4.8-8.0 GB/s throughput in benchmarks

§Quick Start

use bytes::Bytes;
use resp_rs::resp3;

let data = Bytes::from("+OK\r\n");
let (frame, remaining) = resp3::parse_frame(data).unwrap();
assert_eq!(frame, resp3::Frame::SimpleString(Bytes::from("OK")));

§RESP2

use bytes::Bytes;
use resp_rs::resp2;

let data = Bytes::from("+OK\r\n");
let (frame, remaining) = resp2::parse_frame(data).unwrap();
assert_eq!(frame, resp2::Frame::SimpleString(Bytes::from("OK")));

§Streaming parser (handles partial reads)

use bytes::Bytes;
use resp_rs::resp3::Parser;

let mut parser = Parser::new();

// Feed partial data
parser.feed(Bytes::from("+HEL"));
assert!(parser.next_frame().unwrap().is_none()); // Incomplete

// Feed the rest
parser.feed(Bytes::from("LO\r\n"));
let frame = parser.next_frame().unwrap().unwrap(); // Complete!

Modules§

resp2
RESP2 protocol parser and serializer.
resp3
Zero-copy RESP3 parser.

Enums§

ParseError
Errors that can occur during RESP parsing.