use crate::storage::compression::CompressionAlgorithm;
use crate::storage::format::{FormatError, SectionType};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyRange {
pub start: Vec<u8>,
pub end: Vec<u8>,
}
impl KeyRange {
pub fn validate(&self) -> Result<(), FormatError> {
if self.start >= self.end {
return Err(FormatError::InvalidKeyRange {
start: self.start.clone(),
end: self.end.clone(),
});
}
Ok(())
}
pub fn overlaps(&self, other: &Self) -> bool {
!(self.end <= other.start || other.end <= self.start)
}
}
#[derive(Debug, Clone)]
pub struct ExternalSectionIngest {
pub section_data: Vec<u8>,
pub compression: CompressionAlgorithm,
pub uncompressed_length: u64,
pub validate_uncompressed: bool,
pub section_type: SectionType,
pub key_range: KeyRange,
}
impl ExternalSectionIngest {
pub fn new(
section_data: Vec<u8>,
compression: CompressionAlgorithm,
uncompressed_length: u64,
section_type: SectionType,
key_range: KeyRange,
) -> Self {
Self {
section_data,
compression,
uncompressed_length,
validate_uncompressed: false,
section_type,
key_range,
}
}
pub fn new_with_validation(
section_data: Vec<u8>,
compression: CompressionAlgorithm,
uncompressed_length: u64,
section_type: SectionType,
key_range: KeyRange,
) -> Self {
Self {
section_data,
compression,
uncompressed_length,
validate_uncompressed: true,
section_type,
key_range,
}
}
}