Skip to main content

BdxWriter

Struct BdxWriter 

Source
pub struct BdxWriter<'a, 'b> { /* private fields */ }
Expand description

A writer over a BDX transfer - the Sender side.

Obtained from Exchange::upload on the initiating side, or from BdxDownloadResponder::reply on the responding side. write stages and sends the data, driving the protocol as needed; finish flushes the final block and completes the transfer. It also implements embedded_io_async::Write (delegating to the inherent write).

The caller supplies the staging buffer buf, which doubles as the upper bound on the block size (so there is no hidden, MCU-unfriendly internal allocation). It must be non-empty.

Implementations§

Source§

impl<'a, 'b> BdxWriter<'a, 'b>

Source

pub async fn write(&mut self, data: &[u8]) -> Result<usize, Error>

Stage and send data, returning the number of bytes accepted (< data.len() only when the current block fills; call again with the remainder).

This is also the embedded_io_async::Write implementation; the inherent method is kept so callers need not import the trait.

Source

pub fn max_block_size(&self) -> usize

The largest block this writer will send (and the length of the buffer returned by block_buf).

Source

pub fn block_buf(&mut self) -> &mut [u8]

The writer’s own staging buffer (exactly max_block_size bytes), to be filled in place and then sent with commit.

This is the zero-extra-buffer alternative to write: a caller streaming from another source (a flash region, a socket) can read straight into this slice instead of into its own buffer and copying. Do not interleave it with write, which stages into the same space.

Source

pub async fn commit(&mut self, len: usize) -> Result<(), Error>

Send len bytes - previously written into block_buf - as one block. len must not exceed max_block_size.

Source

pub async fn finish(self) -> Result<(), Error>

Flush the final (possibly empty) block and complete the transfer.

Trait Implementations§

Source§

impl ErrorType for BdxWriter<'_, '_>

Source§

type Error = Error

Error type of all the IO operations on this type.
Source§

impl Write for BdxWriter<'_, '_>

Source§

async fn flush(&mut self) -> Result<(), <BdxWriter<'_, '_> as ErrorType>::Error>

Send any staged-but-unsent bytes as a (non-final) block.

Source§

async fn write( &mut self, data: &[u8], ) -> Result<usize, <BdxWriter<'_, '_> as ErrorType>::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more

Auto Trait Implementations§

§

impl<'a, 'b> !RefUnwindSafe for BdxWriter<'a, 'b>

§

impl<'a, 'b> !Send for BdxWriter<'a, 'b>

§

impl<'a, 'b> !Sync for BdxWriter<'a, 'b>

§

impl<'a, 'b> !UnwindSafe for BdxWriter<'a, 'b>

§

impl<'a, 'b> Freeze for BdxWriter<'a, 'b>

§

impl<'a, 'b> Unpin for BdxWriter<'a, 'b>

§

impl<'a, 'b> UnsafeUnpin for BdxWriter<'a, 'b>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, I> IntoFallibleInit<T> for I
where I: Init<T>,

Source§

fn into_fallible<E>(self) -> impl Init<T, E>

Convert the infallible initializer to a fallible one.
Source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

Source§

type Error = <Target as OctetsFrom<Source>>::Error

Source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
Source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V