Skip to main content

ZbiItem

Struct ZbiItem 

Source
pub struct ZbiItem<B: SplitByteSlice> {
    pub header: Ref<B, ZbiHeader>,
    pub payload: B,
}
Expand description

ZbiItem is element representation in ZbiContainer

It contains of header and payload. Both contain references to actual location in buffer. And payload goes right after header in the buffer.

Header must be ZBI_ALIGNMENT_USIZE aligned in the buffer. The length field specifies the actual payload length and does not include the size of padding. Since all headers in ZbiContainer are ZBI_ALIGNMENT_USIZE aligned payload may be followed by padding, which is included in ZbiContainer length, but not in each ZbiItem

Fields§

§header: Ref<B, ZbiHeader>

ZBI header

§payload: B

Payload corresponding to ZBI header

Implementations§

Source§

impl<B: SplitByteSlice + PartialEq> ZbiItem<B>

Source

pub fn parse(buffer: B) -> Result<(ZbiItem<B>, B), ZbiError>

Attempts to parse provided buffer.

§Arguments
  • buffer - buffer to parse (can be mutable if further changes to element is required)
§Returns
  • Ok((ZbiItem, tail)) - if parsing was successful function returns ZbiItem and tail of buffer that wasn’t used.
  • Err(ZbiError) - if parsing fails Err is returned.
§Example
use zbi::ZbiItem;

let (zbi_item, tail) = ZbiItem::parse(buffer).unwrap();
println!("{}", zbi_item.header.type_);
println!("{}", tail.len());
assert_eq!(zbi_item.header.length, zbi_item.payload.len() as u32);
Source

pub fn is_valid(&self) -> Result<(), ZbiError>

Validates ZbiItem header values.

§Example
use zbi::{ZbiItem, ZbiError};

// E.g. if `header.magic = 0` this is invalid value.
let (zbi_item, tail) = ZbiItem::parse(buffer).unwrap();
assert_eq!(zbi_item.header.magic, 0);
assert_eq!(zbi_item.is_valid(), Err(ZbiError::BadMagic));
Source§

impl<B: SplitByteSliceMut + PartialEq> ZbiItem<B>

Source

pub fn new( buffer: B, type_: ZbiType, extra: u32, flags: ZbiFlags, payload_len: usize, ) -> Result<(ZbiItem<B>, B), ZbiError>

Create ZbiItem with provided information and payload length.

§Result
  • (ZbiItem, tail) - returned on success. ZbiItem would have payload of requested length. And tail would be remaining part of the buffer that wasn’t used.
  • ZbiError::BadAlignment - if buffer wasn’t aligned.
  • ZbiError::TooBig - if buffer is not long enough to hold ZbiHeader + payload of payload_len.
  • ZbiError::PlatformBadLength - if payload_len value is bigger than u32::MAX
§Example
use zbi::{ZbiItem, ZbiFlags, ZbiType};

let (item, _tail) = ZbiItem::new(
    &mut buffer[..],
    ZbiType::KernelX64,
    0,
    ZbiFlags::default(),
    2,
).unwrap();
assert_eq!(item.header.length, 2);
assert_eq!(item.payload.len(), 2);

Trait Implementations§

Source§

impl<B: Debug + SplitByteSlice> Debug for ZbiItem<B>

Source§

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

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

impl<B: SplitByteSlice, C: SplitByteSlice> PartialEq<ZbiItem<C>> for ZbiItem<B>

Source§

fn eq(&self, other: &ZbiItem<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<B> Freeze for ZbiItem<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for ZbiItem<B>
where B: RefUnwindSafe,

§

impl<B> Send for ZbiItem<B>
where B: Send,

§

impl<B> Sync for ZbiItem<B>
where B: Sync,

§

impl<B> Unpin for ZbiItem<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for ZbiItem<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for ZbiItem<B>
where B: UnwindSafe,

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.