• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jtmoon79 / super-speedy-syslog-searcher / 21787108938

07 Feb 2026 09:23PM UTC coverage: 68.29% (+0.5%) from 67.84%
21787108938

push

github

jtmoon79
(BIN) allow more partial -a -b patterns, refactor matching

190 of 229 new or added lines in 1 file covered. (82.97%)

213 existing lines in 4 files now uncovered.

15633 of 22892 relevant lines covered (68.29%)

136486.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.01
/src/readers/fixedstructreader.rs
1
// src/readers/fixedstructreader.rs
2

3
//! Implements a [`FixedStructReader`],
4
//! the driver of deriving [`FixedStruct`s] (acct/lastlog/utmp/etc.)
5
//! from a fixed C-struct format file using a [`BlockReader`].
6
//!
7
//! Sibling of [`SyslogProcessor`]. But simpler in a number of ways due to
8
//! predictable format of the fixedsturct files. Also, a `FixedStructReader`
9
//! does not presume entries are in chronological order.
10
//! Whereas `SyslogProcessor` presumes entries are in chronological order.
11
//! This makes a big difference for implementations.
12
//!
13
//! This is an _s4lib_ structure used by the binary program _s4_.
14
//!
15
//! Implements [Issue #70].
16
//!
17
//! [`FixedStructReader`]: self::FixedStructReader
18
//! [`FixedStruct`s]: crate::data::fixedstruct::FixedStruct
19
//! [`BlockReader`]: crate::readers::blockreader::BlockReader
20
//! [`SyslogProcessor`]: crate::readers::syslogprocessor::SyslogProcessor
21
//! [Issue #70]: https://github.com/jtmoon79/super-speedy-syslog-searcher/issues/70
22

23
// TODO: ask question on SO about difference in
24
//       `e_termination` and `e_exit` in `struct exit_status`
25
//       https://elixir.bootlin.com/glibc/glibc-2.37/source/bits/utmp.h#L48
26

27
use std::collections::{
28
    BTreeMap,
29
    LinkedList,
30
};
31
use std::fmt;
32
use std::io::{
33
    Error,
34
    ErrorKind,
35
    Result,
36
};
37

38
use ::more_asserts::{
39
    debug_assert_ge,
40
    debug_assert_le,
41
};
42
#[allow(unused_imports)]
43
use ::si_trace_print::{
44
    de,
45
    def1n,
46
    def1o,
47
    def1x,
48
    def1ñ,
49
    defn,
50
    defo,
51
    defx,
52
    defñ,
53
    den,
54
    deo,
55
    dex,
56
    deñ,
57
    pfn,
58
    pfo,
59
    pfx,
60
};
61

62
use crate::common::{
63
    Count,
64
    FPath,
65
    FileOffset,
66
    FileSz,
67
    FileType,
68
    FileTypeFixedStruct,
69
    ResultFind,
70
    debug_panic,
71
    summary_stat,
72
    summary_stats_enabled,
73
};
74
use crate::data::datetime::{
75
    dt_after_or_before,
76
    dt_pass_filters,
77
    DateTimeL,
78
    DateTimeLOpt,
79
    FixedOffset,
80
    Result_Filter_DateTime1,
81
    Result_Filter_DateTime2,
82
    SystemTime,
83
};
84
use crate::data::fixedstruct::{
85
    buffer_to_fixedstructptr,
86
    convert_datetime_tvpair,
87
    filesz_to_types,
88
    tv_pair_type,
89
    FixedStruct,
90
    FixedStructDynPtr,
91
    FixedStructType,
92
    FixedStructTypeSet,
93
    Score,
94
    ENTRY_SZ_MAX,
95
    ENTRY_SZ_MIN,
96
    TIMEVAL_SZ_MAX,
97
};
98
use crate::readers::blockreader::{
99
    BlockIndex,
100
    BlockOffset,
101
    BlockReader,
102
    BlockSz,
103
    ResultReadDataToBuffer,
104
};
105
use crate::readers::summary::Summary;
106
use crate::{
107
    de_err,
108
    de_wrn,
109
    e_err,
110
};
111

112
// -----------------
113
// FixedStructReader
114

115
/// Map [`FileOffset`] To [`FixedStruct`].
116
///
117
/// Storage for `FixedStruct` found from the underlying `BlockReader`.
118
/// FileOffset key is the first byte/offset that begins the `FixedStruct`.
119
///
120
/// [`FileOffset`]: crate::common::FileOffset
121
/// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
122
pub type FoToEntry = BTreeMap<FileOffset, FixedStruct>;
123

124
/// Map [`FileOffset`] To `FileOffset`
125
///
126
/// [`FileOffset`]: crate::common::FileOffset
127
pub type FoToFo = BTreeMap<FileOffset, FileOffset>;
128

129
pub type FoList = LinkedList<FileOffset>;
130

131
type MapTvPairToFo = BTreeMap<tv_pair_type, FileOffset>;
132

133
/// [`FixedStructReader.find`*] functions results.
134
///
135
/// [`FixedStructReader.find`*]: self::FixedStructReader#method.find_entry
136
pub type ResultFindFixedStruct = ResultFind<(FileOffset, FixedStruct), (Option<FileOffset>, Error)>;
137

138
pub type ResultFindFixedStructProcZeroBlock = ResultFind<(FixedStructType, Score, ListFileOffsetFixedStructPtr), Error>;
139

140
pub type ResultTvFo = Result<(usize, usize, usize, usize, MapTvPairToFo)>;
141

142
#[cfg(test)]
143
pub type DroppedBlocks = LinkedList<BlockOffset>;
144

145
type ListFileOffsetFixedStructPtr = LinkedList<(FileOffset, FixedStructDynPtr)>;
146

147
/// Enum return value for [`FixedStructReader::new`].
148
#[derive(Debug)]
149
pub enum ResultFixedStructReaderNew<E> {
150
    /// `FixedStructReader::new` was successful and returns the
151
    /// `FixedStructReader`
152
    FileOk(FixedStructReader),
153
    FileErrEmpty,
154
    FileErrTooSmall(String),
155
    /// No valid fixedstruct
156
    FileErrNoValidFixedStruct,
157
    /// No fixedstruct within the datetime filters
158
    FileErrNoFixedStructWithinDtFilters,
159
    /// Carries the `E` error data. This is how an [`Error`] is carried between
160
    /// a processing thread and the main printing thread
161
    FileErrIo(E),
162
}
163

164
pub type ResultFixedStructReaderNewError = ResultFixedStructReaderNew<Error>;
165

166
#[derive(Debug)]
167
pub enum ResultFixedStructReaderScoreFile<E> {
168
    /// `score_file` was successful; return the `FixedStructType`, `Score`,
169
    /// already processed `FixedStrcutDynPtr` entries (with associated offsets)
170
    FileOk(FixedStructType, Score, ListFileOffsetFixedStructPtr),
171
    FileErrEmpty,
172
    /// No valid fixedstruct
173
    FileErrNoValidFixedStruct,
174
    /// No high score for the file
175
    FileErrNoHighScore,
176
    /// Carries the `E` error data. This is how an [`Error`] is carried between
177
    /// a processing thread and the main printing thread
178
    FileErrIo(E),
179
}
180

181
pub type ResultFixedStructReaderScoreFileError = ResultFixedStructReaderScoreFile<Error>;
182

