Skip to main content

rvf_types/
segment_type.rs

1//! Segment type discriminator for the RVF format.
2
3/// Identifies the kind of data stored in a segment.
4///
5/// Values `0x00` and `0xF0..=0xFF` are reserved.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[repr(u8)]
9pub enum SegmentType {
10    /// Not a valid segment (uninitialized / zeroed region).
11    Invalid = 0x00,
12    /// Raw vector payloads (the actual embeddings).
13    Vec = 0x01,
14    /// HNSW adjacency lists, entry points, routing tables.
15    Index = 0x02,
16    /// Graph overlay deltas, partition updates, min-cut witnesses.
17    Overlay = 0x03,
18    /// Metadata mutations (label changes, deletions, moves).
19    Journal = 0x04,
20    /// Segment directory, hotset pointers, epoch state.
21    Manifest = 0x05,
22    /// Quantization dictionaries and codebooks.
23    Quant = 0x06,
24    /// Arbitrary key-value metadata (tags, provenance, lineage).
25    Meta = 0x07,
26    /// Temperature-promoted hot data (vectors + neighbors).
27    Hot = 0x08,
28    /// Access counter sketches for temperature decisions.
29    Sketch = 0x09,
30    /// Capability manifests, proof of computation, audit trails.
31    Witness = 0x0A,
32    /// Domain profile declarations (RVDNA, RVText, etc.).
33    Profile = 0x0B,
34    /// Key material, signature chains, certificate anchors.
35    Crypto = 0x0C,
36    /// Metadata inverted indexes for filtered search.
37    MetaIdx = 0x0D,
38    /// Embedded kernel / unikernel image for self-booting.
39    Kernel = 0x0E,
40    /// Embedded eBPF program for kernel fast path.
41    Ebpf = 0x0F,
42    /// COW cluster mapping.
43    CowMap = 0x20,
44    /// Cluster reference counts.
45    Refcount = 0x21,
46    /// Vector membership filter.
47    Membership = 0x22,
48    /// Sparse delta patches.
49    Delta = 0x23,
50}
51
52impl TryFrom<u8> for SegmentType {
53    type Error = u8;
54
55    fn try_from(value: u8) -> Result<Self, Self::Error> {
56        match value {
57            0x00 => Ok(Self::Invalid),
58            0x01 => Ok(Self::Vec),
59            0x02 => Ok(Self::Index),
60            0x03 => Ok(Self::Overlay),
61            0x04 => Ok(Self::Journal),
62            0x05 => Ok(Self::Manifest),
63            0x06 => Ok(Self::Quant),
64            0x07 => Ok(Self::Meta),
65            0x08 => Ok(Self::Hot),
66            0x09 => Ok(Self::Sketch),
67            0x0A => Ok(Self::Witness),
68            0x0B => Ok(Self::Profile),
69            0x0C => Ok(Self::Crypto),
70            0x0D => Ok(Self::MetaIdx),
71            0x0E => Ok(Self::Kernel),
72            0x0F => Ok(Self::Ebpf),
73            0x20 => Ok(Self::CowMap),
74            0x21 => Ok(Self::Refcount),
75            0x22 => Ok(Self::Membership),
76            0x23 => Ok(Self::Delta),
77            other => Err(other),
78        }
79    }
80}
81
82#[cfg(test)]
83mod tests {
84    use super::*;
85
86    #[test]
87    fn round_trip_all_variants() {
88        let variants = [
89            SegmentType::Invalid,
90            SegmentType::Vec,
91            SegmentType::Index,
92            SegmentType::Overlay,
93            SegmentType::Journal,
94            SegmentType::Manifest,
95            SegmentType::Quant,
96            SegmentType::Meta,
97            SegmentType::Hot,
98            SegmentType::Sketch,
99            SegmentType::Witness,
100            SegmentType::Profile,
101            SegmentType::Crypto,
102            SegmentType::MetaIdx,
103            SegmentType::Kernel,
104            SegmentType::Ebpf,
105            SegmentType::CowMap,
106            SegmentType::Refcount,
107            SegmentType::Membership,
108            SegmentType::Delta,
109        ];
110        for v in variants {
111            let raw = v as u8;
112            assert_eq!(SegmentType::try_from(raw), Ok(v));
113        }
114    }
115
116    #[test]
117    fn invalid_value_returns_err() {
118        assert_eq!(SegmentType::try_from(0x24), Err(0x24));
119        assert_eq!(SegmentType::try_from(0xF0), Err(0xF0));
120        assert_eq!(SegmentType::try_from(0xFF), Err(0xFF));
121    }
122
123    #[test]
124    fn kernel_and_ebpf_discriminants() {
125        assert_eq!(SegmentType::Kernel as u8, 0x0E);
126        assert_eq!(SegmentType::Ebpf as u8, 0x0F);
127    }
128}