diff --git a/device/src/protocol.rs b/device/src/protocol.rs index be8dafe..1d39c2f 100644 --- a/device/src/protocol.rs +++ b/device/src/protocol.rs @@ -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::(), + ) + } + } } #[repr(C)] @@ -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::(), + ) + } + } } #[allow(clippy::large_enum_variant)]