183
/// A specialized reader that uses [`BlockReader`] to read [`FixedStruct`]
184
/// entries in a file.
185
///
186
/// The `FixedStructReader` converts `\[u8\]` to `FixedStruct` in
187
/// [`buffer_to_fixedstructptr`].
188
///
189
/// ## Summary of operation
190
///
191
/// A `FixedStructReader` first deteremines the `FixedStructType` of the file
192
/// in [`preprocess_fixedstructtype`].
193
/// Then it scans all ***t***ime ***v***alues in each entry to determine the
194
/// order to process the entries in [`preprocess_timevalues`]. This implies the
195
/// `blockreader` must read the entire file into memory. So far, "in the wild"
196
/// user accounting records are only a few kilobytes at most. So reading the
197
/// entire file into memory should not put much strain on memory usage of a
198
/// typical desktop or server.
199
/// The processing of time values is done first and for the entire file
200
/// because records may not be stored in chronological order.
201
/// Then the caller makes repeated calls to [`process_entry_at`] which processes
202
/// the `FixedStruct`s found in the file.
203
///
204
/// 0x00 byte and 0xFF byte fixedstructs are considered a null entry and
205
/// ignored.
206
///
207
/// _XXX: not a rust "Reader"; does not implement trait [`Read`]._
208
///
209
/// [`buffer_to_fixedstructptr`]: crate::data::fixedstruct::buffer_to_fixedstructptr
210
/// [`BlockReader`]: crate::readers::blockreader::BlockReader
211
/// [`Read`]: std::io::Read
212
/// [`preprocess_fixedstructtype`]: FixedStructReader::preprocess_fixedstructtype
213
/// [`preprocess_timevalues`]: FixedStructReader::preprocess_timevalues
214
/// [`process_entry_at`]: FixedStructReader::process_entry_at
215
pub struct FixedStructReader {
216
    pub(crate) blockreader: BlockReader,
217
    fixedstruct_type: FixedStructType,
218
    filetype_fixedstruct: FileTypeFixedStruct,
219
    /// Size of a single [`FixedStruct`] entry.
220
    fixedstruct_size: usize,
221
    /// The highest score found during `preprocess_file`.
222
    /// Used to determine the `FixedStructType` of the file.
223
    high_score: Score,
224
    /// Timezone to use for conversions using function
225
    /// [`convert_tvpair_to_datetime`].
226
    ///
227
    /// [`convert_tvpair_to_datetime`]: crate::data::fixedstruct::convert_tvpair_to_datetime
228
    tz_offset: FixedOffset,
229
    /// A temporary hold for [`FixedStruct`] entries found
230
    /// by [`preprocess_fixedstructtype`]. Use `insert_cache_entry` and
231
    /// `remove_entry` to manage this cache.
232
    ///
233
    /// [`preprocess_fixedstructtype`]: FixedStructReader::preprocess_fixedstructtype
234
    pub(crate) cache_entries: FoToEntry,
235
    /// A mapping of all entries in the entire file (that pass the datetime
236
    /// filters), mapped by [`tv_pair_type`] to [`FileOffset`]. Created by
237
    /// [`preprocess_timevalues`].
238
    ///
239
    /// [`preprocess_timevalues`]: FixedStructReader::preprocess_timevalues
240
    pub(crate) map_tvpair_fo: MapTvPairToFo,
241
    pub(crate) block_use_count: BTreeMap<BlockOffset, usize>,
242
    /// The first entry found in the file, by `FileOffset`
243
    pub(crate) first_entry_fileoffset: FileOffset,
244
    /// "high watermark" of `FixedStruct` stored in `self.cache_entries`
245
    pub(crate) entries_stored_highest: usize,
246
    pub(crate) entries_out_of_order: usize,
247
    /// Internal stats - hits of `self.cache_entries` in `find_entry*` functions.
248
    pub(super) entries_hits: Count,
249
    /// Internal stats - misses of `self.cache_entries` in `find_entry*` functions.
250
    pub(super) entries_miss: Count,
251
    /// `Count` of `FixedStruct`s processed.
252
    ///
253
    /// Distinct from `self.cache_entries.len()` as that may have contents removed.
254
    pub(super) entries_processed: Count,
255
    /// Summary statistic.
256
    /// First (soonest) processed [`DateTimeL`] (not necessarily printed,
257
    /// not representative of the entire file).
258
    pub(super) dt_first: DateTimeLOpt,
259
    /// Summary statistic.
260
    /// Last (latest) processed [`DateTimeL`] (not necessarily printed,
261
    /// not representative of the entire file).
262
    pub(super) dt_last: DateTimeLOpt,
263
    /// Summary statistic.
264
    /// `Count` of dropped `FixedStruct`.
265
    pub(super) drop_entry_ok: Count,
266
    /// Summary statistic.
267
    /// `Count` of failed drop attempts of `FixedStruct`.
268
    pub(super) drop_entry_errors: Count,
269
    /// testing-only tracker of successfully dropped `FixedStruct`
270
    #[cfg(test)]
271
    pub(crate) dropped_blocks: DroppedBlocks,
272
    pub(super) map_tvpair_fo_max_len: usize,
273
    /// The last [`Error`], if any, as a `String`. Set by [`set_error`].
274
    ///
275
    /// Annoyingly, cannot [Clone or Copy `Error`].
276
    ///
277
    /// [`Error`]: std::io::Error
278
    /// [Clone or Copy `Error`]: https://github.com/rust-lang/rust/issues/24135
279
    /// [`set_error`]: self::FixedStructReader#method.set_error
280
    // TRACKING: https://github.com/rust-lang/rust/issues/24135
281
    error: Option<String>,
282
}
283

284
impl fmt::Debug for FixedStructReader {
285
    fn fmt(
70✔
286
        &self,
70✔
287
        f: &mut fmt::Formatter,
70✔
288
    ) -> fmt::Result {
70✔
289
        f.debug_struct("FixedStructReader")
70✔
290
            .field("Path", &self.path())
70✔
291
            .field("Entries", &self.cache_entries.len())
70✔
292
            .field("tz_offset", &self.tz_offset)
70✔
293
            .field("Error?", &self.error)
70✔
294
            .finish()
70✔
295
    }
70✔
296
}
297

298
// TODO: [2023/04] remove redundant variable prefix name `fixedstructreader_`
299
// TODO: [2023/05] instead of having 1:1 manual copying of `FixedStructReader`
300
//       fields to `SummaryFixedStructReader` fields, just store a
301
//       `SummaryFixedStructReader` in `FixedStructReader` and update directly.
302
#[allow(non_snake_case)]
303
#[derive(Clone, Default, Eq, PartialEq, Debug)]
304
pub struct SummaryFixedStructReader {
305
    pub fixedstructreader_fixedstructtype_opt: Option<FixedStructType>,
306
    pub fixedstructreader_filetypefixedstruct_opt: Option<FileTypeFixedStruct>,
307
    pub fixedstructreader_fixedstruct_size: usize,
308
    pub fixedstructreader_high_score: Score,
309
    pub fixedstructreader_utmp_entries: Count,
310
    pub fixedstructreader_first_entry_fileoffset: FileOffset,
311
    pub fixedstructreader_entries_out_of_order: usize,
312
    pub fixedstructreader_utmp_entries_max: Count,
313
    pub fixedstructreader_utmp_entries_hit: Count,
314
    pub fixedstructreader_utmp_entries_miss: Count,
315
    pub fixedstructreader_drop_entry_ok: Count,
316
    pub fixedstructreader_drop_entry_errors: Count,
317
    /// datetime soonest seen (not necessarily reflective of entire file)
318
    pub fixedstructreader_datetime_first: DateTimeLOpt,
319
    /// datetime latest seen (not necessarily reflective of entire file)
320
    pub fixedstructreader_datetime_last: DateTimeLOpt,
321
    pub fixedstructreader_map_tvpair_fo_max_len: usize,
322
}
323

