pub struct FrameBuilder {
pub pixel_config: PixelConfig,
pub id: ID,
/* private fields */
}Expand description
Builds DDP frames from a pixel buffer, splitting large buffers across multiple packets and managing the rolling sequence number.
§Examples
use ddp_rs::protocol::{FrameBuilder, PixelConfig, ID};
let mut builder = FrameBuilder::new(PixelConfig::default(), ID::Default);
let mut scratch = [0u8; 1500];
// 2 RGB pixels. The closure receives each fully-assembled frame ready to send.
builder
.for_each_frame(&[255, 0, 0, 0, 0, 255], 0, &mut scratch, |frame| {
// e.g. socket.send(frame) on your platform
assert_eq!(frame.len(), 10 + 6);
Ok::<(), ()>(())
})
.unwrap();Fields§
§pixel_config: PixelConfigPixel format configuration written into each frame header.
id: IDProtocol ID written into each frame header.
Implementations§
Source§impl FrameBuilder
impl FrameBuilder
Sourcepub fn new(pixel_config: PixelConfig, id: ID) -> Self
pub fn new(pixel_config: PixelConfig, id: ID) -> Self
Creates a new frame builder. The sequence number starts at 1.
Sourcepub fn sequence_number(&self) -> u8
pub fn sequence_number(&self) -> u8
The sequence number that will be used for the next frame.
Sourcepub fn for_each_frame<F, E>(
&mut self,
data: &[u8],
offset: u32,
scratch: &mut [u8],
f: F,
) -> Result<(), E>
pub fn for_each_frame<F, E>( &mut self, data: &[u8], offset: u32, scratch: &mut [u8], f: F, ) -> Result<(), E>
Splits data into DDP frames and invokes f with each fully-assembled frame.
Each frame is written into scratch (which must be at least
header_len + MAX_DATA_LENGTH, i.e. ≥ 1500 bytes) and the resulting slice is passed
to f, which performs the actual transmission. offset is the starting byte offset
into the display buffer (not a pixel index); subsequent chunks advance it
automatically. The push flag is set on the final frame.
Uses this builder’s configured pixel_config and
id. For control messages with a custom id, use Self::frames_with.
Sourcepub fn frames_with<F, E>(
&mut self,
header: Header,
data: &[u8],
offset: u32,
scratch: &mut [u8],
f: F,
) -> Result<(), E>
pub fn frames_with<F, E>( &mut self, header: Header, data: &[u8], offset: u32, scratch: &mut [u8], f: F, ) -> Result<(), E>
Like Self::for_each_frame but using a caller-supplied header template.
The template’s packet_type, pixel_config, id and time_code are used as-is;
the offset, length, sequence_number and push flag are managed per chunk.
Trait Implementations§
Source§impl Clone for FrameBuilder
impl Clone for FrameBuilder
Source§fn clone(&self) -> FrameBuilder
fn clone(&self) -> FrameBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more