Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions device/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ impl DequeueBufferEvent {
v4l2_buffer,
}
}

pub fn as_bytes(&self) -> &[u8] {
// SAFETY: `DequeueBufferEvent` is a C-compatible struct with no padding and fully initialized bytes.
unsafe {
std::slice::from_raw_parts(
self as *const Self as *const u8,
std::mem::size_of::<Self>(),
)
}
}
}

#[repr(C)]
Expand All @@ -306,6 +316,16 @@ impl SessionEvent {
v4l2_event,
}
}

pub fn as_bytes(&self) -> &[u8] {
// SAFETY: `SessionEvent` is a C-compatible struct with no padding and fully initialized bytes.
unsafe {
std::slice::from_raw_parts(
self as *const Self as *const u8,
std::mem::size_of::<Self>(),
)
}
}
}

#[allow(clippy::large_enum_variant)]
Expand Down