pub struct ChunkedBuffer { /* private fields */ }Expand description
A buffer that manages chunked data.
Implementations§
Source§impl ChunkedBuffer
impl ChunkedBuffer
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new chunked buffer with default settings.
Sourcepub fn calculate_chunks(&self, total_size: u64) -> usize
pub fn calculate_chunks(&self, total_size: u64) -> usize
Calculate the number of chunks needed for a given size.
Sourcepub fn descriptor_for_index(
&self,
index: usize,
total_size: u64,
) -> ChunkDescriptor
pub fn descriptor_for_index( &self, index: usize, total_size: u64, ) -> ChunkDescriptor
Get a chunk descriptor for a given index.
Sourcepub async fn push(&self, descriptor: ChunkDescriptor, data: Bytes) -> Result<()>
pub async fn push(&self, descriptor: ChunkDescriptor, data: Bytes) -> Result<()>
Push a chunk into the buffer.
Sourcepub async fn pop(&self) -> Result<Option<(ChunkDescriptor, Bytes)>>
pub async fn pop(&self) -> Result<Option<(ChunkDescriptor, Bytes)>>
Pop a chunk from the buffer.
Sourcepub async fn peek(&self) -> Result<Option<ChunkDescriptor>>
pub async fn peek(&self) -> Result<Option<ChunkDescriptor>>
Peek at the next chunk without removing it.
Sourcepub async fn rebase_if_empty(&self, index: usize) -> bool
pub async fn rebase_if_empty(&self, index: usize) -> bool
Move the write cursor to index, but only while the buffer is drained.
Self::push enforces a strictly sequential producer: a chunk is only
accepted when its index equals the internal write cursor. A pull-based
consumer such as crate::io::ChunkedReader serves a buffer miss with a
direct read that deliberately bypasses this buffer, which leaves the
write cursor lagging behind the stream and makes every later read-ahead
push fail with StreamingError::InvalidOperation. Re-basing while
the buffer holds nothing lets read-ahead resume at the consumer’s real
position without weakening the ordering check for buffered chunks.
Returns true when the cursor was moved, false when the buffer still
holds chunks (in which case re-basing would reorder them and is refused).
Sourcepub async fn size_bytes(&self) -> usize
pub async fn size_bytes(&self) -> usize
Get the current buffer size in bytes.
Sourcepub async fn is_complete(&self) -> bool
pub async fn is_complete(&self) -> bool
Check if writing is complete.
Sourcepub async fn stats(&self) -> BufferStats
pub async fn stats(&self) -> BufferStats
Get buffer statistics.