Struct blob_stream::BlobStreamIn
source · pub struct BlobStreamIn { /* private fields */ }
Expand description
A struct representing a stream of binary data divided into fixed-size chunks.
Implementations§
source§impl BlobStreamIn
impl BlobStreamIn
sourcepub fn new(octet_count: usize, fixed_chunk_size: usize) -> Self
pub fn new(octet_count: usize, fixed_chunk_size: usize) -> Self
Creates a new BlobStreamIn
instance with the specified number of octets and chunk size.
§Parameters
octet_count
: The total number of octets (bytes) in the stream.fixed_chunk_size
: The size of each chunk in the stream.
§Panics
Panics if fixed_chunk_size
is zero.
§Returns
A new BlobStreamIn
instance.
sourcepub const fn chunk_count(&self) -> usize
pub const fn chunk_count(&self) -> usize
Returns the total number of expected chunks.
This function provides the total count of chunks that are expected based on the size of the data and the chunk size.
§Returns
The total number of chunks (usize
) that are expected for the data.
sourcepub const fn is_complete(&self) -> bool
pub const fn is_complete(&self) -> bool
Checks if all chunks have been received.
§Returns
true
if all chunks have been received; false
otherwise.
sourcepub fn blob(&self) -> Option<&[u8]>
pub fn blob(&self) -> Option<&[u8]>
Returns a reference to the complete blob if all chunks have been received.
§Returns
An Option
containing a reference to the blob if complete; otherwise, None
.
sourcepub fn set_chunk(
&mut self,
chunk_index: usize,
payload: &[u8],
) -> Result<(), BlobError>
pub fn set_chunk( &mut self, chunk_index: usize, payload: &[u8], ) -> Result<(), BlobError>
Sets a chunk of data at the specified chunk_index
with the provided payload
.
§Parameters
chunk_index
: The index of the chunk to set.payload
: A slice of octets representing the chunk’s data.
§Errors
Returns a BlobError
if:
- The
chunk_index
is invalid. - The
payload
size does not match the expected size for the chunk. - The chunk has already been set, with either the same or different contents.
§Returns
Ok(())
if the chunk was set successfully; otherwise, a BlobError
.