rustlite_core/
format_version.rs1pub const SSTABLE_FORMAT_VERSION: u16 = 1;
7
8pub const WAL_FORMAT_VERSION: u16 = 1;
10
11pub const MANIFEST_FORMAT_VERSION: u16 = 1;
13
14pub mod magic {
16 pub const SSTABLE: u32 = 0x5253544C;
18
19 pub const WAL: u32 = 0x524C574C;
21
22 pub const MANIFEST: u32 = 0x524C4D46;
24}
25
26pub struct FormatVersion {
28 pub current: u16,
30 pub min_read: u16,
32 pub min_write: u16,
34}
35
36impl FormatVersion {
37 pub fn can_read(&self, version: u16) -> bool {
39 version >= self.min_read && version <= self.current
40 }
41
42 pub fn can_write(&self, version: u16) -> bool {
44 version >= self.min_write && version <= self.current
45 }
46}
47
48pub fn sstable_version() -> FormatVersion {
50 FormatVersion {
51 current: SSTABLE_FORMAT_VERSION,
52 min_read: 1,
53 min_write: 1,
54 }
55}
56
57pub fn wal_version() -> FormatVersion {
59 FormatVersion {
60 current: WAL_FORMAT_VERSION,
61 min_read: 1,
62 min_write: 1,
63 }
64}
65
66pub fn manifest_version() -> FormatVersion {
68 FormatVersion {
69 current: MANIFEST_FORMAT_VERSION,
70 min_read: 1,
71 min_write: 1,
72 }
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_version_compatibility() {
81 let v = sstable_version();
82 assert!(v.can_read(1));
83 assert!(v.can_write(1));
84 assert!(!v.can_read(0));
85 assert!(!v.can_read(999));
86 }
87}