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
15 changes: 11 additions & 4 deletions rust/fory-core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@ impl<'a> Writer<'a> {

#[inline(always)]
pub fn set_bytes(&mut self, offset: usize, data: &[u8]) {
self.bf
.get_mut(offset..offset + data.len())
.unwrap()
.copy_from_slice(data);
debug_assert!(offset + data.len() <= self.bf.len());
// SAFETY: Callers write placeholder bytes first (via write_*/skip), then
// call set_bytes to back-fill. The offset always points to previously
// written data within bounds.
unsafe {
std::ptr::copy_nonoverlapping(
data.as_ptr(),
self.bf.as_mut_ptr().add(offset),
data.len(),
);
}
}

#[inline(always)]
Expand Down
Loading