Struct DrmEvent

Source
#[repr(C)]
pub struct DrmEvent { pub hdr: DrmEventHeader, pub body: [u8], }
Expand description

A raw DRM event.

This is a dynamically-sized type because DRM returns events of varying sizes. DRM events typically come from reading the file descriptor associated with a “card” device.

If you have a byte slice you’ve read from a card device then you can use DrmEvent::from_bytes to safely build a DrmEvent from the first event, if any.

Fields§

§hdr: DrmEventHeader§body: [u8]

Implementations§

Source§

impl DrmEvent

Source

pub unsafe fn from_event_header<'a>(hdr: &'a DrmEventHeader) -> &'a DrmEvent

Given a reference to the header part of a valid event, reinterprets it into a full DrmEvent object.

§Safety

The given reference must be to a valid header that is at the start of an event object whose length matches that given in the header. The result is a wide pointer that tracks the body length, which safe Rust cannot modify and so can be relied on by safe methods of DrmEvent while the header length cannot.

Source

pub fn from_bytes<'a>(buf: &'a [u8]) -> Option<(&'a DrmEvent, &'a [u8])>

Given a byte slice that contains zero or more DRM events, obtain the first event and a slice of the remaining bytes, or None if there aren’t enough bytes left to extract even one event.

The returned event does not necessarily have valid content. The only checking done by this function is that there are enough bytes in the slice for the length claimed in the header field.

Source

pub fn body_len(&self) -> usize

Get the length of the body in bytes.

This is based on the information stored in the wide pointer underlying self, and so ignores the length given in the header.

Source

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

Get the body of the event as a raw byte slice.

Source

pub fn body_ptr<T: Sized>(&self) -> *const T

Get a pointer to the event body that interprets it as a value of T.

Dereferencing the returned pointer is undefined behavior unless the body is long enough to contain a T and contains a valid representation of T.

Source

pub unsafe fn body_as<T>(&self) -> Option<&T>

Get a reference to the body interpreted as type T only if the body is at least long enough to fit a value of that type.

§Safety

Caller must ensure that the raw body is a valid representation of T. If all bit patterns are valid representations of T then this is always safe but the result might still be nonsense.

Source

pub unsafe fn body_as_unchecked<T>(&self) -> &T

Returns a reference to the body interpreted as type T without checking whether the header’s indicated length is long enough for that type.

§Safety

Caller must ensure that there’s enough valid memory after the event header for a T and that the data there is a valid representation of T.

Trait Implementations§

Source§

impl Pointee for DrmEvent
where [u8]: Pointee,

Source§

type Metadata = <[u8] as Pointee>::Metadata

The metadata type for pointers and references to this type.

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