reifydb_core/value/encoded/
encoded.rs1use std::ops::Deref;
5
6use serde::{Deserialize, Serialize};
7
8use crate::util::CowVec;
9
10pub type EncodedValuesIter = Box<dyn EncodedValuesIterator>;
12
13pub trait EncodedValuesIterator: Iterator<Item = EncodedValues> {}
14
15impl<I: Iterator<Item = EncodedValues>> EncodedValuesIterator for I {}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[derive(PartialEq, Eq)]
20pub struct EncodedValues(pub CowVec<u8>);
21
22impl Deref for EncodedValues {
23 type Target = CowVec<u8>;
24
25 fn deref(&self) -> &Self::Target {
26 &self.0
27 }
28}
29
30impl EncodedValues {
31 pub fn make_mut(&mut self) -> &mut [u8] {
32 self.0.make_mut()
33 }
34
35 #[inline]
36 pub fn is_defined(&self, index: usize) -> bool {
37 let byte = index / 8;
38 let bit = index % 8;
39 (self.0[byte] & (1 << bit)) != 0
40 }
41
42 pub(crate) fn set_valid(&mut self, index: usize, bitvec: bool) {
43 let byte = index / 8;
44 let bit = index % 8;
45 if bitvec {
46 self.0.make_mut()[byte] |= 1 << bit;
47 } else {
48 self.0.make_mut()[byte] &= !(1 << bit);
49 }
50 }
51}