1use reifydb_codec::row::bytes::EncodedBytes;
5
6use crate::key::any::TaggedKey;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum Delta {
10 Set {
11 key: TaggedKey,
12 bytes: EncodedBytes,
13 },
14
15 Remove {
16 key: TaggedKey,
17 announce: RemoveAnnounce,
18 },
19}
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum RemoveVisibility {
23 Silent,
24
25 Announced,
26
27 Unobserved,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub enum RemoveAnnounce {
32 Silent,
33
34 Announced {
35 pre: EncodedBytes,
36 },
37
38 Unobserved {
39 pre: EncodedBytes,
40 },
41}
42
43impl RemoveAnnounce {
44 pub fn announces(&self) -> bool {
45 !matches!(self, Self::Silent)
46 }
47
48 pub fn visible(&self) -> bool {
49 matches!(self, Self::Announced { .. })
50 }
51
52 pub fn pre(&self) -> Option<&EncodedBytes> {
53 match self {
54 Self::Silent => None,
55 Self::Announced {
56 pre,
57 }
58 | Self::Unobserved {
59 pre,
60 } => Some(pre),
61 }
62 }
63}
64
65impl Delta {
66 pub fn remove_silent(key: TaggedKey) -> Self {
67 Self::Remove {
68 key,
69 announce: RemoveAnnounce::Silent,
70 }
71 }
72
73 pub fn remove_announced(key: TaggedKey, pre: EncodedBytes) -> Self {
74 Self::Remove {
75 key,
76 announce: RemoveAnnounce::Announced {
77 pre,
78 },
79 }
80 }
81
82 pub fn remove_unobserved(key: TaggedKey, pre: EncodedBytes) -> Self {
83 Self::Remove {
84 key,
85 announce: RemoveAnnounce::Unobserved {
86 pre,
87 },
88 }
89 }
90
91 pub fn key(&self) -> &TaggedKey {
92 match self {
93 Self::Set {
94 key,
95 ..
96 } => key,
97 Self::Remove {
98 key,
99 ..
100 } => key,
101 }
102 }
103
104 pub fn bytes(&self) -> Option<&EncodedBytes> {
105 match self {
106 Self::Set {
107 bytes,
108 ..
109 } => Some(bytes),
110 Self::Remove {
111 ..
112 } => None,
113 }
114 }
115
116 pub fn announces(&self) -> bool {
117 match self {
118 Self::Set {
119 ..
120 } => true,
121 Self::Remove {
122 announce,
123 ..
124 } => announce.announces(),
125 }
126 }
127}