Function writeSliceAssumeCapacity [src]

Write bytes into the ring buffer. If there is not enough space, older bytes will be overwritten. Uses memcpy and so bytes must not overlap ring buffer data.

Prototype

pub fn writeSliceAssumeCapacity(self: *RingBuffer, bytes: []const u8) void

Parameters

self: *RingBufferbytes: []const u8

Source

pub fn writeSliceAssumeCapacity(self: *RingBuffer, bytes: []const u8) void { assert(bytes.len <= self.data.len); const data_start = self.mask(self.write_index); const part1_data_end = @min(data_start + bytes.len, self.data.len); const part1_len = part1_data_end - data_start; @memcpy(self.data[data_start..part1_data_end], bytes[0..part1_len]); const remaining = bytes.len - part1_len; const to_write = @min(remaining, remaining % self.data.len + self.data.len); const part2_bytes_start = bytes.len - to_write; const part2_bytes_end = @min(part2_bytes_start + self.data.len, bytes.len); const part2_len = part2_bytes_end - part2_bytes_start; @memcpy(self.data[0..part2_len], bytes[part2_bytes_start..part2_bytes_end]); if (part2_bytes_end != bytes.len) { const part3_len = bytes.len - part2_bytes_end; @memcpy(self.data[0..part3_len], bytes[part2_bytes_end..bytes.len]); } self.write_index = self.mask2(self.write_index + bytes.len); }