reifydb_core/interface/catalog/
ringbuffer.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use serde::{Deserialize, Serialize};
5
6use crate::interface::{ColumnDef, NamespaceId, PrimaryKeyDef, RingBufferId};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct RingBufferDef {
10	pub id: RingBufferId,
11	pub namespace: NamespaceId,
12	pub name: String,
13	pub columns: Vec<ColumnDef>,
14	pub capacity: u64,
15	pub primary_key: Option<PrimaryKeyDef>,
16}
17
18#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
19pub struct RingBufferMetadata {
20	pub id: RingBufferId,
21	pub capacity: u64,
22	pub count: u64,
23	pub head: u64, // Position of oldest entry
24	pub tail: u64, // Position for next insert
25}
26
27impl RingBufferMetadata {
28	pub fn new(buffer_id: RingBufferId, capacity: u64) -> Self {
29		Self {
30			id: buffer_id,
31			capacity,
32			count: 0,
33			head: 1,
34			tail: 1,
35		}
36	}
37
38	pub fn is_full(&self) -> bool {
39		self.count >= self.capacity
40	}
41
42	pub fn is_empty(&self) -> bool {
43		self.count == 0
44	}
45}