Struct Logic

Source
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

Source

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);
Source

pub fn info(&self) -> Info

Source

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();
Source

pub fn send(&mut self) -> AckChunkData

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.

§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
}
Source

pub fn is_complete(&self) -> bool

Trait Implementations§

Source§

impl Debug for Logic

Source§

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

Formats the value using the given formatter. Read more

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> 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.