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 receive(
&mut self,
command: &SenderToReceiverFrontCommands,
) -> Result<(), FrontLogicError>
pub fn receive( &mut self, command: &SenderToReceiverFrontCommands, ) -> Result<(), FrontLogicError>
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
StartTransfercommand is processed, it returnsAckStartwith thetransfer_id. - If a
SetChunkcommand is processed successfully, it returnsAckChunkwith 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
SetChunkcommand is received and the transfer state has not been initialized (i.e., noStartTransferhas been processed), it returns anio::ErrorwithErrorKind::InvalidDataand a message indicating that thetransfer_idis unknown. -
Any I/O error encountered during the update of the logic will be propagated.
§Example
use nimble_blob_stream::in_logic_front::FrontLogic;
use nimble_blob_stream::protocol::StartTransferData;
use nimble_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.receive(&start_command);
assert!(response.is_ok());pub fn send(&mut self) -> Option<ReceiverToSenderFrontCommands>
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.