use std::sync::Arc;
use core_types::BufferId;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum BufferKind {
Owned,
Shared,
}
#[derive(Clone, Debug)]
pub struct Buffer {
pub id: BufferId,
pub kind: BufferKind,
bytes: Arc<[u8]>,
}
impl Buffer {
pub fn from_vec(id: BufferId, data: Vec<u8>) -> Self {
Self {
id,
kind: BufferKind::Owned,
bytes: Arc::from(data.into_boxed_slice()),
}
}
pub fn len(&self) -> usize {
self.bytes.len()
}
pub fn is_empty(&self) -> bool {
self.bytes.is_empty()
}
pub fn as_slice(&self) -> &[u8] {
&self.bytes
}
}