Skip to main content

acta/validate/
report.rs

1use crate::format::prologue::Prologue;
2
3/// The result of a sequential Acta v0.2 structural validation.
4///
5/// A report is only produced for a file that contains at least its schema
6/// frame, so [`frame_count`](Self::frame_count) is always one or more.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub struct ValidationReport {
9    format_version: (u16, u16),
10    feature_flags: u64,
11    frame_count: u64,
12    file_size: u64,
13    last_good_offset: u64,
14    incomplete_tail: bool,
15}
16
17impl ValidationReport {
18    /// The format version the prologue declares.
19    pub fn format_version(&self) -> (u16, u16) {
20        self.format_version
21    }
22
23    /// The prologue feature flags. Bit zero is `ROW_IDS`.
24    pub fn feature_flags(&self) -> u64 {
25        self.feature_flags
26    }
27
28    /// The number of complete frames, including the schema frame.
29    pub fn frame_count(&self) -> u64 {
30        self.frame_count
31    }
32
33    pub fn file_size(&self) -> u64 {
34        self.file_size
35    }
36
37    /// The byte after the last complete frame.
38    ///
39    /// A writer resumes appending here, and a repair tool may truncate here.
40    pub fn last_good_offset(&self) -> u64 {
41        self.last_good_offset
42    }
43
44    /// Whether the file ends inside a frame that is still being appended.
45    pub fn incomplete_tail(&self) -> bool {
46        self.incomplete_tail
47    }
48
49    pub(crate) fn complete(prologue: Prologue, frame_count: u64, file_size: u64) -> Self {
50        Self {
51            format_version: prologue.format_version,
52            feature_flags: prologue.feature_flags,
53            frame_count,
54            file_size,
55            last_good_offset: file_size,
56            incomplete_tail: false,
57        }
58    }
59
60    pub(crate) fn from_snapshot(
61        format_version: (u16, u16),
62        feature_flags: u64,
63        frame_count: u64,
64        file_size: u64,
65        last_good_offset: u64,
66        incomplete_tail: bool,
67    ) -> Self {
68        Self {
69            format_version,
70            feature_flags,
71            frame_count,
72            file_size,
73            last_good_offset,
74            incomplete_tail,
75        }
76    }
77
78    pub(crate) fn with_incomplete_tail(
79        prologue: Prologue,
80        frame_count: u64,
81        file_size: u64,
82        last_good_offset: u64,
83    ) -> Self {
84        Self {
85            format_version: prologue.format_version,
86            feature_flags: prologue.feature_flags,
87            frame_count,
88            file_size,
89            last_good_offset,
90            incomplete_tail: true,
91        }
92    }
93}