scdb/internal/entries/values/shared.rs
1use crate::internal::get_current_timestamp;
2use std::io;
3
4pub(crate) trait ValueEntry<'a>: Sized {
5 /// Gets the expiry of the value entry
6 fn get_expiry(&self) -> u64;
7
8 /// Extracts the value entry from the data array
9 fn from_data_array(data: &'a [u8], offset: usize) -> io::Result<Self>;
10
11 /// Retrieves the byte array that represents the value entry.
12 fn as_bytes(&self) -> Vec<u8>;
13
14 /// Returns true if key has lived for longer than its time-to-live
15 /// It will always return false if time-to-live was never set
16 fn is_expired(&self) -> bool {
17 let expiry = self.get_expiry();
18 if expiry == 0 {
19 false
20 } else {
21 expiry < get_current_timestamp()
22 }
23 }
24}