reifydb_codec/row/queue_deduplication/
mod.rs1use std::ops::Deref;
5
6use reifydb_value::value::{datetime::DateTime, row_number::RowNumber};
7
8use crate::row::{
9 bytes::{
10 EncodedBytes, EncodedRowBuilder, RowBuilder, read_created_at, read_deduplication_row_number,
11 read_expires_at, read_fingerprint, read_updated_at, sealed::Sealed, write_deduplication_row_number,
12 write_expires_at, write_fingerprint, write_storage_time, write_timestamps,
13 },
14 shape::fingerprint::RowShapeFingerprint,
15};
16
17#[repr(transparent)]
18#[derive(Debug, Clone, PartialEq)]
19pub struct EncodedQueueDeduplicationRow(EncodedBytes);
20
21impl EncodedQueueDeduplicationRow {
22 pub fn view(bytes: &EncodedBytes) -> &Self {
23 unsafe { &*(bytes as *const EncodedBytes as *const Self) }
26 }
27
28 pub fn bytes(&self) -> &EncodedBytes {
29 &self.0
30 }
31
32 pub fn as_slice(&self) -> &[u8] {
33 self.0.as_slice()
34 }
35
36 pub fn into_bytes(self) -> EncodedBytes {
37 self.0
38 }
39
40 #[inline]
41 pub fn fingerprint(&self) -> RowShapeFingerprint {
42 read_fingerprint(&self.0)
43 }
44
45 #[inline]
46 pub fn created_at(&self) -> DateTime {
47 read_created_at(&self.0)
48 }
49
50 #[inline]
51 pub fn updated_at(&self) -> DateTime {
52 read_updated_at(&self.0)
53 }
54
55 #[inline]
56 pub fn row_number(&self) -> RowNumber {
57 read_deduplication_row_number(&self.0)
58 }
59
60 #[inline]
61 pub fn expires_at(&self) -> DateTime {
62 read_expires_at(&self.0)
63 }
64}
65
66impl From<EncodedQueueDeduplicationRow> for EncodedBytes {
67 fn from(row: EncodedQueueDeduplicationRow) -> Self {
68 row.0
69 }
70}
71
72impl From<EncodedBytes> for EncodedQueueDeduplicationRow {
73 fn from(bytes: EncodedBytes) -> Self {
74 Self(bytes)
75 }
76}
77
78#[repr(transparent)]
79#[derive(Debug, Clone, PartialEq, Eq)]
80pub struct EncodedQueueDeduplicationRowBuilder(EncodedRowBuilder);
81
82impl EncodedQueueDeduplicationRowBuilder {
83 pub(crate) fn wrap(builder: EncodedRowBuilder) -> Self {
84 Self(builder)
85 }
86
87 #[inline]
88 pub fn fingerprint(&self) -> RowShapeFingerprint {
89 read_fingerprint(self.as_slice())
90 }
91
92 pub fn set_fingerprint(&mut self, fingerprint: RowShapeFingerprint) {
93 write_fingerprint(self.as_mut_slice(), fingerprint);
94 }
95
96 #[inline]
97 pub fn created_at(&self) -> DateTime {
98 read_created_at(self.as_slice())
99 }
100
101 #[inline]
102 pub fn updated_at(&self) -> DateTime {
103 read_updated_at(self.as_slice())
104 }
105
106 pub fn set_timestamps(&mut self, created_at: DateTime, updated_at: DateTime) {
107 write_timestamps(self.as_mut_slice(), created_at, updated_at);
108 }
109
110 pub fn set_time(&mut self, time: DateTime) {
111 write_storage_time(self.as_mut_slice(), time);
112 }
113
114 #[inline]
115 pub fn row_number(&self) -> RowNumber {
116 read_deduplication_row_number(self.as_slice())
117 }
118
119 pub fn set_row_number(&mut self, row_number: RowNumber) {
120 write_deduplication_row_number(self.as_mut_slice(), row_number);
121 }
122
123 #[inline]
124 pub fn expires_at(&self) -> DateTime {
125 read_expires_at(self.as_slice())
126 }
127
128 pub fn set_expires_at(&mut self, expires_at: DateTime) {
129 write_expires_at(self.as_mut_slice(), expires_at);
130 }
131
132 pub fn freeze(self) -> EncodedQueueDeduplicationRow {
133 EncodedQueueDeduplicationRow(self.0.freeze())
134 }
135}
136
137impl Sealed for EncodedQueueDeduplicationRowBuilder {
138 fn buffer(&self) -> &Vec<u8> {
139 self.0.buffer()
140 }
141
142 fn buffer_mut(&mut self) -> &mut Vec<u8> {
143 self.0.buffer_mut()
144 }
145
146 fn take_buffer(self) -> Vec<u8> {
147 self.0.take_buffer()
148 }
149}
150
151impl EncodedQueueDeduplicationRow {
152 pub fn thaw(self) -> EncodedQueueDeduplicationRowBuilder {
153 EncodedQueueDeduplicationRowBuilder(self.0.thaw())
154 }
155}
156
157impl Deref for EncodedQueueDeduplicationRowBuilder {
158 type Target = [u8];
159
160 fn deref(&self) -> &Self::Target {
161 self.as_slice()
162 }
163}