DataItem

Struct DataItem 

Source
pub struct DataItem { /* private fields */ }
Expand description

Represents a data item with header information, names, a value payload, and a checksum for validation.

Implementations§

Source§

impl DataItem

Source

pub fn item_size(&self) -> u32

Calculates the total binary size of the DataItem.

This includes the fixed header size, sizes of the group name, item name, value, and the checksum (2 bytes).

§Returns
  • The full size of the item as a u32 value.
Source

pub fn item_header(&self) -> &DataItemHeader

Provides a reference to the DataItemHeader of this item.

§Returns
  • A reference to the contained DataItemHeader.
Source

pub fn name(&self) -> &str

Returns the name of the item as a string slice.

§Returns
  • A string slice representing the item name.
Source

pub fn group(&self) -> &str

Returns the group name of the item as a string slice.

§Returns
  • A string slice representing the group name.
Source

pub fn data(&self) -> &[u8]

Returns a byte slice containing the item’s value data.

§Returns
  • A slice of bytes representing the value of the data item.

Trait Implementations§

Source§

impl Debug for DataItem

Source§

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

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

impl Default for DataItem

Source§

fn default() -> Self

Creates a new DataItem with default values.

§Returns
  • A DataItem instance where all fields are initialized to their default states, including an empty group and item names, zero checksum, and an empty value vector.
Source§

impl FromStream for DataItem

Source§

fn read_from<R>(&mut self, reader: &mut R) -> Result<(), Error>
where R: Read + Seek,

Reads a DataItem from a binary stream.

This method reads the header first, then if the status is not Empty or Unknown, it reads the group name, item name, value bytes, and checksum from the stream.

The group and item names are read as UTF-8 strings and exclude the trailing null byte.

§Parameters
  • reader: A mutable reference to a reader implementing Read and Seek.
§Returns
  • Ok(()) if the item was read successfully.
  • Err(Error) if any I/O error occurs or UTF-8 conversion fails.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.