Struct 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

Source

pub const fn new() -> Self

Creates a new InLogicFront 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 InLogicFront instance.

Source

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 StartTransfer command is processed, it returns AckStart with the transfer_id.
  • If a SetChunk command is processed successfully, it returns AckChunk 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., no StartTransfer has been processed), it returns an io::Error with ErrorKind::InvalidData and a message indicating that the transfer_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.receive(&start_command);
assert!(response.is_ok());
Source

pub fn send(&mut self) -> Option<ReceiverToSenderFrontCommands>

Source

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.

Source

pub fn info(&self) -> Option<Info>

Trait Implementations§

Source§

impl Debug for FrontLogic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FrontLogic

Source§

fn default() -> FrontLogic

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.