pub struct Logic { /* private fields */ }
Expand description
Logic
handles the logic for receiving and processing chunks of data
in a streaming context. It manages the internal state and interactions
between the sender and receiver commands.
Implementations§
Source§impl Logic
impl Logic
Sourcepub fn new(octet_count: usize, chunk_size: usize) -> Self
pub fn new(octet_count: usize, chunk_size: usize) -> Self
Creates a new Logic
instance with the specified octet_count
and chunk_size
.
§Arguments
octet_count
- The total number of octets (bytes) expected in the stream.chunk_size
- The size of each chunk in the stream.
§Returns
A new Logic
instance.
§Example
use blob_stream::in_logic::Logic;
let in_logic = Logic::new(1024, 64);
pub fn info(&self) -> Info
Sourcepub fn receive(&mut self, chunk_data: &SetChunkData) -> Result<(), BlobError>
pub fn receive(&mut self, chunk_data: &SetChunkData) -> Result<(), BlobError>
Processes a SenderToReceiverCommands
command, applying it to the internal stream.
Currently, this function only handles the SetChunk
command, which updates the
stream with a new chunk of data.
§Arguments
command
- The command sent by the sender, containing the chunk data.
§Errors
Returns an [io::Error
] if the chunk cannot be set due to an I/O error.
§Example
use blob_stream::in_logic::Logic;
use blob_stream::protocol::{SetChunkData};
let mut in_logic = Logic::new(1024, 5);
let chunk_data = SetChunkData {
chunk_index: 1,
payload: [0x8f, 0x23, 0x98, 0xfa, 0x99].into(),
};
in_logic.receive(&chunk_data).unwrap();
pub fn send(&mut self) -> AckChunkData
Sourcepub fn blob(&self) -> Option<&[u8]>
pub fn blob(&self) -> Option<&[u8]>
Retrieves the full blob data if all chunks have been received.
§Returns
An Some(&[u8])
containing the full blob data if all chunks have been received,
or None
if the blob is incomplete.
§Example
use blob_stream::in_logic::Logic;
let mut in_logic = Logic::new(1024, 64);
if let Some(blob) = in_logic.blob() {
// Use the blob data
}
pub fn is_complete(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Logic
impl RefUnwindSafe for Logic
impl Send for Logic
impl Sync for Logic
impl Unpin for Logic
impl UnwindSafe for Logic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more