Skip to main content

FrameBuilder

Struct FrameBuilder 

Source
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: PixelConfig

Pixel format configuration written into each frame header.

§id: ID

Protocol ID written into each frame header.

Implementations§

Source§

impl FrameBuilder

Source

pub fn new(pixel_config: PixelConfig, id: ID) -> Self

Creates a new frame builder. The sequence number starts at 1.

Source

pub fn sequence_number(&self) -> u8

The sequence number that will be used for the next frame.

Source

pub fn for_each_frame<F, E>( &mut self, data: &[u8], offset: u32, scratch: &mut [u8], f: F, ) -> Result<(), E>
where F: FnMut(&[u8]) -> 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.

Source

pub fn frames_with<F, E>( &mut self, header: Header, data: &[u8], offset: u32, scratch: &mut [u8], f: F, ) -> Result<(), E>
where F: FnMut(&[u8]) -> 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

Source§

fn clone(&self) -> FrameBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FrameBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.