Skip to main content

resp_proto/
lib.rs

1//! Bidirectional RESP2/RESP3 protocol implementation.
2//!
3//! This crate provides complete RESP (Redis Serialization Protocol) support for both
4//! client and server implementations, supporting both RESP2 and RESP3 protocols.
5//!
6//! - **Values**: Parse and encode RESP values (strings, integers, arrays, etc.)
7//! - **Requests**: Encode commands (client) and parse commands (server)
8//! - **Responses**: Encode responses (server) and parse responses (client)
9//!
10//! # Features
11//!
12//! - `resp3` - Enables RESP3 protocol support with additional types:
13//!   - Boolean (`#t`/`#f`)
14//!   - Double (`,3.14159`)
15//!   - BigNumber (`(12345678901234567890`)
16//!   - BulkError (`!<len>\r\n<error>`)
17//!   - VerbatimString (`=<len>\r\ntxt:<data>`)
18//!   - Map (`%<len>\r\n<key><val>...`)
19//!   - Set (`~<len>\r\n<elem>...`)
20//!   - Push (`><len>\r\n<elem>...`)
21//!   - Attribute (`|<len>\r\n<attrs>...<value>`)
22//!   - Null (`_\r\n`)
23//!
24//! # Example - Client Side
25//!
26//! ```
27//! use resp_proto::{Request, Value};
28//!
29//! // Encode a GET command
30//! let mut buf = vec![0u8; 1024];
31//! let len = Request::get(b"mykey").encode(&mut buf);
32//!
33//! // Parse the response
34//! let response_data = b"+OK\r\n";
35//! let (value, consumed) = Value::parse(response_data).unwrap();
36//! ```
37//!
38//! # Example - Server Side
39//!
40//! ```
41//! use resp_proto::{Command, Value};
42//!
43//! // Parse an incoming command
44//! let request_data = b"*2\r\n$3\r\nGET\r\n$5\r\nmykey\r\n";
45//! let (cmd, consumed) = Command::parse(request_data).unwrap();
46//!
47//! // Encode a response
48//! let mut buf = vec![0u8; 1024];
49//! let len = Value::bulk_string(b"myvalue").encode(&mut buf);
50//! ```
51
52pub mod cluster;
53mod command;
54mod error;
55mod request;
56pub mod streaming;
57mod value;
58
59pub use cluster::{
60    NodeInfo, Redirect, RedirectKind, SLOT_COUNT, SlotMap, SlotRange, crc16, hash_slot,
61    parse_redirect,
62};
63pub use command::Command;
64pub use error::ParseError;
65pub use request::{Request, SetRequest};
66pub use streaming::{ParseProgress, STREAMING_THRESHOLD, SetHeader, complete_set, parse_streaming};
67pub use value::{
68    DEFAULT_MAX_BULK_STRING_LEN, DEFAULT_MAX_COLLECTION_ELEMENTS, DEFAULT_MAX_DEPTH,
69    DEFAULT_MAX_KEY_LEN, DEFAULT_MAX_TOTAL_ITEMS, ParseOptions, Value,
70};