rustlite_core/
format_version.rs1pub const SSTABLE_FORMAT_VERSION: u16 = 1;
8
9pub const WAL_FORMAT_VERSION: u16 = 1;
11
12pub const MANIFEST_FORMAT_VERSION: u16 = 1;
14
15pub mod magic {
17 pub const SSTABLE: u32 = 0x5253544C;
19
20 pub const WAL: u32 = 0x524C574C;
22
23 pub const MANIFEST: u32 = 0x524C4D46;
25}
26
27pub struct FormatVersion {
29 pub current: u16,
31 pub min_read: u16,
33 pub min_write: u16,
35}
36
37impl FormatVersion {
38 pub fn can_read(&self, version: u16) -> bool {
40 version >= self.min_read && version <= self.current
41 }
42
43 pub fn can_write(&self, version: u16) -> bool {
45 version >= self.min_write && version <= self.current
46 }
47}
48
49pub fn sstable_version() -> FormatVersion {
51 FormatVersion {
52 current: SSTABLE_FORMAT_VERSION,
53 min_read: 1,
54 min_write: 1,
55 }
56}
57
58pub fn wal_version() -> FormatVersion {
60 FormatVersion {
61 current: WAL_FORMAT_VERSION,
62 min_read: 1,
63 min_write: 1,
64 }
65}
66
67pub fn manifest_version() -> FormatVersion {
69 FormatVersion {
70 current: MANIFEST_FORMAT_VERSION,
71 min_read: 1,
72 min_write: 1,
73 }
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn test_version_compatibility() {
82 let v = sstable_version();
83 assert!(v.can_read(1));
84 assert!(v.can_write(1));
85 assert!(!v.can_read(0));
86 assert!(!v.can_read(999));
87 }
88}