pub struct DataDownload<'s> { /* private fields */ }
Expand description
Data download helper
To success stream data over usb it needs to be sent in blocks that are multiple of the max endpoint size, otherwise the receiver may complain. It also should only send as much data as was indicate in the DATA command.
This helper ensures both invariants are met. To do this data needs to be sent by using DataDownload::extend_from_slice or DataDownload::get_mut_data, after sending the data DataDownload::finish should be called to validate and finalize.
Implementations§
Source§impl DataDownload<'_>
impl DataDownload<'_>
Sourcepub async fn extend_from_slice(
&mut self,
data: &[u8],
) -> Result<(), DownloadError>
pub async fn extend_from_slice( &mut self, data: &[u8], ) -> Result<(), DownloadError>
Extend the streaming from a slice
This will copy all provided data and send it out if enough is collected. The total amount of data being sent should not exceed the download size
Sourcepub async fn get_mut_data(
&mut self,
max: usize,
) -> Result<&mut [u8], DownloadError>
pub async fn get_mut_data( &mut self, max: usize, ) -> Result<&mut [u8], DownloadError>
This will provide a mutable reference to a u8 of at most max
size. The returned slice
should be completely filled with data to be downloaded to the device
The total amount of data should not exceed the download size
Sourcepub async fn finish(self) -> Result<(), DownloadError>
pub async fn finish(self) -> Result<(), DownloadError>
Finish all pending transfer
This should only be called if all data has been queued up (matching the total size)