pub enum Frame {
Show 32 variants
SimpleString(Bytes),
Error(Bytes),
Integer(i64),
BulkString(Option<Bytes>),
BlobError(Bytes),
StreamedStringHeader,
StreamedBlobErrorHeader,
StreamedVerbatimStringHeader,
StreamedArrayHeader,
StreamedSetHeader,
StreamedMapHeader,
StreamedAttributeHeader,
StreamedPushHeader,
StreamedStringChunk(Bytes),
StreamedString(Vec<Bytes>),
StreamedArray(Vec<Frame>),
StreamedSet(Vec<Frame>),
StreamedMap(Vec<(Frame, Frame)>),
StreamedAttribute(Vec<(Frame, Frame)>),
StreamedPush(Vec<Frame>),
StreamTerminator,
Null,
Double(f64),
SpecialFloat(Bytes),
Boolean(bool),
BigNumber(Bytes),
VerbatimString(Bytes, Bytes),
Array(Option<Vec<Frame>>),
Set(Vec<Frame>),
Map(Vec<(Frame, Frame)>),
Attribute(Vec<(Frame, Frame)>),
Push(Vec<Frame>),
}Expand description
A parsed RESP3 frame.
Each variant corresponds to one of the RESP3 types, including both fixed-length and streaming headers for bulk strings, arrays, sets, maps, attributes, and pushes.
Variants§
SimpleString(Bytes)
Simple string: +<string>\r\n
Error(Bytes)
Simple error: -<error>\r\n
Integer(i64)
Integer: :<number>\r\n
BulkString(Option<Bytes>)
Blob string: $<length>\r\n<bytes>\r\n
BlobError(Bytes)
Blob error: !<length>\r\n<bytes>\r\n
StreamedStringHeader
Streaming blob string header: $?\r\n
StreamedBlobErrorHeader
Streaming blob error header: !?\r\n
StreamedVerbatimStringHeader
Streaming verbatim string header: =?\r\n
StreamedArrayHeader
Streaming array header: *?\r\n
StreamedSetHeader
Streaming set header: ~?\r\n
StreamedMapHeader
Streaming map header: %?\r\n
StreamedAttributeHeader
Streaming attribute header: |?\r\n
StreamedPushHeader
Streaming push header: >?\r\n
StreamedStringChunk(Bytes)
Streaming string chunk: ;length\r\ndata\r\n
Represents an individual chunk in a streaming string sequence.
These chunks are parsed from ;{length}\r\n{data}\r\n format.
A zero-length chunk (;0\r\n) indicates the end of the stream.
§Example
use resp_rs::resp3::Frame;
use bytes::Bytes;
// Chunk containing "Hello"
// Wire format: ;5\r\nHello\r\n
Frame::StreamedStringChunk(Bytes::from("Hello"));StreamedString(Vec<Bytes>)
Accumulated streaming string data from multiple chunks
Created by parse_streaming_sequence() when parsing a complete
streaming string sequence ($?\r\n + chunks + ;0\r\n).
Contains all chunks in order, allowing reconstruction of the full string.
§Example
use resp_rs::resp3::Frame;
use bytes::Bytes;
// Represents "Hello world" from chunks ["Hello ", "world"]
Frame::StreamedString(vec![
Bytes::from("Hello "),
Bytes::from("world")
]);StreamedArray(Vec<Frame>)
Accumulated streaming array data from multiple chunks
Created when parsing a streaming array sequence (*?\r\n + frames + .\r\n).
Contains all frames that were streamed as part of the array.
§Example
use resp_rs::resp3::Frame;
use bytes::Bytes;
// Array with mixed types
Frame::StreamedArray(vec![
Frame::SimpleString(Bytes::from("hello")),
Frame::Integer(42),
Frame::Boolean(true)
]);StreamedSet(Vec<Frame>)
Accumulated streaming set data from multiple chunks
Created when parsing a streaming set sequence (~?\r\n + frames + .\r\n).
Contains all unique elements that were streamed as part of the set.
StreamedMap(Vec<(Frame, Frame)>)
Accumulated streaming map data from multiple chunks
Created when parsing a streaming map sequence (%?\r\n + key-value pairs + .\r\n).
Contains all key-value pairs that were streamed as part of the map.
§Example
use resp_rs::resp3::Frame;
use bytes::Bytes;
Frame::StreamedMap(vec![
(Frame::SimpleString(Bytes::from("name")), Frame::SimpleString(Bytes::from("Alice"))),
(Frame::SimpleString(Bytes::from("age")), Frame::Integer(25))
]);StreamedAttribute(Vec<(Frame, Frame)>)
Accumulated streaming attribute data from multiple chunks
Created when parsing a streaming attribute sequence (|?\r\n + key-value pairs + .\r\n).
Attributes provide out-of-band metadata that doesn’t affect the main data structure.
StreamedPush(Vec<Frame>)
Accumulated streaming push data from multiple chunks
Created when parsing a streaming push sequence (>?\r\n + frames + .\r\n).
Push messages are server-initiated communications (e.g., pub/sub messages).
§Example
use resp_rs::resp3::Frame;
use bytes::Bytes;
// Pub/sub message
Frame::StreamedPush(vec![
Frame::SimpleString(Bytes::from("pubsub")),
Frame::SimpleString(Bytes::from("channel1")),
Frame::SimpleString(Bytes::from("message content"))
]);StreamTerminator
End-of-stream terminator for all chunked sequences: .\r\n
Null
Null: _\r\n
Double(f64)
Double: ,<float>\r\n
SpecialFloat(Bytes)
Special Float: ,inf\r\n, -inf\r\n, nan\r\n
Boolean(bool)
Boolean: #t\r\n or #f\r\n
BigNumber(Bytes)
Big number: (<number>\r\n
VerbatimString(Bytes, Bytes)
Verbatim string: =format:content\r\n
Array(Option<Vec<Frame>>)
Array: *<count>\r\n… (or streaming header *?\r\n)
Set(Vec<Frame>)
Set: ~<count>\r\n… (or streaming header ~?\r\n)
Map(Vec<(Frame, Frame)>)
Map: %<count>\r\n… (or streaming header %?\r\n)
Attribute(Vec<(Frame, Frame)>)
Attribute: |<count>\r\n… (or streaming header |?\r\n)
Push(Vec<Frame>)
Push: > <count>\r\n… (or streaming header >?\r\n)
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn as_bytes(&self) -> Option<&Bytes>
pub fn as_bytes(&self) -> Option<&Bytes>
Returns the bytes if this is a string-like frame (SimpleString, Error,
BulkString, BlobError, or BigNumber).
For BulkString(None) (null), returns None.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the string data as a UTF-8 &str, if this is a string-like frame
and contains valid UTF-8.
Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Returns the integer value if this is an Integer frame.
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
Returns the boolean value if this is a Boolean frame.
Sourcepub fn as_array(&self) -> Option<&[Frame]>
pub fn as_array(&self) -> Option<&[Frame]>
Returns a reference to the array items if this is an Array.
For Array(None) (null), returns None.
Sourcepub fn as_set(&self) -> Option<&[Frame]>
pub fn as_set(&self) -> Option<&[Frame]>
Returns a reference to the set items if this is a Set.
Sourcepub fn as_map(&self) -> Option<&[(Frame, Frame)]>
pub fn as_map(&self) -> Option<&[(Frame, Frame)]>
Returns a reference to the map pairs if this is a Map.
Sourcepub fn as_push(&self) -> Option<&[Frame]>
pub fn as_push(&self) -> Option<&[Frame]>
Returns a reference to the push items if this is a Push.
Sourcepub fn as_verbatim_string(&self) -> Option<(&Bytes, &Bytes)>
pub fn as_verbatim_string(&self) -> Option<(&Bytes, &Bytes)>
Returns the verbatim string format and content if this is a VerbatimString.
Sourcepub fn into_array(self) -> Result<Vec<Frame>, Frame>
pub fn into_array(self) -> Result<Vec<Frame>, Frame>
Consumes the frame and returns the array items.
Returns Err(self) if this is not a non-null Array.
Sourcepub fn into_bulk_string(self) -> Result<Bytes, Frame>
pub fn into_bulk_string(self) -> Result<Bytes, Frame>
Consumes the frame and returns the bulk string bytes.
Returns Err(self) if this is not a non-null BulkString.
Sourcepub fn into_map(self) -> Result<Vec<(Frame, Frame)>, Frame>
pub fn into_map(self) -> Result<Vec<(Frame, Frame)>, Frame>
Consumes the frame and returns the map pairs.
Returns Err(self) if this is not a Map.