Struct blob_stream::in_logic_front::FrontLogic
source · pub struct FrontLogic { /* 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 FrontLogic
impl FrontLogic
sourcepub fn update(
&mut self,
command: &SenderToReceiverFrontCommands,
) -> Result<ReceiverToSenderFrontCommands>
pub fn update( &mut self, command: &SenderToReceiverFrontCommands, ) -> Result<ReceiverToSenderFrontCommands>
Updates the internal state based on a SenderToReceiverFrontCommands
command.
This method processes either a StartTransfer
or SetChunk
command sent by the sender.
If a StartTransfer
command is received, the current state (including transfer_id
and
logic
) is reinitialized if necessary. If a SetChunk
command is received, it applies
the chunk of data to the current logic.
§Arguments
command
- A command sent by the sender to either start a new transfer or update an existing one with a chunk of data.
§Returns
On success, this method returns a corresponding response:
- If a
StartTransfer
command is processed, it returnsAckStart
with thetransfer_id
. - If a
SetChunk
command is processed successfully, it returnsAckChunk
with information on the last chunk received in order as well as a receive-mask for up to 64 chunks after that.
§Errors
This function returns an io::Error
in the following cases:
-
If a
SetChunk
command is received and the transfer state has not been initialized (i.e., noStartTransfer
has been processed), it returns anio::Error
withErrorKind::InvalidData
and a message indicating that thetransfer_id
is unknown. -
Any I/O error encountered during the update of the logic will be propagated.
§Example
use blob_stream::in_logic_front::FrontLogic;
use blob_stream::protocol::StartTransferData;
use blob_stream::protocol_front::SenderToReceiverFrontCommands;
let mut logic_front = FrontLogic::new();
let start_command = SenderToReceiverFrontCommands::StartTransfer(StartTransferData {
transfer_id: 1234,
total_octet_size: 1024,
chunk_size: 256,
});
let response = logic_front.update(&start_command);
assert!(response.is_ok());
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.