324
/// Implement the FixedStructReader.
325
impl FixedStructReader {
326
    /// Create a new `FixedStructReader`.
327
    ///
328
    /// **NOTE:** this `new()` calls [`BlockerReader.read_block`],
329
    /// dissimilar from other
330
    /// `*Readers::new()` which try to avoid calls to `read_block`.
331
    /// This means the reading may return `Done` (like if the file is empty) and
332
    /// `Done` must be reflected in the return value of `new`. Hence this
333
    /// function has a specialized return value.
334
    ///
335
    /// [`BlockerReader.read_block`]: crate::readers::blockreader::BlockReader#method.read_block
336
    pub fn new(
201✔
337
        path: FPath,
201✔
338
        filetype: FileType,
201✔
339
        blocksz: BlockSz,
201✔
340
        tz_offset: FixedOffset,
201✔
341
        dt_filter_after: DateTimeLOpt,
201✔
342
        dt_filter_before: DateTimeLOpt,
201✔
343
    ) -> ResultFixedStructReaderNewError {
201✔
344
        def1n!(
201✔
345
            "({:?}, filetype={:?}, blocksz={:?}, {:?}, {:?}, {:?})",
346
            path, filetype, blocksz, tz_offset, dt_filter_after, dt_filter_before,
347
        );
348
        let mut blockreader = match BlockReader::new(path.clone(), filetype, blocksz) {
201✔
349
            Ok(blockreader_) => blockreader_,
200✔
350
            Err(err) => {
1✔
351
                def1x!("return Err {}", err);
1✔
352
                //return Some(Result::Err(err));
353
                return ResultFixedStructReaderNew::FileErrIo(err);
1✔
354
            }
355
        };
356
        let filetype_fixedstruct = match filetype {
200✔
357
            FileType::FixedStruct { archival_type: _, fixedstruct_type: type_ } => type_,
200✔
358
            _ => {
359
                debug_panic!("Unexpected FileType: {:?}", filetype);
×
360
                return ResultFixedStructReaderNew::FileErrIo(Error::new(
×
361
                    ErrorKind::InvalidData,
×
362
                    format!("Unexpected FileType {:?}", filetype),
×
363
                ));
×
364
            }
365
        };
366

367
        const ENTRY_SZ_MIN_FSZ: FileSz = ENTRY_SZ_MIN as FileSz;
368
        if blockreader.filesz() == 0 {
200✔
369
            def1x!("return FileErrEmpty");
1✔
370
            return ResultFixedStructReaderNew::FileErrEmpty;
1✔
371
        } else if blockreader.filesz() < ENTRY_SZ_MIN_FSZ {
199✔
372
            def1x!(
1✔
373
                "return FileErrTooSmall; {} < {} (ENTRY_SZ_MIN)",
374
                blockreader.filesz(), ENTRY_SZ_MIN_FSZ
1✔
375
            );
376
            return ResultFixedStructReaderNew::FileErrTooSmall(
1✔
377
                format!(
1✔
378
                    "file size {} < {} (ENTRY_SZ_MIN), file {:?}",
1✔
379
                    blockreader.filesz(), ENTRY_SZ_MIN_FSZ, path,
1✔
380
                )
1✔
381
            );
1✔
382
        }
198✔
383

384
        // preprocess the file, pass `oneblock=false` to process
385
        // the entire file. This is because `lastlog` files are often nearly
386
        // entirely null bytes until maybe one entry near the end, so this should
387
        // search past the first block of data.
388
        let (
389
            fixedstruct_type,
190✔
390
            high_score,
190✔
391
            list_entries,
190✔
392
        ) = match FixedStructReader::preprocess_fixedstructtype(
198✔
393
            &mut blockreader, &filetype_fixedstruct, false,
198✔
394
        ) {
198✔
395
            ResultFixedStructReaderScoreFileError::FileOk(
190✔
396
                fixedstruct_type_, high_score_, list_entries_,
190✔
397
            ) => (fixedstruct_type_, high_score_, list_entries_),
190✔
398
            ResultFixedStructReaderScoreFileError::FileErrEmpty => {
×
399
                def1x!("return FileErrEmpty");
×
400
                return ResultFixedStructReaderNew::FileErrEmpty;
×
401
            }
402
            ResultFixedStructReaderScoreFileError::FileErrNoHighScore => {
8✔
403
                def1x!("return FileErrNoHighScore");
8✔
404
                return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
8✔
405
            }
406
            ResultFixedStructReaderScoreFileError::FileErrNoValidFixedStruct => {
×
407
                def1x!("return FileErrNoValidFixedStruct");
×
408
                return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
×
409
            }
410
            ResultFixedStructReaderScoreFileError::FileErrIo(err) => {
×
411
                de_err!("FixedStructReader::preprocess_fixedstructtype Error {}; file {:?}",
×
412
                        err, blockreader.path());
×
413
                def1x!("return Err {:?}", err);
×
414
                return ResultFixedStructReaderNew::FileErrIo(err);
×
415
            }
416
        };
417

418
        let (total, invalid, valid_no_filter, out_of_order, map_tvpair_fo) = 
190✔
419
            match FixedStructReader::preprocess_timevalues(
190✔
420
                &mut blockreader,
190✔
421
                fixedstruct_type,
190✔
422
                &dt_filter_after,
190✔
423
                &dt_filter_before,
190✔
424
            )
190✔
425
        {
426
            ResultTvFo::Err(err) => {
×
427
                de_err!("FixedStructReader::preprocess_timevalues Error {}; file {:?}",
×
428
                        err, blockreader.path());
×
429
                def1x!("return Err {:?}", err);
×
430
                return ResultFixedStructReaderNew::FileErrIo(err);
×
431
            }
432
            ResultTvFo::Ok(
190✔
433
                (total_, invalid_, valid_no_filter_, out_of_order_, map_tvpair_fo_)
190✔
434
            ) =>
190✔
435
                (total_, invalid_, valid_no_filter_, out_of_order_, map_tvpair_fo_),
190✔
436
        };
437
        def1o!("total: {}, invalid: {}, valid_no_filter: {}, out_of_order: {}",
190✔
438
               total, invalid, valid_no_filter, out_of_order);
439
        #[cfg(debug_assertions)]
440
        {
441
            def1o!("map_tvpair_fo has {} entries", map_tvpair_fo.len());
190✔
442
            for (_tv_pair, _fo) in map_tvpair_fo.iter() {
1,094✔
443
                def1o!("map_tvpair_fo: [tv_pair: {:?}] = fo: {}", _tv_pair, _fo);
1,094✔
444
            }
445
        }
446
        debug_assert_ge!(total, invalid);
190✔
447
        debug_assert_ge!(total, valid_no_filter);
190✔
448

449
        if map_tvpair_fo.is_empty() {
190✔
450
            if valid_no_filter > 0 {
19✔
451
                def1x!("return FileErrNoFixedStructWithinDtFilters");
19✔
452
                return ResultFixedStructReaderNew::FileErrNoFixedStructWithinDtFilters;
19✔
453
            }
×
454
            def1x!("return FileErrNoValidFixedStruct");
×
455
            return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
×
456
        }
171✔
457

458
        // set `first_entry_fileoffset` to the first entry by fileoffset
459
        let mut first_entry_fileoffset: FileOffset = blockreader.filesz();
171✔
460
        for (_tv_pair, fo) in map_tvpair_fo.iter() {
1,094✔
461
            if &first_entry_fileoffset > fo {
1,094✔
462
                first_entry_fileoffset = *fo;
201✔
463
            }
961✔
464
        }
465
        debug_assert_ne!(first_entry_fileoffset, blockreader.filesz(), "failed to update first_entry_fileoffset");
171✔
466

467
        // create a mapping of blocks to not-yet-processed entries
468
        // later on, this will be used to proactively drop blocks
469
        let mut block_use_count: BTreeMap<BlockOffset, usize> = BTreeMap::new();
171✔
470
        def1o!("block_use_count create");
171✔
471
        for (_tv_pair, fo) in map_tvpair_fo.iter() {
1,094✔
472
            let bo_beg: BlockOffset = BlockReader::block_offset_at_file_offset(*fo, blocksz);
1,094✔
473
            let fo_end: FileOffset = *fo + fixedstruct_type.size() as FileOffset;
1,094✔
474
            let bo_end: BlockOffset = BlockReader::block_offset_at_file_offset(fo_end, blocksz);
1,094✔
475
            def1o!("blocksz = {}", blocksz);
1,094✔
476
            for bo in bo_beg..bo_end + 1 {
4,337✔
477
                match block_use_count.get_mut(&bo) {
4,337✔
478
                    Some(count) => {
923✔
479
                        let count_ = *count + 1;
923✔
480
                        def1o!(
923✔
481
                            "block_use_count[{}] += 1 ({}); [{}‥{}]; total span [{}‥{})",
482
                            bo,
483
                            count_,
484
                            *fo,
485
                            fo_end,
486
                            BlockReader::file_offset_at_block_offset(bo_beg, blocksz),
923✔
487
                            BlockReader::file_offset_at_block_offset(bo_end + 1, blocksz),
923✔
488
                        );
489
                        *count = count_;
923✔
490
                    }
491
                    None => {
492
                        def1o!(
3,414✔
493
                            "block_use_count[{}] = 1; [{}‥{}]; total span [{}‥{})",
494
                            bo,
495
                            *fo,
496
                            fo_end,
497
                            BlockReader::file_offset_at_block_offset(bo_beg, blocksz),
3,414✔
498
                            BlockReader::file_offset_at_block_offset(bo_end + 1, blocksz),
3,414✔
499
                        );
500
                        block_use_count.insert(bo, 1);
3,414✔
501
                    }
502
                }
503
            }
504
        }
505
        #[cfg(debug_assertions)]
506
        {
507
            for (bo, count) in block_use_count.iter() {
3,414✔
508
                def1o!(
3,414✔
509
                    "block_use_count[{}] = {}; total span [{}‥{}]",
510
                    bo,
511
                    count,
512
                    BlockReader::file_offset_at_block_offset(*bo, blocksz),
3,414✔
513
                    BlockReader::file_offset_at_block_offset(*bo + 1, blocksz),
3,414✔
514
                );
515
            }
516
        }
517

518
        let map_max_len = map_tvpair_fo.len();
171✔
519
        // now that the `fixedstruct_type` is known, create the FixedStructReader
520
        let mut fixedstructreader = FixedStructReader {
171✔
521
            blockreader,
171✔
522
            fixedstruct_type,
171✔
523
            filetype_fixedstruct,
171✔
524
            fixedstruct_size: fixedstruct_type.size(),
171✔
525
            high_score,
171✔
526
            tz_offset,
171✔
527
            cache_entries: FoToEntry::new(),
171✔
528
            map_tvpair_fo,
171✔
529
            block_use_count,
171✔
530
            first_entry_fileoffset,
171✔
531
            entries_stored_highest: 0,
171✔
532
            entries_out_of_order: out_of_order,
171✔
533
            entries_hits: 0,
171✔
534
            entries_miss: 0,
171✔
535
            entries_processed: 0,
171✔
536
            dt_first: DateTimeLOpt::None,
171✔
537
            dt_last: DateTimeLOpt::None,
171✔
538
            drop_entry_ok: 0,
171✔
539
            drop_entry_errors: 0,
171✔
540
            #[cfg(test)]
171✔
541
            dropped_blocks: DroppedBlocks::new(),
171✔
542
            map_tvpair_fo_max_len: map_max_len,
171✔
543
            error: None,
171✔
544
        };
171✔
545

546
        // store the entries found and processed during `preprocess_file` into
547
        // `fixedstructreader.cache_entries`, to avoid duplicating work later on
548
        for (fo, fixedstructptr) in list_entries.into_iter() {
536✔
549
            // TODO: cost-savings: if `FixedStructTrait` had a `tv_pair` function then that time
550
            //       value could be checked against `map_tvpair_fo` *before* creating a new
551
            //       `FixedStruct`. However, the maximum number of `FixedStruct` entries
552
            //       created and then discarded will be very few so this is a marginal
553
            //       improvement.
554
            match FixedStruct::from_fixedstructptr(fo, &tz_offset, fixedstructptr) {
536✔
555
                Ok(fixedstruct) => {
536✔
556
                    if fixedstructreader
536✔
557
                        .map_tvpair_fo
536✔
558
                        .iter()
536✔
559
                        .any(|(_tv_pair, fo2)| &fo == fo2)
1,331✔
560
                    {
561
                        def1o!("insert entry at fo {}", fo);
508✔
562
                        fixedstructreader.insert_cache_entry(fixedstruct);
508✔
563
                    } else {
564
                        def1o!("skip entry at fo {}; not in map_tvpair_fo", fo);
28✔
565
                    }
566
                }
567
                Err(err) => {
×
568
                    de_err!("FixedStruct::from_fixedstructptr Error {}; file {:?}", err, fixedstructreader.path());
×
569
                    fixedstructreader.set_error(&err);
×
570
                }
×
571
            }
572
        }
573

574
        def1x!("return FileOk(FixedStructReader)");
171✔
575

576
        ResultFixedStructReaderNew::FileOk(fixedstructreader)
171✔
577
    }
201✔
578

579
    /// See [`BlockReader::blocksz`].
580
    ///
581
    /// [`BlockReader::blocksz`]: crate::readers::blockreader::BlockReader#method.blocksz
582
    #[inline(always)]
583
    pub const fn blocksz(&self) -> BlockSz {
1,039✔
584
        self.blockreader.blocksz()
1,039✔
585
    }
1,039✔
586

587
    /// See [`BlockReader::filesz`].
588
    ///
589
    /// [`BlockReader::filesz`]: crate::readers::blockreader::BlockReader#method.filesz
590
    #[inline(always)]
591
    pub const fn filesz(&self) -> FileSz {
2,296✔
592
        self.blockreader.filesz()
2,296✔
593
    }
2,296✔
594

595
    /// See [`BlockReader::filetype`].
596
    ///
597
    /// [`BlockReader::filetype`]: crate::readers::blockreader::BlockReader#method.filetype
598
    #[inline(always)]
599
    pub const fn filetype(&self) -> FileType {
93✔
600
        self.blockreader.filetype()
93✔
601
    }
93✔
602

603
    /// See [`BlockReader::path`].
604
    ///
605
    /// [`BlockReader::path`]: crate::readers::blockreader::BlockReader#method.path
606
    #[inline(always)]
607
    pub const fn path(&self) -> &FPath {
163✔
608
        self.blockreader.path()
163✔
609
    }
163✔
610

611
    /// See [`BlockReader::mtime`].
612
    ///
613
    /// [`BlockReader::mtime`]: crate::readers::blockreader::BlockReader#method.mtime
614
    pub fn mtime(&self) -> SystemTime {
70✔
615
        self.blockreader.mtime()
70✔
616
    }
70✔
617

618
    /// `Count` of `FixedStruct`s processed by this `FixedStructReader`
619
    /// (i.e. `self.entries_processed`).
620
    #[inline(always)]
621
    pub fn count_entries_processed(&self) -> Count {
1✔
622
        self.entries_processed
1✔
623
    }
1✔
624

625
    /// "_High watermark_" of `FixedStruct` stored in `self.cache_entries`.
626
    #[inline(always)]
627
    pub fn entries_stored_highest(&self) -> usize {
×
628
        self.entries_stored_highest
×
629
    }
×
630

631
    /// See [`BlockReader::block_offset_at_file_offset`].
632
    ///
633
    /// [`BlockReader::block_offset_at_file_offset`]: crate::readers::blockreader::BlockReader#method.block_offset_at_file_offset
634
    #[inline(always)]
635
    pub const fn block_offset_at_file_offset(
1✔
636
        &self,
1✔
637
        fileoffset: FileOffset,
1✔
638
    ) -> BlockOffset {
1✔
639
        BlockReader::block_offset_at_file_offset(fileoffset, self.blocksz())
1✔
640
    }
1✔
641

642
    /// See [`BlockReader::file_offset_at_block_offset`].
643
    ///
644
    /// [`BlockReader::file_offset_at_block_offset`]: crate::readers::blockreader::BlockReader#method.file_offset_at_block_offset
645
    #[inline(always)]
646
    pub const fn file_offset_at_block_offset(
1✔
647
        &self,
1✔
648
        blockoffset: BlockOffset,
1✔
649
    ) -> FileOffset {
1✔
650
        BlockReader::file_offset_at_block_offset(blockoffset, self.blocksz())
1✔
651
    }
1✔
652

653
    /// See [`BlockReader::file_offset_at_block_offset_index`].
654
    ///
655
    /// [`BlockReader::file_offset_at_block_offset_index`]: crate::readers::blockreader::BlockReader#method.file_offset_at_block_offset_index
656
    #[inline(always)]
657
    pub const fn file_offset_at_block_offset_index(
1✔
658
        &self,
1✔
659
        blockoffset: BlockOffset,
1✔
660
        blockindex: BlockIndex,
1✔
661
    ) -> FileOffset {
1✔
662
        BlockReader::file_offset_at_block_offset_index(blockoffset, self.blocksz(), blockindex)
1✔
663
    }
1✔
664

665
    /// See [`BlockReader::block_index_at_file_offset`].
666
    ///
667
    /// [`BlockReader::block_index_at_file_offset`]: crate::readers::blockreader::BlockReader#method.block_index_at_file_offset
668
    #[inline(always)]
669
    pub const fn block_index_at_file_offset(
1✔
670
        &self,
1✔
671
        fileoffset: FileOffset,
1✔
672
    ) -> BlockIndex {
1✔
673
        BlockReader::block_index_at_file_offset(fileoffset, self.blocksz())
1✔
674
    }
1✔
675

676
    /// See [`BlockReader::count_blocks`].
677
    ///
678
    /// [`BlockReader::count_blocks`]: crate::readers::blockreader::BlockReader#method.count_blocks
679
    #[inline(always)]
680
    pub const fn count_blocks(&self) -> Count {
1✔
681
        BlockReader::count_blocks(self.filesz(), self.blocksz()) as Count
1✔
682
    }
1✔
683

684
    /// See [`BlockReader::blockoffset_last`].
685
    ///
686
    /// [`BlockReader::blockoffset_last`]: crate::readers::blockreader::BlockReader#method.blockoffset_last
687
    pub const fn blockoffset_last(&self) -> BlockOffset {
1✔
688
        self.blockreader
1✔
689
            .blockoffset_last()
1✔
690
    }
1✔
691

692
    /// See [`BlockReader::fileoffset_last`].
693
    ///
694
    /// [`BlockReader::fileoffset_last`]: crate::readers::blockreader::BlockReader#method.fileoffset_last
695
    pub const fn fileoffset_last(&self) -> FileOffset {
910✔
696
        self.blockreader
910✔
697
            .fileoffset_last()
910✔
698
    }
910✔
699

700
    /// Is the passed `FileOffset` the last byte of the file?
701
    pub const fn is_fileoffset_last(
908✔
702
        &self,
908✔
703
        fileoffset: FileOffset,
908✔
704
    ) -> bool {
908✔
705
        self.fileoffset_last() == fileoffset
908✔
706
    }
908✔
707

708
    /// Is the passed `FixedStruct` the last of the file?
709
    #[inline(always)]
710
    pub fn is_last(
902✔
711
        &self,
902✔
712
        fixedstruct: &FixedStruct,
902✔
713
    ) -> bool {
902✔
714
        self.is_fileoffset_last(fixedstruct.fileoffset_end() - 1)
902✔
715
    }
902✔
716

717
    /// Return the `FileOffset` that is adjusted to the beginning offset of
718
    /// a `fixedstruct` entry.
719
    #[inline(always)]
720
    pub const fn fileoffset_to_fixedstructoffset(
1✔
721
        &self,
1✔
722
        fileoffset: FileOffset,
1✔
723
    ) -> FileOffset {
1✔
724
        (fileoffset / self.fixedstruct_size_fo()) * self.fixedstruct_size_fo()
1✔
725
    }
1✔
726

727
    /// Return the first file offset from `self.map_tvpair_fo` for the first
728
    /// entry as sorted by `tv_pair_type` (datetime); i.e. the earliest entry.
729
    /// Ties are broken by `FileOffset`.
730
    pub fn fileoffset_first(&self) -> Option<FileOffset> {
102✔
731
        match self
102✔
732
            .map_tvpair_fo
102✔
733
            .iter()
102✔
734
            .min_by_key(|(tv_pair, fo)| (*tv_pair, *fo))
971✔
735
        {
736
            Some((_tv_pair, fo_)) => Some(*fo_),
102✔
737
            None => None,
×
738
        }
739
    }
102✔
740

741
    /// The size in bytes of the `FixedStruct` entries managed by this
742
    /// `FixedStructReader`.
743
    #[inline(always)]
744
    pub const fn fixedstruct_size(&self) -> usize {
1,245✔
745
        self.fixedstruct_size
1,245✔
746
    }
1,245✔
747

748
    /// [`fixedstruct_size`] as a `FileOffset`.
749
    ///
750
    /// [`fixedstruct_size`]: self::FixedStructReader#method.fixedstruct_size
751
    #[inline(always)]
752
    pub const fn fixedstruct_size_fo(&self) -> FileOffset {
1,150✔
753
        self.fixedstruct_size() as FileOffset
1,150✔
754
    }
1,150✔
755

756
    /// The `FixedStructType` of the file.
757
    #[inline(always)]
758
    pub const fn fixedstruct_type(&self) -> FixedStructType {
673✔
759
        self.fixedstruct_type
673✔
760
    }
673✔
761

762
    /// Return all currently stored `FileOffset` in `self.cache_entries`.
763
    ///
764
    /// Only for testing.
765
    #[cfg(test)]
766
    pub fn get_fileoffsets(&self) -> Vec<FileOffset> {
1✔
767
        self.cache_entries
1✔
768
            .keys()
1✔
769
            .cloned()
1✔
770
            .collect()
1✔
771
    }
1✔
772

773
    /// store an `Error` that occurred. For later printing during `--summary`.
774
    // XXX: duplicates `SyslogProcessor.set_error`
775
    fn set_error(
×
776
        &mut self,
×
777
        error: &Error,
×
778
    ) {
×
779
        def1ñ!("{:?}", error);
×
780
        let mut error_string: String = error.kind().to_string();
×
781
        error_string.push_str(": ");
×
782
        error_string.push_str(error.kind().to_string().as_str());
×
783
        // print the error but avoid printing the same error more than once
784
        // XXX: This is somewhat a hack as it's possible the same error, with the
785
        //      the same error message, could occur more than once.
786
        //      Considered another way, this function `set_error` may get called
787
        //      too often. The responsibility for calling `set_error` is haphazard.
788
        match &self.error {
×
789
            Some(err_s) => {
×
790
                if err_s != &error_string {
×
791
                    e_err!("{}", error);
×
792
                }
×
793
            }
794
            None => {
×
795
                e_err!("{}", error);
×
796
            }
×
797
        }
798
        if let Some(ref _err) = self.error {
×
799
            de_wrn!("skip overwrite of previous Error ({:?}) with Error ({:?})", _err, error);
×
800
            return;
×
801
        }
×
802
        self.error = Some(error_string);
×
803
    }
×
804

805
    /// Store information about a single [`FixedStruct`] entry.
806
    ///
807
    /// Should only be called by `FixedStructReader::new`
808
    ///
809
    /// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
810
    fn insert_cache_entry(
508✔
811
        &mut self,
508✔
812
        entry: FixedStruct,
508✔
813
    ) {
508✔
814
        defn!("@{}", entry.fileoffset_begin());
508✔
815
        let fo_beg: FileOffset = entry.fileoffset_begin();
508✔
816
        debug_assert!(
508✔
817
            !self.cache_entries.contains_key(&fo_beg),
508✔
818
            "self.cache_entries already contains key {}",
819
            fo_beg
820
        );
821

822
        // update some stats and (most importantly) `self.cache_entries`
823
        self.cache_entries
508✔
824
            .insert(fo_beg, entry);
508✔
825
        self.entries_stored_highest = std::cmp::max(self.entries_stored_highest, self.cache_entries.len());
508✔
826
        self.entries_processed += 1;
508✔
827
        defo!("entries_processed = {}", self.entries_processed);
508✔
828

829
        defx!();
508✔
830
    }
508✔
831

832
    /// Update the statistic `DateTimeL` of
833
    /// `self.dt_first` and `self.dt_last`
834
    fn dt_first_last_update(
943✔
835
        &mut self,
943✔
836
        datetime: &DateTimeL,
943✔
837
    ) {
943✔
838
        if !summary_stats_enabled() {
943✔
839
            return;
×
840
        }
943✔
841
        defñ!("({:?})", datetime);
943✔
842
        match self.dt_first {
943✔
843
            Some(dt_first_) => {
789✔
844
                if &dt_first_ > datetime {
789✔
845
                    self.dt_first = Some(*datetime);
×
846
                }
789✔
847
            }
848
            None => {
154✔
849
                self.dt_first = Some(*datetime);
154✔
850
            }
154✔
851
        }
852
        match self.dt_last {
943✔
853
            Some(dt_last_) => {
789✔
854
                if &dt_last_ < datetime {
789✔
855
                    self.dt_last = Some(*datetime);
788✔
856
                }
788✔
857
            }
858
            None => {
154✔
859
                self.dt_last = Some(*datetime);
154✔
860
            }
154✔
861
        }
862
    }
943✔
863

864
    /// Proactively `drop` the [`Block`s] associated with the
865
    /// passed [`FixedStruct`]. Return count of dropped entries (0 or 1).
866
    ///
867
    /// _The caller must know what they are doing!_
868
    ///
869
    /// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
870
    /// [`Block`s]: crate::readers::blockreader::Block
871
    /// [`FileOffset`]: crate::common::FileOffset
872
    fn drop_entry(
1,033✔
873
        &mut self,
1,033✔
874
        fixedstruct: &FixedStruct,
1,033✔
875
    ) -> usize {
1,033✔
876
        let bsz: BlockSz = self.blocksz();
1,033✔
877
        defn!(
1,033✔
878
            "(fixedstruct@{}); offsets [{}‥{}), blocks [{}‥{}]",
879
            fixedstruct.fileoffset_begin(),
1,033✔
880
            fixedstruct.fileoffset_begin(),
1,033✔
881
            fixedstruct.fileoffset_end(),
1,033✔
882
            fixedstruct.blockoffset_begin(bsz),
1,033✔
883
            fixedstruct.blockoffset_end(bsz),
1,033✔
884
        );
885
        let mut dropped_ok: usize = 0;
1,033✔
886
        let mut dropped_err: usize = 0;
1,033✔
887
        let mut bo_at: BlockOffset = fixedstruct.blockoffset_begin(bsz);
1,033✔
888
        let bo_end: BlockOffset = fixedstruct.blockoffset_end(bsz);
1,033✔
889
        debug_assert_le!(bo_at, bo_end);
1,033✔
890
        while bo_at <= bo_end {
4,819✔
891
            defo!("block_use_count.get_mut({})", bo_at);
3,786✔
892
            match self.block_use_count.get_mut(&bo_at) {
3,786✔
893
                Some(count) => {
3,782✔
894
                    if *count <= 1 {
3,782✔
895
                        defo!(
2,876✔
896
                            "block_use_count[{}] found; count=={}; total span [{}‥{})",
897
                            bo_at, count,
898
                            BlockReader::file_offset_at_block_offset(bo_at, bsz),
2,876✔
899
                            BlockReader::file_offset_at_block_offset(bo_end + 1, bsz),
2,876✔
900
                        );
901
                        if self
2,876✔
902
                            .blockreader
2,876✔
903
                            .drop_block(bo_at)
2,876✔
904
                        {
905
                            defo!(
2,873✔
906
                                "dropped block {}; total span [{}‥{})",
907
                                bo_at,
908
                                BlockReader::file_offset_at_block_offset(bo_at, bsz),
2,873✔
909
                                BlockReader::file_offset_at_block_offset(bo_end + 1, bsz),
2,873✔
910
                            );
911
                            self.block_use_count.remove(&bo_at);
2,873✔
912
                            #[cfg(test)]
913
                            self.dropped_blocks.push_back(bo_at);
2,803✔
914
                            dropped_ok += 1;
2,873✔
915
                        } else {
916
                            defo!("failed to drop block {}", bo_at);
3✔
917
                            dropped_err += 1;
3✔
918
                        }
919
                    } else {
920
                        *count -= 1;
906✔
921
                        defo!("block_use_count[{}] found; count-=1=={}", bo_at, *count);
906✔
922
                    }
923
                }
924
                None => {
925
                    defo!("block_use_count[{}] not found", bo_at);
4✔
926
                }
927
            }
928
            bo_at += 1;
3,786✔
929
        }
930
        summary_stat!(
1,033✔
931
            if dropped_ok > 0 {
943✔
932
                self.drop_entry_ok += 1;
164✔
933
            }
848✔
934
        );
935
        summary_stat!(
1,033✔
936
            if dropped_err > 0 {
943✔
937
                self.drop_entry_errors += 1;
2✔
938
            }
941✔
939
        );
940
        defx!("return {}", dropped_ok);
1,033✔
941

942
        dropped_ok
1,033✔
943
    }
1,033✔
944

945
    /// Check the internal storage `self.cache_entries`.
946
    /// Remove the entry and return it if found.
947
    #[inline(always)]
948
    fn remove_cache_entry(
1,033✔
949
        &mut self,
1,033✔
950
        fileoffset: FileOffset,
1,033✔
951
    ) -> Option<FixedStruct> {
1,033✔
952
        match self.cache_entries.remove(&fileoffset) {
1,033✔
953
            Some(fixedstruct) => {
454✔
954
                defñ!("({}): found in store", fileoffset);
454✔
955
                self.entries_hits += 1;
454✔
956

957
                Some(fixedstruct)
454✔
958
            }
959
            None => {
960
                defñ!("({}): not found in store", fileoffset);
579✔
961
                self.entries_miss += 1;
579✔
962

963
                None
579✔
964
            }
965
        }
966
    }
1,033✔
967

968
    /// Process entries for the file managed by the `BlockReader`.
969
    /// Find the entry with the highest "score" as judged by `score_fixedstruct`.
970
    ///
971
    /// Returns the highest scored `FixedStructType`, that highest score,
972
    /// and any processed [`FixedStruct`] entries (referenced by a
973
    /// [`FixedStructDynPtr`]) in a list.
974
    ///
975
    /// Each list entry is a tuple of the
976
    /// the entries `FileOffset` and the `FixedStructDynPtr`.
977
    /// The entries will presumably be stored in the
978
    /// `FixedStructReader`'s `cache_entries`.
979
    pub fn score_file(
198✔
980
        blockreader: &mut BlockReader,
198✔
981
        oneblock: bool,
198✔
982
        types_to_bonus: FixedStructTypeSet,
198✔
983
    ) -> ResultFixedStructReaderScoreFileError {
198✔
984
        def1n!("(oneblock={}, types_to_bonus len {})", oneblock, types_to_bonus.len());
198✔
985
        #[cfg(debug_assertions)]
986
        {
987
            for (fixedstructtype, bonus) in types_to_bonus.iter() {
771✔
988
                def1o!("types_to_bonus: ({:<30?}, {:2}) size {}", fixedstructtype, bonus, fixedstructtype.size(),);
771✔
989
            }
990
        }
991
        // allocate largest possible buffer needed on the stack
992
        let mut buffer: [u8; ENTRY_SZ_MAX] = [0; ENTRY_SZ_MAX];
198✔
993
        // only score this number of entries, i.e. don't walk the
994
        // entire file scoring all entries
995
        #[cfg(not(test))]
996
        const COUNT_FOUND_ENTRIES_MAX: usize = 5;
997
        #[cfg(test)]
998
        const COUNT_FOUND_ENTRIES_MAX: usize = 2;
999
        let mut _count_total: usize = 0;
198✔
1000
        let mut highest_score: Score = 0;
198✔
1001
        let mut highest_score_type: Option<FixedStructType> = None;
198✔
1002
        let mut highest_score_entries = ListFileOffsetFixedStructPtr::new();
198✔
1003

1004
        for (fixedstructtype, bonus) in types_to_bonus.into_iter() {
771✔
1005
            let mut _count_loop: usize = 0;
771✔
1006
            let mut count_found_entries: usize = 0;
771✔
1007
            let mut high_score: Score = 0;
771✔
1008
            let mut fo: FileOffset = 0;
771✔
1009
            let mut found_entries = ListFileOffsetFixedStructPtr::new();
771✔
1010

1011
            loop {
1012
                if count_found_entries >= COUNT_FOUND_ENTRIES_MAX {
4,192✔
1013
                    def1o!("count_found_entries {} >= COUNT_FOUND_ENTRIES_MAX {}", count_found_entries, COUNT_FOUND_ENTRIES_MAX);
724✔
1014
                    break;
724✔
1015
                }
3,468✔
1016
                _count_total += 1;
3,468✔
1017
                _count_loop += 1;
3,468✔
1018
                let utmp_sz: usize = fixedstructtype.size();
3,468✔
1019
                let fo_end = fo + utmp_sz as FileOffset;
3,468✔
1020
                def1o!(
3,468✔
1021
                    "loop try {} (total {}), fixedstructtype {:?}, zero the buffer (size {}), looking at fileoffset {}‥{} (0x{:08X}‥0x{:08X})",
1022
                    _count_loop, _count_total, fixedstructtype, buffer.len(), fo, fo_end, fo, fo_end
3,468✔
1023
                );
1024
                // zero out the buffer
1025
                // XXX: not strictly necessary to zero buffer but it helps humans
1026
                //      manually reviewing debug logs
1027
                // this compiles down to a single `memset` call
1028
                // See https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,selection:(endColumn:1,endLineNumber:5,positionColumn:1,positionLineNumber:5,selectionStartColumn:1,selectionStartLineNumber:5,startColumn:1,startLineNumber:5),source:'pub+fn+foo()+%7B%0A++++const+ENTRY_SZ_MAX:+usize+%3D+400%3B%0A++++let+mut+buffer:+%5Bu8%3B+ENTRY_SZ_MAX%5D+%3D+%5B0%3B+ENTRY_SZ_MAX%5D%3B%0A++++buffer.iter_mut().for_each(%7Cm%7C+*m+%3D+0)%3B%0A%0A++++std::hint::black_box(buffer)%3B%0A%7D'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:41.18316477421653,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:r1750,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'1',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,libs:!(),options:'-O',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+rustc+1.75.0+(Editor+%231)',t:'0')),k:42.788718063415104,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+rustc+1.75.0+(Compiler+%231)',t:'0')),k:16.028117162368364,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
1029
                // See https://godbolt.org/z/KcxW9hWYb
1030
                buffer.iter_mut().for_each(|m| *m = 0);
3,468✔
1031
                // read data into buffer
1032
                let buffer_read: usize = match blockreader.read_data_to_buffer(fo, fo_end, oneblock, &mut buffer) {
3,468✔
1033
                    ResultReadDataToBuffer::Found(buffer_read) => buffer_read,
3,421✔
1034
                    ResultReadDataToBuffer::Err(err) => {
×
1035
                        def1x!("return Err");
×
1036
                        return ResultFixedStructReaderScoreFileError::FileErrIo(err);
×
1037
                    }
1038
                    ResultReadDataToBuffer::Done => {
47✔
1039
                        // reached end of block (if `oneblock` is `true`) or end of file
1040
                        break;
47✔
1041
                    }
1042
                };
1043
                if buffer_read < utmp_sz {
3,421✔
1044
                    def1o!(
×
1045
                        "read_data_to_buffer read bytes {} < {} requested fixedstruct size bytes; break",
1046
                        buffer_read,
1047
                        utmp_sz,
1048
                    );
1049
                    break;
×
1050
                }
3,421✔
1051
                // advance the file offset for the next loop
1052
                let fo2 = fo;
3,421✔
1053
                fo += utmp_sz as FileOffset;
3,421✔
1054
                // grab the slice of interest
1055
                let slice_ = &buffer[..buffer_read];
3,421✔
1056
                // convert buffer to fixedstruct
1057
                let fixedstructptr: FixedStructDynPtr = match buffer_to_fixedstructptr(slice_, fixedstructtype) {
3,421✔
1058
                    Some(val) => val,
2,311✔
1059
                    None => {
1060
                        def1o!(
1,110✔
1061
                            "buffer_to_fixedstructptr(buf len {}, {:?}) returned None; continue",
1062
                            buffer.len(),
1,110✔
1063
                            fixedstructtype,
1064
                        );
1065
                        continue;
1,110✔
1066
                    }
1067
                };
1068
                count_found_entries += 1;
2,311✔
1069
                // score the newly create fixedstruct
1070
                let score: Score = FixedStruct::score_fixedstruct(&fixedstructptr, bonus);
2,311✔
1071
                def1o!("score {} for entry type {:?} @[{}‥{}]", score, fixedstructptr.fixedstruct_type(), fo2, fo_end);
2,311✔
1072
                // update the high score
1073
                let _fs_type: FixedStructType = fixedstructptr.fixedstruct_type();
2,311✔
1074
                found_entries.push_back((fo2, fixedstructptr));
2,311✔
1075
                if score <= high_score {
2,311✔
1076
                    def1o!("score {} ({:?}) not higher than high score {}", score, _fs_type, high_score,);
2,095✔
1077
                    // score is not higher than high score so continue
1078
                    continue;
2,095✔
1079
                }
216✔
1080
                // there is a new high score for this type
1081
                def1o!("new high score {} for entry type {:?} @[{}‥{}]", score, _fs_type, fo2, fo_end);
216✔
1082
                high_score = score;
216✔
1083
            }
1084
            // finished with that fixedstructtype
1085
            // so check if it's high score beat any previous high score of a different fixedstructtype
1086
            if high_score > highest_score {
771✔
1087
                // a new high score was found for a different type so throw away
1088
                // linked lists of entries for the previous type
1089
                match highest_score_type {
196✔
1090
                    None => {
1091
                        def1o!(
190✔
1092
                            "new highest score {} entry type {:?} with {} entries",
1093
                            high_score, fixedstructtype, found_entries.len(),
190✔
1094
                        );
1095
                    }
1096
                    Some(_highest_score_type) => {
6✔
1097
                        def1o!(
6✔
1098
                            "new highest score {} entry type {:?} with {} entries; replaces old high score {} entry type {:?} with {} entries (entries dropped)",
1099
                            high_score, fixedstructtype, found_entries.len(),
6✔
1100
                            highest_score, _highest_score_type, highest_score_entries.len(),
6✔
1101
                        );
1102
                    }
1103
                }
1104
                highest_score = high_score;
196✔
1105
                highest_score_type = Some(fixedstructtype);
196✔
1106
                highest_score_entries = found_entries;
196✔
1107
            } else {
1108
                def1o!(
575✔
1109
                    "no new highest score: score {} entry type {:?} with {} entries. old high score remains: score {} entry type {:?} with {} entries",
1110
                    high_score, fixedstructtype, found_entries.len(),
575✔
1111
                    highest_score, highest_score_type, highest_score_entries.len(),
575✔
1112
                );
1113
            }
1114
        }
1115

1116
        match highest_score_type {
198✔
1117
            None => {
1118
                def1x!("return Err {:?}", ResultFixedStructReaderScoreFileError::FileErrNoHighScore);
8✔
1119
                return ResultFixedStructReaderScoreFileError::FileErrNoHighScore;
8✔
1120
            }
1121
            Some(highest_score_type) => {
190✔
1122
                def1x!("return Ok(({:?}, {}, found_entries))", highest_score_type, highest_score);
190✔
1123

1124
                ResultFixedStructReaderScoreFileError::FileOk(highest_score_type, highest_score, highest_score_entries)
190✔
1125
            }
1126
        }
1127
    }
198✔
1128

1129
    /// Determine the `FixedStructType` based on the file size and data.
1130
    ///
1131
    /// 1. Makes best guess about file structure based on size by calling
1132
    ///    `filesz_to_types`
1133
    /// 2. Searches for a valid struct within the first block of the file (if
1134
    ///    `oneblock` is `true`, else searches all available blocks).
1135
    /// 3. Creates a [`FixedStruct`] from the found struct.
1136
    ///
1137
    /// Call this before calling `process_entry_at`.
1138
    ///
1139
    /// [OpenBSD file `w.c`] processes `/var/log/utmp`. Reviewing the code you
1140
    /// get some idea of how the file is determined to be valid.
1141
    ///
1142
    /// [OpenBSD file `w.c`]: https://github.com/openbsd/src/blob/20248fc4cbb7c0efca41a8aafd40db7747023515/usr.bin/w/w.c
1143
    pub(crate) fn preprocess_fixedstructtype(
198✔
1144
        blockreader: &mut BlockReader,
198✔
1145
        filetype_fixedstruct: &FileTypeFixedStruct,
198✔
1146
        oneblock: bool,
198✔
1147
    ) -> ResultFixedStructReaderScoreFileError {
198✔
1148
        def1n!("({:?}, oneblock={})", filetype_fixedstruct, oneblock);
198✔
1149

1150
        // short-circuit special case of empty file
1151
        if blockreader.filesz() == 0 {
198✔
1152
            def1x!("empty file; return FileErrEmpty");
×
1153
            return ResultFixedStructReaderScoreFileError::FileErrEmpty;
×
1154
        }
198✔
1155

1156
        let types_to_bonus: FixedStructTypeSet = match filesz_to_types(
198✔
1157
            blockreader.filesz(),
198✔
1158
            filetype_fixedstruct,
198✔
1159
        ) {
198✔
1160
            Some(set) => set,
198✔
1161
            None => {
1162
                de_wrn!("FixedStructReader::filesz_to_types({}) failed; file {:?}",
×
1163
                        blockreader.filesz(), blockreader.path());
×
1164
                def1x!("filesz_to_types returned None; return FileErrNoValidFixedStruct");
×
1165
                return ResultFixedStructReaderScoreFileError::FileErrNoValidFixedStruct;
×
1166
            }
1167
        };
1168
        def1o!("filesz_to_types returned {} types: {:?}", types_to_bonus.len(), types_to_bonus);
198✔
1169

1170
        let ret = FixedStructReader::score_file(blockreader, oneblock, types_to_bonus);
198✔
1171
        def1x!("score_file returned {:?}", ret);
198✔
1172

1173
        ret
198✔
1174
    }
198✔
1175

1176
    /// Jump to each entry offset, convert the raw bytes to a `tv_pair_type`.
1177
    /// If the value is within the passed filters than save the value and the
1178
    /// file offset of the entry.
1179
    /// Return a count of out of order entries, and map of filtered tv_pair to
1180
    /// fileoffsets. The fileoffsets in the map are the fixedstruct offsets
1181
    /// (not timevalue offsets).
1182
    pub(crate) fn preprocess_timevalues(
190✔
1183
        blockreader: &mut BlockReader,
190✔
1184
        fixedstruct_type: FixedStructType,
190✔
1185
        dt_filter_after: &DateTimeLOpt,
190✔
1186
        dt_filter_before: &DateTimeLOpt,
190✔
1187
    ) -> ResultTvFo {
190✔
1188
        defn!();
190✔
1189
        // allocate largest possible buffer needed on the stack
1190
        let mut buffer: [u8; TIMEVAL_SZ_MAX] = [0; TIMEVAL_SZ_MAX];
190✔
1191
        // map of time values to file offsets
1192
        let mut map_tv_pair_fo: MapTvPairToFo = MapTvPairToFo::new();
190✔
1193
        // count of out of order entries
1194
        let mut out_of_order: usize = 0;
190✔
1195
        // valid fixedstruct but does not pass the time value filters
1196
        let mut valid_no_pass_filter: usize = 0;
190✔
1197
        // null fixedstruct or non-sense time values
1198
        let mut invalid: usize = 0;
190✔
1199
        // total number of entries processed
1200
        let mut total_entries: usize = 0;
190✔
1201

1202
        let tv_filter_after: Option<tv_pair_type> = match dt_filter_after {
190✔
1203
            Some(dt) => Some(convert_datetime_tvpair(dt)),
60✔
1204
            None => None,
130✔
1205
        };
1206
        defo!("tv_filter_after: {:?}", tv_filter_after);
190✔
1207
        let tv_filter_before: Option<tv_pair_type> = match dt_filter_before {
190✔
1208
            Some(dt) => Some(convert_datetime_tvpair(dt)),
34✔
1209
            None => None,
156✔
1210
        };
1211
        defo!("tv_filter_before: {:?}", tv_filter_before);
190✔
1212

1213
        // 1. get offsets
1214
        let entry_sz: FileOffset = fixedstruct_type.size() as FileOffset;
190✔
1215
        debug_assert_eq!(blockreader.filesz() % entry_sz, 0, "file not a multiple of entry size {}", entry_sz);
190✔
1216
        let tv_sz: usize = fixedstruct_type.size_tv();
190✔
1217
        let tv_offset: usize = fixedstruct_type.offset_tv();
190✔
1218
        let slice_: &mut [u8] = &mut buffer[..tv_sz];
190✔
1219
        let mut fo: FileOffset = 0;
190✔
1220
        let mut tv_pair_prev: Option<tv_pair_type> = None;
190✔
1221
        loop {
1222
            // 2. jump to each offset, grab datetime bytes,
1223
            let beg: FileOffset = fo + tv_offset as FileOffset;
1,367✔
1224
            let end: FileOffset = beg + tv_sz as FileOffset;
1,367✔
1225
            match blockreader.read_data_to_buffer(beg, end, false, slice_) {
1,367✔
1226
                ResultReadDataToBuffer::Found(_readn) => {
1,177✔
1227
                    defo!("read {} bytes at fileoffset {}", _readn, beg);
1,177✔
1228
                    debug_assert_eq!(
1,177✔
1229
                        _readn, tv_sz,
1230
                        "read {} bytes, expected {} bytes (size of a time value)",
1231
                        _readn, tv_sz,
1232
                    );
1233
                }
1234
                ResultReadDataToBuffer::Err(err) => {
×
1235
                    defx!("return Err");
×
1236
                    return ResultTvFo::Err(err);
×
1237
                }
1238
                ResultReadDataToBuffer::Done => {
190✔
1239
                    defo!("return Done");
190✔
1240
                    break;
190✔
1241
                }
1242
            }
1243
            // 3. convert bytes to tv_sec, tv_usec
1244
            let tv_pair: tv_pair_type = match fixedstruct_type.tv_pair_from_buffer(slice_) {
1,177✔
1245
                Some(pair) => pair,
1,177✔
1246
                None => {
1247
                    de_err!("invalid entry at fileoffset {}", fo);
×
1248
                    defo!("invalid entry at fileoffset {}", fo);
×
1249
                    fo += entry_sz;
×
1250
                    invalid += 1;
×
1251
                    continue;
×
1252
                }
1253
            };
1254
            defo!("tv_pair: {:?}", tv_pair);
1,177✔
1255
            if tv_pair == tv_pair_type(0, 0) {
1,177✔
1256
                defo!("tv_pair is (0, 0); continue");
×
1257
                fo += entry_sz;
×
1258
                continue;
×
1259
            }
1,177✔
1260
            if let Some(tv_pair_prev) = tv_pair_prev {
1,177✔
1261
                if tv_pair < tv_pair_prev {
987✔
1262
                    out_of_order += 1;
70✔
1263
                    defo!(
70✔
1264
                        "out_of_order = {}; tv_pair = {:?}, tv_pair_prev = {:?}",
1265
                        out_of_order,
1266
                        tv_pair,
1267
                        tv_pair_prev,
1268
                    );
1269
                }
917✔
1270
            }
190✔
1271
            tv_pair_prev = Some(tv_pair);
1,177✔
1272
            total_entries += 1;
1,177✔
1273
            // 4. compare to time value filters
1274
            if let Some(tv_filter) = tv_filter_after {
1,177✔
1275
                if tv_pair < tv_filter {
150✔
1276
                    defo!("tv_pair {:?} < {:?} tv_filter_after; continue", tv_pair, tv_filter);
61✔
1277
                    fo += entry_sz;
61✔
1278
                    valid_no_pass_filter += 1;
61✔
1279
                    continue;
61✔
1280
                }
89✔
1281
            }
1,027✔
1282
            if let Some(tv_filter) = tv_filter_before {
1,116✔
1283
                if tv_pair > tv_filter {
49✔
1284
                    defo!("tv_pair {:?} > {:?} tv_filter_before; continue", tv_pair, tv_filter);
22✔
1285
                    fo += entry_sz;
22✔
1286
                    valid_no_pass_filter += 1;
22✔
1287
                    // continue to check _all_ entries as the entries may not be
1288
                    // in chronological order
1289
                    continue;
22✔
1290
                }
27✔
1291
            }
1,067✔
1292
            // 5. save entries that pass the time value filters
1293
            defo!("tv_pair {:?} @{} passes time value filters", tv_pair, fo);
1,094✔
1294
            map_tv_pair_fo.insert(tv_pair, fo);
1,094✔
1295

1296
            fo += entry_sz;
1,094✔
1297
        }
1298
        // 6. return list of valid entries
1299
        defx!("map_tv_pair_fo len {}", map_tv_pair_fo.len());
190✔
1300

1301
        ResultTvFo::Ok((total_entries, invalid, valid_no_pass_filter, out_of_order, map_tv_pair_fo))
190✔
1302
    }
190✔
1303

1304
    /// Process the data at FileOffset `fo`. Transform it into a `FixedStruct`
1305
    /// using [`FixedStruct::new`].
1306
    /// But before that, check private `self.cache_entries`
1307
    /// in case the data at the fileoffset was already processed (transformed)
1308
    /// during `FixedStructReader::new`.
1309
    ///
1310
    /// Let the caller pass a `buffer` to avoid this function having allocate.
1311
    ///
1312
    /// This function does the bulk of file processing after the
1313
    /// `FixedStructReader` has been initialized during
1314
    /// [`FixedStructReader::new`].
1315
    pub fn process_entry_at(
1,147✔
1316
        &mut self,
1,147✔
1317
        fo: FileOffset,
1,147✔
1318
        buffer: &mut [u8],
1,147✔
1319
    ) -> ResultFindFixedStruct {
1,147✔
1320
        defn!("({})", fo);
1,147✔
1321

1322
        let sz: FileOffset = self.fixedstruct_size_fo();
1,147✔
1323
        debug_assert_eq!(fo % sz, 0, "fileoffset {} not multiple of {}", fo, sz,);
1,147✔
1324
        let fileoffset: FileOffset = fo - (fo % sz);
1,147✔
1325

1326
        if fileoffset >= self.filesz() {
1,147✔
1327
            defx!("return ResultFindFixedStruct::Done; fileoffset {} >= filesz {}", fileoffset, self.filesz());
114✔
1328
            return ResultFindFixedStruct::Done;
114✔
1329
        }
1,033✔
1330

1331
        // The `map_tvpair_fo` is the oracle listing of entries ordered by
1332
        // `tv_pair` (it was  fully created during `preprocess_timevalues`).
1333
        // Search `map_tvpair_fo` for the passed `fo`, then return the
1334
        // fileoffset of the entry *after that* which will be returned in `Found`.
1335
        // If no next fileoffset is found it means `map_tvpair_fo` is empty.
1336
        // In that case, the `fo_next` will be the value of `filesz()` and the
1337
        // next call to `process_entry_at` will return `Done`.
1338
        let fo_next: FileOffset = {
1,033✔
1339
            let mut fo_next_: FileOffset = self.filesz();
1,033✔
1340
            let mut next_pair: bool = false;
1,033✔
1341
            let mut tv_pair_at_opt: Option<tv_pair_type> = None;
1,033✔
1342
            // TODO: is there a rustic iterator way to
1343
            //       "find something and return the next thing"?
1344
            for (tv_pair_at, fo_at) in self.map_tvpair_fo.iter() {
1,944✔
1345
                if next_pair {
1,944✔
1346
                    defo!("set fo_next = {}", fo_at);
887✔
1347
                    fo_next_ = *fo_at;
887✔
1348
                    break;
887✔
1349
                }
1,057✔
1350
                if &fileoffset == fo_at {
1,057✔
1351
                    defo!("found fileoffset {} with key {:?} in map_tvpair_fo", fileoffset, tv_pair_at,);
1,025✔
1352
                    tv_pair_at_opt = Some(*tv_pair_at);
1,025✔
1353
                    next_pair = true;
1,025✔
1354
                }
32✔
1355
            }
1356
            // remove the `tv_pair` from `map_tvpair_fo`
1357
            match tv_pair_at_opt {
1,033✔
1358
                Some(tv_pair_at) => {
1,025✔
1359
                    self.map_tvpair_fo
1,025✔
1360
                        .remove(&tv_pair_at);
1,025✔
1361
                    defo!("remove tv_pair {:?}; map_tvpair_fo size {}", tv_pair_at, self.map_tvpair_fo.len());
1,025✔
1362
                }
1363
                None => {
1364
                    defo!("no map_tvpair_fo found!");
8✔
1365
                }
1366
            }
1367

1368
            fo_next_
1,033✔
1369
        };
1370
        defo!("fo_next = {}", fo_next);
1,033✔
1371

1372
        // check if the entry is already stored
1373
        if let Some(fixedstruct) = self.remove_cache_entry(fileoffset) {
1,033✔
1374
            summary_stat!(self.dt_first_last_update(fixedstruct.dt()));
454✔
1375
            // try to drop blocks associated with the entry
1376
            self.drop_entry(&fixedstruct);
454✔
1377
            defx!("remove_cache_entry found fixedstruct at fileoffset {}; return Found({}, …)", fileoffset, fo_next,);
454✔
1378
            return ResultFindFixedStruct::Found((fo_next, fixedstruct));
454✔
1379
        }
579✔
1380

1381
        // the entry was not in the cache so read the raw bytes from the file
1382
        // and transform them into a `FixedStruct`
1383

1384
        // check the buffer size
1385
        if buffer.len() < sz as usize {
579✔
UNCOV
1386
            defx!("return ResultFindFixedStruct::Err");
×
UNCOV
1387
            return ResultFindFixedStruct::Err((
×
UNCOV
1388
                None,
×
1389
                Error::new(
×
1390
                    ErrorKind::InvalidData,
×
1391
                    format!(
×
1392
                        "buffer size {} less than fixedstruct size {} at fileoffset {}, file {:?}",
×
1393
                        buffer.len(), sz, fileoffset, self.path(),
×
1394
                    ),
×
1395
                ),
×
1396
            ));
×
1397
        }
579✔
1398

1399
        // zero out the slice
1400
        defo!("zero buffer[‥{}]", sz);
579✔
1401
        let slice_: &mut [u8] = &mut buffer[..sz as usize];
579✔
1402
        slice_.iter_mut().for_each(|m| *m = 0);
579✔
1403

1404
        // read raw bytes into the slice
1405
        let _readn = match self
579✔
1406
            .blockreader
579✔
1407
            .read_data_to_buffer(fileoffset, fileoffset + sz, false, slice_)
579✔
1408
        {
1409
            ResultReadDataToBuffer::Found(val) => val,
579✔
UNCOV
1410
            ResultReadDataToBuffer::Done => {
×
UNCOV
1411
                defx!("return ResultFindFixedStruct::Done; read_data_to_buffer returned Done");
×
UNCOV
1412
                return ResultFindFixedStruct::Done;
×
1413
            }
1414
            ResultReadDataToBuffer::Err(err) => {
×
1415
                self.set_error(&err);
×
UNCOV
1416
                defx!("return ResultFindFixedStruct::Err({:?})", err);
×
1417
                // an error from `blockreader.read_data_to_buffer` is unlikely to improve
1418
                // with a retry so return `None` signifying no more processing of the file
1419
                return ResultFindFixedStruct::Err((None, err));
×
1420
            }
1421
        };
1422
        debug_assert_eq!(_readn, sz as usize, "read {} bytes, expected {} bytes", _readn, sz);
579✔
1423

1424
        // create a FixedStruct from the slice
1425
        let fs: FixedStruct = match FixedStruct::new(
579✔
1426
            fileoffset,
579✔
1427
            &self.tz_offset,
579✔
1428
            slice_,
579✔
1429
            self.fixedstruct_type(),
579✔
1430
        ) {
579✔
1431
            Ok(val) => val,
579✔
UNCOV
1432
            Err(err) => {
×
UNCOV
1433
                defx!("return ResultFindFixedStruct::Done; FixedStruct::new returned Err({:?})", err);
×
UNCOV
1434
                return ResultFindFixedStruct::Err((Some(fo_next), err));
×
1435
            }
1436
        };
1437
        // update various statistics/counters
1438
        self.entries_processed += 1;
579✔
1439
        defo!("entries_processed = {}", self.entries_processed);
579✔
1440
        summary_stat!(self.dt_first_last_update(fs.dt()));
579✔
1441
        // try to drop blocks associated with the entry
1442
        self.drop_entry(&fs);
579✔
1443

1444
        defx!("return ResultFindFixedStruct::Found((fo_next={}, …))", fo_next);
579✔
1445

1446
        ResultFindFixedStruct::Found((fo_next, fs))
579✔
1447
    }
1,147✔
1448

1449
    /// Wrapper function for call to [`datetime::dt_after_or_before`] using the
1450
    /// [`FixedStruct::dt`] of the `entry`.
1451
    ///
1452
    /// [`datetime::dt_after_or_before`]: crate::data::datetime::dt_after_or_before
1453
    /// [`FixedStruct::dt`]: crate::data::fixedstruct::FixedStruct::dt
UNCOV
1454
    pub fn entry_dt_after_or_before(
×
UNCOV
1455
        entry: &FixedStruct,
×
UNCOV
1456
        dt_filter: &DateTimeLOpt,
×
1457
    ) -> Result_Filter_DateTime1 {
×
1458
        defñ!("({:?})", dt_filter);
×
1459

1460
        dt_after_or_before(entry.dt(), dt_filter)
×
1461
    }
×
1462

1463
    /// Wrapper function for call to [`datetime::dt_pass_filters`] using the
1464
    /// [`FixedStruct::dt`] of the `entry`.
1465
    ///
1466
    /// [`datetime::dt_pass_filters`]: crate::data::datetime::dt_pass_filters
1467
    /// [`FixedStruct::dt`]: crate::data::fixedstruct::FixedStruct::dt
1468
    #[inline(always)]
UNCOV
1469
    pub fn entry_pass_filters(
×
UNCOV
1470
        entry: &FixedStruct,
×
UNCOV
1471
        dt_filter_after: &DateTimeLOpt,
×
1472
        dt_filter_before: &DateTimeLOpt,
×
1473
    ) -> Result_Filter_DateTime2 {
×
1474
        defn!("({:?}, {:?})", dt_filter_after, dt_filter_before);
×
1475

1476
        let result: Result_Filter_DateTime2 = dt_pass_filters(
×
1477
            entry.dt(),
×
UNCOV
1478
            dt_filter_after,
×
1479
            dt_filter_before
×
1480
        );
1481
        defx!("(…) return {:?};", result);
×
1482

UNCOV
1483
        result
×
1484
    }
×
1485

1486
    /// Return an up-to-date [`SummaryFixedStructReader`] instance for this
1487
    /// `FixedStructReader`.
1488
    ///
1489
    /// [`SummaryFixedStructReader`]: SummaryFixedStructReader
1490
    #[allow(non_snake_case)]
1491
    pub fn summary(&self) -> SummaryFixedStructReader {
94✔
1492
        let fixedstructreader_fixedstructtype_opt = Some(self.fixedstruct_type());
94✔
1493
        let fixedstructreader_filetypefixedstruct_opt = Some(self.filetype_fixedstruct);
94✔
1494
        let fixedstructreader_high_score: Score = self.high_score;
94✔
1495
        let fixedstructreader_utmp_entries: Count = self.entries_processed;
94✔
1496
        let fixedstructreader_first_entry_fileoffset: FileOffset = self.first_entry_fileoffset;
94✔
1497
        let fixedstructreader_entries_out_of_order: usize = self.entries_out_of_order;
94✔
1498
        let fixedstructreader_utmp_entries_max: Count = self.entries_stored_highest as Count;
94✔
1499
        let fixedstructreader_utmp_entries_hit: Count = self.entries_hits as Count;
94✔
1500
        let fixedstructreader_utmp_entries_miss: Count = self.entries_miss as Count;
94✔
1501
        let fixedstructreader_drop_entry_ok: Count = self.drop_entry_ok;
94✔
1502
        let fixedstructreader_drop_entry_errors: Count = self.drop_entry_errors;
94✔
1503
        let fixedstructreader_datetime_first = self.dt_first;
94✔
1504
        let fixedstructreader_datetime_last = self.dt_last;
94✔
1505
        let fixedstructreader_map_tvpair_fo_max_len: usize = self.map_tvpair_fo_max_len;
94✔
1506

1507
        SummaryFixedStructReader {
94✔
1508
            fixedstructreader_fixedstructtype_opt,
94✔
1509
            fixedstructreader_filetypefixedstruct_opt,
94✔
1510
            fixedstructreader_fixedstruct_size: self.fixedstruct_size(),
94✔
1511
            fixedstructreader_high_score,
94✔
1512
            fixedstructreader_utmp_entries,
94✔
1513
            fixedstructreader_first_entry_fileoffset,
94✔
1514
            fixedstructreader_entries_out_of_order,
94✔
1515
            fixedstructreader_utmp_entries_max,
94✔
1516
            fixedstructreader_utmp_entries_hit,
94✔
1517
            fixedstructreader_utmp_entries_miss,
94✔
1518
            fixedstructreader_drop_entry_ok,
94✔
1519
            fixedstructreader_drop_entry_errors,
94✔
1520
            fixedstructreader_datetime_first,
94✔
1521
            fixedstructreader_datetime_last,
94✔
1522
            fixedstructreader_map_tvpair_fo_max_len,
94✔
1523
        }
94✔
1524
    }
94✔
1525

1526
    /// Return an up-to-date [`Summary`] instance for this `FixedStructReader`.
1527
    ///
1528
    /// [`Summary`]: crate::readers::summary::Summary
1529
    pub fn summary_complete(&self) -> Summary {
93✔
1530
        let path = self.path().clone();
93✔
1531
        let path_ntf = None;
93✔
1532
        let filetype = self.filetype();
93✔
1533
        let logmessagetype = filetype.to_logmessagetype();
93✔
1534
        let summaryblockreader = self.blockreader.summary();
93✔
1535
        let summaryfixedstructreader = self.summary();
93✔
1536
        let error: Option<String> = self.error.clone();
93✔
1537

1538
        Summary::new(
93✔
1539
            path,
93✔
1540
            path_ntf,
93✔
1541
            filetype,
93✔
1542
            logmessagetype,
93✔
1543
            Some(summaryblockreader),
93✔
1544
            None,
93✔
1545
            None,
93✔
1546
            None,
93✔
1547
            Some(summaryfixedstructreader),
93✔
1548
            None,
93✔
1549
            None,
93✔
1550
            None,
93✔
1551
            error,
93✔
1552
        )
1553
    }
93✔
1554
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc