pub struct PacketRef<'a> {
pub header: Header,
pub data: &'a [u8],
}Expand description
A borrowed, zero-copy view of a received DDP packet.
This is the allocation-free receive path: it parses the header and borrows the payload
directly from the input buffer, so it works on bare-metal no_std targets with no
allocator. For an owned packet (and JSON message parsing), use Packet (requires the
std feature).
§Examples
use ddp_rs::packet::PacketRef;
let bytes = [
0x41, 0x01, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xFF, 0x00, 0x00, // 1 RGB pixel: red
];
let packet = PacketRef::from_bytes(&bytes).unwrap();
assert_eq!(packet.header.sequence_number, 1);
assert_eq!(packet.data, &[0xFF, 0x00, 0x00]);Fields§
§header: HeaderThe parsed packet header with metadata.
data: &'a [u8]The packet payload, borrowed from the input buffer.
Implementations§
Trait Implementations§
impl<'a> Copy for PacketRef<'a>
impl<'a> Eq for PacketRef<'a>
Source§impl<'a> PartialEq for PacketRef<'a>
impl<'a> PartialEq for PacketRef<'a>
impl<'a> StructuralPartialEq for PacketRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for PacketRef<'a>
impl<'a> RefUnwindSafe for PacketRef<'a>
impl<'a> Send for PacketRef<'a>
impl<'a> Sync for PacketRef<'a>
impl<'a> Unpin for PacketRef<'a>
impl<'a> UnsafeUnpin for PacketRef<'a>
impl<'a> UnwindSafe for PacketRef<'a>
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