alopex_core/storage/format/
ingest.rs1use crate::storage::compression::CompressionAlgorithm;
4use crate::storage::format::{FormatError, SectionType};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct KeyRange {
9 pub start: Vec<u8>,
11 pub end: Vec<u8>,
13}
14
15impl KeyRange {
16 pub fn validate(&self) -> Result<(), FormatError> {
18 if self.start >= self.end {
19 return Err(FormatError::InvalidKeyRange {
20 start: self.start.clone(),
21 end: self.end.clone(),
22 });
23 }
24 Ok(())
25 }
26
27 pub fn overlaps(&self, other: &Self) -> bool {
29 !(self.end <= other.start || other.end <= self.start)
30 }
31}
32
33#[derive(Debug, Clone)]
35pub struct ExternalSectionIngest {
36 pub section_data: Vec<u8>,
38 pub compression: CompressionAlgorithm,
40 pub uncompressed_length: u64,
42 pub validate_uncompressed: bool,
44 pub section_type: SectionType,
46 pub key_range: KeyRange,
48}
49
50impl ExternalSectionIngest {
51 pub fn new(
53 section_data: Vec<u8>,
54 compression: CompressionAlgorithm,
55 uncompressed_length: u64,
56 section_type: SectionType,
57 key_range: KeyRange,
58 ) -> Self {
59 Self {
60 section_data,
61 compression,
62 uncompressed_length,
63 validate_uncompressed: false,
64 section_type,
65 key_range,
66 }
67 }
68
69 pub fn new_with_validation(
71 section_data: Vec<u8>,
72 compression: CompressionAlgorithm,
73 uncompressed_length: u64,
74 section_type: SectionType,
75 key_range: KeyRange,
76 ) -> Self {
77 Self {
78 section_data,
79 compression,
80 uncompressed_length,
81 validate_uncompressed: true,
82 section_type,
83 key_range,
84 }
85 }
86}