pub struct Packet {
pub header: Header,
pub data: Vec<u8>,
pub parsed: Option<Message>,
}Expand description
A parsed DDP packet received from a display.
This struct represents packets sent back by displays, such as status updates, configuration responses, or acknowledgments.
§Examples
use ddp_rs::packet::Packet;
// Parse a packet from raw bytes
let bytes = vec![
0x41, 0x01, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xFF, 0x00, 0x00 // 1 RGB pixel: red
];
let packet = Packet::from_bytes(&bytes);
assert_eq!(packet.header.sequence_number, 1);
assert_eq!(packet.data, vec![0xFF, 0x00, 0x00]);Fields§
§header: HeaderThe parsed packet header with metadata
data: Vec<u8>Raw pixel data (if this packet contains pixels)
parsed: Option<Message>Parsed JSON message (if this packet contains a message)
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn from_data(h: Header, d: &[u8]) -> Packet
pub fn from_data(h: Header, d: &[u8]) -> Packet
Creates a packet from a header and data slice (without parsing).
Sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Parses a DDP packet from raw bytes.
This method handles both 10-byte and 14-byte headers (with timecode), and attempts to parse JSON messages if the packet is a reply/query.
§Arguments
bytes- Raw packet bytes including header and data
§Returns
A parsed Packet. If parsing fails, returns a default packet with empty data.
§Examples
use ddp_rs::packet::Packet;
let bytes = vec![
0x41, 0x01, 0x0D, 0x01, // Packet type, seq, config, id
0x00, 0x00, 0x00, 0x00, // Offset
0x00, 0x06, // Length = 6
0xFF, 0x00, 0x00, // Pixel 1: Red
0x00, 0xFF, 0x00, // Pixel 2: Green
];
let packet = Packet::from_bytes(&bytes);
assert_eq!(packet.data.len(), 6);Trait Implementations§
impl StructuralPartialEq for Packet
Auto Trait Implementations§
impl Freeze for Packet
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more