Skip to main content

reifydb_core/key/
kind.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::error::Error;
5use serde::{Deserialize, Serialize};
6
7#[repr(u8)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[serde(try_from = "u8", into = "u8")]
10pub enum KeyKind {
11	Namespace = 0x01,
12	Table = 0x02,
13	Row = 0x03,
14	NamespaceTable = 0x04,
15	SystemSequence = 0x05,
16	Columns = 0x06,
17	Column = 0x07,
18	RowSequence = 0x08,
19	ColumnPolicy = 0x09,
20	SystemVersion = 0x0A,
21	TransactionVersion = 0x0B,
22	Index = 0x0C,
23	IndexEntry = 0x0D,
24	ColumnSequence = 0x0E,
25	CdcConsumer = 0x0F,
26	View = 0x10,
27	NamespaceView = 0x11,
28	PrimaryKey = 0x12,
29	FlowNodeState = 0x13,
30	RingBuffer = 0x14,
31	NamespaceRingBuffer = 0x15,
32	RingBufferMetadata = 0x16,
33	PrimitiveRetentionPolicy = 0x17,
34	OperatorRetentionPolicy = 0x18,
35	Flow = 0x19,
36	NamespaceFlow = 0x1A,
37	FlowNode = 0x1B,
38	FlowNodeByFlow = 0x1C,
39	FlowEdge = 0x1D,
40	FlowEdgeByFlow = 0x1E,
41	FlowNodeInternalState = 0x1F,
42	Dictionary = 0x20,
43	DictionaryEntry = 0x21,
44	DictionaryEntryIndex = 0x22,
45	NamespaceDictionary = 0x23,
46	DictionarySequence = 0x24,
47	Metric = 0x25,
48	FlowVersion = 0x26,
49	Subscription = 0x27,
50	SubscriptionRow = 0x28,
51	SubscriptionColumn = 0x29,
52	Schema = 0x2A,
53	SchemaField = 0x2B,
54	SumType = 0x2C,
55	NamespaceSumType = 0x2D,
56}
57
58impl From<KeyKind> for u8 {
59	fn from(kind: KeyKind) -> Self {
60		kind as u8
61	}
62}
63impl TryFrom<u8> for KeyKind {
64	type Error = Error;
65
66	fn try_from(value: u8) -> Result<Self, Self::Error> {
67		match value {
68			0x01 => Ok(Self::Namespace),
69			0x02 => Ok(Self::Table),
70			0x03 => Ok(Self::Row),
71			0x04 => Ok(Self::NamespaceTable),
72			0x05 => Ok(Self::SystemSequence),
73			0x06 => Ok(Self::Columns),
74			0x07 => Ok(Self::Column),
75			0x08 => Ok(Self::RowSequence),
76			0x09 => Ok(Self::ColumnPolicy),
77			0x0A => Ok(Self::SystemVersion),
78			0x0B => Ok(Self::TransactionVersion),
79			0x0C => Ok(Self::Index),
80			0x0D => Ok(Self::IndexEntry),
81			0x0E => Ok(Self::ColumnSequence),
82			0x0F => Ok(Self::CdcConsumer),
83			0x10 => Ok(Self::View),
84			0x11 => Ok(Self::NamespaceView),
85			0x12 => Ok(Self::PrimaryKey),
86			0x13 => Ok(Self::FlowNodeState),
87			0x14 => Ok(Self::RingBuffer),
88			0x15 => Ok(Self::NamespaceRingBuffer),
89			0x16 => Ok(Self::RingBufferMetadata),
90			0x17 => Ok(Self::PrimitiveRetentionPolicy),
91			0x18 => Ok(Self::OperatorRetentionPolicy),
92			0x19 => Ok(Self::Flow),
93			0x1A => Ok(Self::NamespaceFlow),
94			0x1B => Ok(Self::FlowNode),
95			0x1C => Ok(Self::FlowNodeByFlow),
96			0x1D => Ok(Self::FlowEdge),
97			0x1E => Ok(Self::FlowEdgeByFlow),
98			0x1F => Ok(Self::FlowNodeInternalState),
99			0x20 => Ok(Self::Dictionary),
100			0x21 => Ok(Self::DictionaryEntry),
101			0x22 => Ok(Self::DictionaryEntryIndex),
102			0x23 => Ok(Self::NamespaceDictionary),
103			0x24 => Ok(Self::DictionarySequence),
104			0x25 => Ok(Self::Metric),
105			0x26 => Ok(Self::FlowVersion),
106			0x27 => Ok(Self::Subscription),
107			0x28 => Ok(Self::SubscriptionRow),
108			0x29 => Ok(Self::SubscriptionColumn),
109			0x2A => Ok(Self::Schema),
110			0x2B => Ok(Self::SchemaField),
111			0x2C => Ok(Self::SumType),
112			0x2D => Ok(Self::NamespaceSumType),
113			_ => Err(serde::de::Error::custom(format!("Invalid KeyKind value: {value:#04x}"))),
114		}
115	}
116}