pub struct MultipartPush<'a, const N: usize> { /* private fields */ }Expand description
Guard returned by BytearrayRingbuffer::push_multipart and
BytearrayRingbuffer::push_multipart_force.
Accumulates payload bytes written via repeated Self::push calls. When dropped, the
completed packet (header + payload + footer) is committed to the ring buffer. Call
Self::cancel to discard the in-progress write without committing a packet.
In force mode any existing packets that were displaced to make room are permanently lost, even if the write is cancelled.
Implementations§
Source§impl<'a, const N: usize> MultipartPush<'a, N>
impl<'a, const N: usize> MultipartPush<'a, N>
Sourcepub fn push(&mut self, data: &[u8]) -> Result<(), NotEnoughSpaceError>
pub fn push(&mut self, data: &[u8]) -> Result<(), NotEnoughSpaceError>
Appends data to the packet currently being written.
May be called multiple times. The chunks are concatenated in order.
In normal mode returns NotEnoughSpaceError when there is not enough space in the buffer
to fit data plus the 4-byte footer. In force mode it drops the oldest packets until there
is room.
§Errors
Returns NotEnoughSpaceError if:
- The total accumulated payload would exceed
N - 8(the maximum for any single packet). - In normal mode: there is not enough unused space.
- In force mode: even after dropping all existing packets there is still not enough space (meaning the total accumulated payload exceeds what can fit in the buffer).
Sourcepub fn cancel(self)
pub fn cancel(self)
Discards the in-progress packet without committing it to the ring buffer.
Rewinds head to the position it had before BytearrayRingbuffer::push_multipart was
called. Any packets that were already dropped in force mode are permanently lost.