pub(crate) unsafe fn from_ptr<'a>(ptr: *const u8, len: usize) -> &'a [u8] {
debug_assert!(!ptr.is_null() || len == 0, "null ptr with len={len}");
if ptr.is_null() {
&[]
} else {
unsafe { core::slice::from_raw_parts(ptr, len) }
}
}
pub(crate) unsafe fn from_mut_ptr<'a>(ptr: *mut u8, len: usize) -> &'a mut [u8] {
debug_assert!(!ptr.is_null() || len == 0, "null ptr with len={len}");
if ptr.is_null() {
&mut []
} else {
unsafe { core::slice::from_raw_parts_mut(ptr, len) }
}
}
pub(crate) unsafe fn copy_out(src: &[u8], buf: *mut u8, buf_len: usize, out_len: *mut usize) {
if !out_len.is_null() {
unsafe { *out_len = src.len() };
}
if !buf.is_null() && buf_len > 0 {
let n = src.len().min(buf_len);
unsafe { core::ptr::copy_nonoverlapping(src.as_ptr(), buf, n) };
}
}