Skip to main content

memcache_proto/
lib.rs

1//! Bidirectional Memcache protocol implementation.
2//!
3//! This crate provides complete Memcache protocol support for both client
4//! and server implementations. Both ASCII and binary protocols are supported.
5//!
6//! # Features
7//!
8//! - `ascii` (default): ASCII text protocol support
9//! - `binary`: Binary protocol support
10//! - `full`: Both ASCII and binary protocols
11//!
12//! # ASCII Protocol
13//!
14//! The ASCII protocol is text-based and human-readable. It's easier to debug
15//! but has more parsing overhead.
16//!
17//! ## Example - Client Side
18//!
19//! ```
20//! use memcache_proto::{Request, Response};
21//!
22//! // Encode a GET command
23//! let mut buf = vec![0u8; 1024];
24//! let len = Request::get(b"mykey").encode(&mut buf);
25//!
26//! // Parse the response
27//! let response_data = b"VALUE mykey 0 5\r\nhello\r\nEND\r\n";
28//! let (response, consumed) = Response::parse(response_data).unwrap();
29//! ```
30//!
31//! ## Example - Server Side
32//!
33//! ```
34//! use memcache_proto::{Command, Response};
35//!
36//! // Parse an incoming command
37//! let request_data = b"get mykey\r\n";
38//! let (cmd, consumed) = Command::parse(request_data).unwrap();
39//!
40//! // Encode a response
41//! let mut buf = vec![0u8; 1024];
42//! let len = Response::stored().encode(&mut buf);
43//! ```
44//!
45//! # Binary Protocol
46//!
47//! The binary protocol uses fixed 24-byte headers and is more efficient for
48//! high-throughput scenarios. Enable with the `binary` feature.
49//!
50//! ```ignore
51//! use memcache_proto::binary::{BinaryRequest, BinaryResponse, Opcode};
52//!
53//! // Encode a GET request
54//! let mut buf = [0u8; 256];
55//! let len = BinaryRequest::encode_get(&mut buf, b"mykey", 1);
56//! ```
57
58#[cfg(feature = "ascii")]
59mod command;
60mod error;
61#[cfg(feature = "ascii")]
62mod request;
63#[cfg(feature = "ascii")]
64mod response;
65#[cfg(feature = "ascii")]
66mod streaming;
67
68#[cfg(feature = "binary")]
69pub mod binary;
70
71#[cfg(feature = "ascii")]
72pub use command::{
73    Command, DEFAULT_MAX_KEY_LEN, DEFAULT_MAX_KEYS, DEFAULT_MAX_VALUE_LEN, ParseOptions,
74};
75pub use error::ParseError;
76#[cfg(feature = "ascii")]
77pub use request::{AddRequest, ReplaceRequest, Request};
78#[cfg(feature = "ascii")]
79pub use response::{Response, Value};
80#[cfg(feature = "ascii")]
81pub use streaming::{ParseProgress, STREAMING_THRESHOLD, SetHeader, complete_set, parse_streaming};