#[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
impl DrmEvent
Sourcepub unsafe fn from_event_header<'a>(hdr: &'a DrmEventHeader) -> &'a DrmEvent
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.
Sourcepub fn from_bytes<'a>(buf: &'a [u8]) -> Option<(&'a DrmEvent, &'a [u8])>
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.
Sourcepub fn body_len(&self) -> usize
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.
Sourcepub fn body_bytes(&self) -> &[u8] ⓘ
pub fn body_bytes(&self) -> &[u8] ⓘ
Get the body of the event as a raw byte slice.
Sourcepub fn body_ptr<T: Sized>(&self) -> *const T
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
.
Sourcepub unsafe fn body_as<T>(&self) -> Option<&T>
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.
Sourcepub unsafe fn body_as_unchecked<T>(&self) -> &T
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
.