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

jtmoon79 / super-speedy-syslog-searcher / 18082229368

29 Sep 2025 12:40AM UTC coverage: 69.783% (+0.2%) from 69.601%
18082229368

push

github

jtmoon79
(LIB) pin ctrlc=3.4.7

14415 of 20657 relevant lines covered (69.78%)

35839.2 hits per line

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

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

110
// -----------------
111
// FixedStructReader
112

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

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

127
pub type FoList = LinkedList<FileOffset>;
128

129
type MapTvPairToFo = BTreeMap<tv_pair_type, FileOffset>;
130

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

136
pub type ResultFindFixedStructProcZeroBlock = ResultFind<(FixedStructType, Score, ListFileOffsetFixedStructPtr), Error>;
137

138
pub type ResultTvFo = Result<(usize, usize, usize, usize, MapTvPairToFo)>;
139

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

143
type ListFileOffsetFixedStructPtr = LinkedList<(FileOffset, FixedStructDynPtr)>;
144

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

162
pub type ResultFixedStructReaderNewError = ResultFixedStructReaderNew<Error>;
163

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

179
pub type ResultFixedStructReaderScoreFileError = ResultFixedStructReaderScoreFile<Error>;
180

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

288
impl fmt::Debug for FixedStructReader {
289
    fn fmt(
70✔
290
        &self,
70✔
291
        f: &mut fmt::Formatter,
70✔
292
    ) -> fmt::Result {
70✔
293
        f.debug_struct("FixedStructReader")
70✔
294
            .field("Path", &self.path())
70✔
295
            .field("Entries", &self.cache_entries.len())
70✔
296
            .field("tz_offset", &self.tz_offset)
70✔
297
            .field("dt_first", &self.dt_first)
70✔
298
            .field("dt_last", &self.dt_last)
70✔
299
            .field("Error?", &self.error)
70✔
300
            .finish()
70✔
301
    }
70✔
302
}
303

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

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

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

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

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

455
        if map_tvpair_fo.is_empty() {
190✔
456
            if valid_no_filter > 0 {
19✔
457
                def1x!("return FileErrNoFixedStructWithinDtFilters");
19✔
458
                return ResultFixedStructReaderNew::FileErrNoFixedStructWithinDtFilters;
19✔
459
            }
×
460
            def1x!("return FileErrNoValidFixedStruct");
×
461
            return ResultFixedStructReaderNew::FileErrNoValidFixedStruct;
×
462
        }
171✔
463

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

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

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

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

582
        def1x!("return FileOk(FixedStructReader)");
171✔
583

584
        ResultFixedStructReaderNew::FileOk(fixedstructreader)
171✔
585
    }
201✔
586

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

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

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

611
    /// See [`BlockReader::path`].
612
    ///
613
    /// [`BlockReader::path`]: crate::readers::blockreader::BlockReader#method.path
614
    #[inline(always)]
615
    pub const fn path(&self) -> &FPath {
163✔
616
        self.blockreader.path()
163✔
617
    }
163✔
618

619
    /// See [`BlockReader::mtime`].
620
    ///
621
    /// [`BlockReader::mtime`]: crate::readers::blockreader::BlockReader#method.mtime
622
    pub fn mtime(&self) -> SystemTime {
70✔
623
        self.blockreader.mtime()
70✔
624
    }
70✔
625

626
    /// `Count` of `FixedStruct`s processed by this `FixedStructReader`
627
    /// (i.e. `self.entries_processed`).
628
    #[inline(always)]
629
    pub fn count_entries_processed(&self) -> Count {
1✔
630
        self.entries_processed
1✔
631
    }
1✔
632

633
    /// "_High watermark_" of `FixedStruct` stored in `self.cache_entries`.
634
    #[inline(always)]
635
    pub fn entries_stored_highest(&self) -> usize {
×
636
        self.entries_stored_highest
×
637
    }
×
638

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

650
    /// See [`BlockReader::file_offset_at_block_offset`].
651
    ///
652
    /// [`BlockReader::file_offset_at_block_offset`]: crate::readers::blockreader::BlockReader#method.file_offset_at_block_offset
653
    #[inline(always)]
654
    pub const fn file_offset_at_block_offset(
1✔
655
        &self,
1✔
656
        blockoffset: BlockOffset,
1✔
657
    ) -> FileOffset {
1✔
658
        BlockReader::file_offset_at_block_offset(blockoffset, self.blocksz())
1✔
659
    }
1✔
660

661
    /// See [`BlockReader::file_offset_at_block_offset_index`].
662
    ///
663
    /// [`BlockReader::file_offset_at_block_offset_index`]: crate::readers::blockreader::BlockReader#method.file_offset_at_block_offset_index
664
    #[inline(always)]
665
    pub const fn file_offset_at_block_offset_index(
1✔
666
        &self,
1✔
667
        blockoffset: BlockOffset,
1✔
668
        blockindex: BlockIndex,
1✔
669
    ) -> FileOffset {
1✔
670
        BlockReader::file_offset_at_block_offset_index(blockoffset, self.blocksz(), blockindex)
1✔
671
    }
1✔
672

673
    /// See [`BlockReader::block_index_at_file_offset`].
674
    ///
675
    /// [`BlockReader::block_index_at_file_offset`]: crate::readers::blockreader::BlockReader#method.block_index_at_file_offset
676
    #[inline(always)]
677
    pub const fn block_index_at_file_offset(
1✔
678
        &self,
1✔
679
        fileoffset: FileOffset,
1✔
680
    ) -> BlockIndex {
1✔
681
        BlockReader::block_index_at_file_offset(fileoffset, self.blocksz())
1✔
682
    }
1✔
683

684
    /// See [`BlockReader::count_blocks`].
685
    ///
686
    /// [`BlockReader::count_blocks`]: crate::readers::blockreader::BlockReader#method.count_blocks
687
    #[inline(always)]
688
    pub const fn count_blocks(&self) -> Count {
1✔
689
        BlockReader::count_blocks(self.filesz(), self.blocksz()) as Count
1✔
690
    }
1✔
691

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

700
    /// See [`BlockReader::fileoffset_last`].
701
    ///
702
    /// [`BlockReader::fileoffset_last`]: crate::readers::blockreader::BlockReader#method.fileoffset_last
703
    pub const fn fileoffset_last(&self) -> FileOffset {
910✔
704
        self.blockreader
910✔
705
            .fileoffset_last()
910✔
706
    }
910✔
707

708
    /// Is the passed `FileOffset` the last byte of the file?
709
    pub const fn is_fileoffset_last(
908✔
710
        &self,
908✔
711
        fileoffset: FileOffset,
908✔
712
    ) -> bool {
908✔
713
        self.fileoffset_last() == fileoffset
908✔
714
    }
908✔
715

716
    /// Is the passed `FixedStruct` the last of the file?
717
    #[inline(always)]
718
    pub fn is_last(
902✔
719
        &self,
902✔
720
        fixedstruct: &FixedStruct,
902✔
721
    ) -> bool {
902✔
722
        self.is_fileoffset_last(fixedstruct.fileoffset_end() - 1)
902✔
723
    }
902✔
724

725
    /// Return the `FileOffset` that is adjusted to the beginning offset of
726
    /// a `fixedstruct` entry.
727
    #[inline(always)]
728
    pub const fn fileoffset_to_fixedstructoffset(
1✔
729
        &self,
1✔
730
        fileoffset: FileOffset,
1✔
731
    ) -> FileOffset {
1✔
732
        (fileoffset / self.fixedstruct_size_fo()) * self.fixedstruct_size_fo()
1✔
733
    }
1✔
734

735
    /// Return the first file offset from `self.map_tvpair_fo` for the first
736
    /// entry as sorted by `tv_pair_type` (datetime); i.e. the earliest entry.
737
    /// Ties are broken by `FileOffset`.
738
    pub fn fileoffset_first(&self) -> Option<FileOffset> {
102✔
739
        match self
102✔
740
            .map_tvpair_fo
102✔
741
            .iter()
102✔
742
            .min_by_key(|(tv_pair, fo)| (*tv_pair, *fo))
971✔
743
        {
744
            Some((_tv_pair, fo_)) => Some(*fo_),
102✔
745
            None => None,
×
746
        }
747
    }
102✔
748

749
    /// The size in bytes of the `FixedStruct` entries managed by this
750
    /// `FixedStructReader`.
751
    #[inline(always)]
752
    pub const fn fixedstruct_size(&self) -> usize {
1,245✔
753
        self.fixedstruct_size
1,245✔
754
    }
1,245✔
755

756
    /// [`fixedstruct_size`] as a `FileOffset`.
757
    ///
758
    /// [`fixedstruct_size`]: self::FixedStructReader#method.fixedstruct_size
759
    #[inline(always)]
760
    pub const fn fixedstruct_size_fo(&self) -> FileOffset {
1,150✔
761
        self.fixedstruct_size() as FileOffset
1,150✔
762
    }
1,150✔
763

764
    /// The `FixedStructType` of the file.
765
    #[inline(always)]
766
    pub const fn fixedstruct_type(&self) -> FixedStructType {
673✔
767
        self.fixedstruct_type
673✔
768
    }
673✔
769

770
    /// Return all currently stored `FileOffset` in `self.cache_entries`.
771
    ///
772
    /// Only for testing.
773
    #[cfg(test)]
774
    pub fn get_fileoffsets(&self) -> Vec<FileOffset> {
1✔
775
        self.cache_entries
1✔
776
            .keys()
1✔
777
            .cloned()
1✔
778
            .collect()
1✔
779
    }
1✔
780

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

813
    /// Store information about a single [`FixedStruct`] entry.
814
    ///
815
    /// Should only be called by `FixedStructReader::new`
816
    ///
817
    /// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
818
    fn insert_cache_entry(
508✔
819
        &mut self,
508✔
820
        entry: FixedStruct,
508✔
821
    ) {
508✔
822
        defn!("@{}", entry.fileoffset_begin());
508✔
823
        let fo_beg: FileOffset = entry.fileoffset_begin();
508✔
824
        debug_assert!(
508✔
825
            !self.cache_entries.contains_key(&fo_beg),
508✔
826
            "self.cache_entries already contains key {}",
×
827
            fo_beg
828
        );
829

830
        // update some stats and (most importantly) `self.cache_entries`
831
        self.cache_entries
508✔
832
            .insert(fo_beg, entry);
508✔
833
        self.entries_stored_highest = std::cmp::max(self.entries_stored_highest, self.cache_entries.len());
508✔
834
        self.entries_processed += 1;
508✔
835
        defo!("entries_processed = {}", self.entries_processed);
508✔
836

837
        defx!();
508✔
838
    }
508✔
839

840
    /// Update the statistic `DateTimeL` of
841
    /// `self.dt_first` and `self.dt_last`
842
    fn dt_first_last_update(
1,033✔
843
        &mut self,
1,033✔
844
        datetime: &DateTimeL,
1,033✔
845
    ) {
1,033✔
846
        defñ!("({:?})", datetime);
1,033✔
847
        // TODO: cost-savings: the `dt_first` and `dt_last` are only for `--summary`,
848
        //       no need to always copy datetimes.
849
        //       Would be good to only run this when `if self.do_summary {...}`
850
        match self.dt_first {
1,033✔
851
            Some(dt_first_) => {
872✔
852
                if &dt_first_ > datetime {
872✔
853
                    self.dt_first = Some(*datetime);
×
854
                }
872✔
855
            }
856
            None => {
161✔
857
                self.dt_first = Some(*datetime);
161✔
858
            }
161✔
859
        }
860
        match self.dt_last {
1,033✔
861
            Some(dt_last_) => {
872✔
862
                if &dt_last_ < datetime {
872✔
863
                    self.dt_last = Some(*datetime);
871✔
864
                }
871✔
865
            }
866
            None => {
161✔
867
                self.dt_last = Some(*datetime);
161✔
868
            }
161✔
869
        }
870
    }
1,033✔
871

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

949
        dropped_ok
1,033✔
950
    }
1,033✔
951

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

964
                Some(fixedstruct)
454✔
965
            }
966
            None => {
967
                defñ!("({}): not found in store", fileoffset);
579✔
968
                self.entries_miss += 1;
579✔
969

970
                None
579✔
971
            }
972
        }
973
    }
1,033✔
974

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

1011
        for (fixedstructtype, bonus) in types_to_bonus.into_iter() {
771✔
1012
            let mut _count_loop: usize = 0;
771✔
1013
            let mut count_found_entries: usize = 0;
771✔
1014
            let mut high_score: Score = 0;
771✔
1015
            let mut fo: FileOffset = 0;
771✔
1016
            let mut found_entries = ListFileOffsetFixedStructPtr::new();
771✔
1017

1018
            loop {
1019
                if count_found_entries >= COUNT_FOUND_ENTRIES_MAX {
4,192✔
1020
                    def1o!("count_found_entries {} >= COUNT_FOUND_ENTRIES_MAX {}", count_found_entries, COUNT_FOUND_ENTRIES_MAX);
724✔
1021
                    break;
724✔
1022
                }
3,468✔
1023
                _count_total += 1;
3,468✔
1024
                _count_loop += 1;
3,468✔
1025
                let utmp_sz: usize = fixedstructtype.size();
3,468✔
1026
                let fo_end = fo + utmp_sz as FileOffset;
3,468✔
1027
                def1o!(
3,468✔
1028
                    "loop try {} (total {}), fixedstructtype {:?}, zero the buffer (size {}), looking at fileoffset {}‥{} (0x{:08X}‥0x{:08X})",
3,468✔
1029
                    _count_loop, _count_total, fixedstructtype, buffer.len(), fo, fo_end, fo, fo_end
3,468✔
1030
                );
1031
                // zero out the buffer
1032
                // XXX: not strictly necessary to zero buffer but it helps humans
1033
                //      manually reviewing debug logs
1034
                // this compiles down to a single `memset` call
1035
                // 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
1036
                // See https://godbolt.org/z/KcxW9hWYb
1037
                buffer.iter_mut().for_each(|m| *m = 0);
3,468✔
1038
                // read data into buffer
1039
                let buffer_read: usize = match blockreader.read_data_to_buffer(fo, fo_end, oneblock, &mut buffer) {
3,468✔
1040
                    ResultReadDataToBuffer::Found(buffer_read) => buffer_read,
3,421✔
1041
                    ResultReadDataToBuffer::Err(err) => {
×
1042
                        def1x!("return Err");
×
1043
                        return ResultFixedStructReaderScoreFileError::FileErrIo(err);
×
1044
                    }
1045
                    ResultReadDataToBuffer::Done => {
47✔
1046
                        // reached end of block (if `oneblock` is `true`) or end of file
1047
                        break;
47✔
1048
                    }
1049
                };
1050
                if buffer_read < utmp_sz {
3,421✔
1051
                    def1o!(
×
1052
                        "read_data_to_buffer read bytes {} < {} requested fixedstruct size bytes; break",
×
1053
                        buffer_read,
1054
                        utmp_sz,
1055
                    );
1056
                    break;
×
1057
                }
3,421✔
1058
                // advance the file offset for the next loop
1059
                let fo2 = fo;
3,421✔
1060
                fo += utmp_sz as FileOffset;
3,421✔
1061
                // grab the slice of interest
1062
                let slice_ = &buffer[..buffer_read];
3,421✔
1063
                // convert buffer to fixedstruct
1064
                let fixedstructptr: FixedStructDynPtr = match buffer_to_fixedstructptr(slice_, fixedstructtype) {
3,421✔
1065
                    Some(val) => val,
2,311✔
1066
                    None => {
1067
                        def1o!(
1,110✔
1068
                            "buffer_to_fixedstructptr(buf len {}, {:?}) returned None; continue",
1,110✔
1069
                            buffer.len(),
1,110✔
1070
                            fixedstructtype,
1071
                        );
1072
                        continue;
1,110✔
1073
                    }
1074
                };
1075
                count_found_entries += 1;
2,311✔
1076
                // score the newly create fixedstruct
1077
                let score: Score = FixedStruct::score_fixedstruct(&fixedstructptr, bonus);
2,311✔
1078
                def1o!("score {} for entry type {:?} @[{}‥{}]", score, fixedstructptr.fixedstruct_type(), fo2, fo_end);
2,311✔
1079
                // update the high score
1080
                let _fs_type: FixedStructType = fixedstructptr.fixedstruct_type();
2,311✔
1081
                found_entries.push_back((fo2, fixedstructptr));
2,311✔
1082
                if score <= high_score {
2,311✔
1083
                    def1o!("score {} ({:?}) not higher than high score {}", score, _fs_type, high_score,);
2,094✔
1084
                    // score is not higher than high score so continue
1085
                    continue;
2,094✔
1086
                }
217✔
1087
                // there is a new high score for this type
1088
                def1o!("new high score {} for entry type {:?} @[{}‥{}]", score, _fs_type, fo2, fo_end);
217✔
1089
                high_score = score;
217✔
1090
            }
1091
            // finished with that fixedstructtype
1092
            // so check if it's high score beat any previous high score of a different fixedstructtype
1093
            if high_score > highest_score {
771✔
1094
                // a new high score was found for a different type so throw away
1095
                // linked lists of entries for the previous type
1096
                match highest_score_type {
198✔
1097
                    None => {
1098
                        def1o!(
190✔
1099
                            "new highest score {} entry type {:?} with {} entries",
190✔
1100
                            high_score, fixedstructtype, found_entries.len(),
190✔
1101
                        );
1102
                    }
1103
                    Some(_highest_score_type) => {
8✔
1104
                        def1o!(
8✔
1105
                            "new highest score {} entry type {:?} with {} entries; replaces old high score {} entry type {:?} with {} entries (entries dropped)",
8✔
1106
                            high_score, fixedstructtype, found_entries.len(),
8✔
1107
                            highest_score, _highest_score_type, highest_score_entries.len(),
8✔
1108
                        );
1109
                    }
1110
                }
1111
                highest_score = high_score;
198✔
1112
                highest_score_type = Some(fixedstructtype);
198✔
1113
                highest_score_entries = found_entries;
198✔
1114
            } else {
1115
                def1o!(
573✔
1116
                    "no new highest score: score {} entry type {:?} with {} entries. old high score remains: score {} entry type {:?} with {} entries",
573✔
1117
                    high_score, fixedstructtype, found_entries.len(),
573✔
1118
                    highest_score, highest_score_type, highest_score_entries.len(),
573✔
1119
                );
1120
            }
1121
        }
1122

1123
        match highest_score_type {
198✔
1124
            None => {
1125
                def1x!("return Err {:?}", ResultFixedStructReaderScoreFileError::FileErrNoHighScore);
8✔
1126
                return ResultFixedStructReaderScoreFileError::FileErrNoHighScore;
8✔
1127
            }
1128
            Some(highest_score_type) => {
190✔
1129
                def1x!("return Ok(({:?}, {}, found_entries))", highest_score_type, highest_score);
190✔
1130

1131
                ResultFixedStructReaderScoreFileError::FileOk(highest_score_type, highest_score, highest_score_entries)
190✔
1132
            }
1133
        }
1134
    }
198✔
1135

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

1157
        // short-circuit special case of empty file
1158
        if blockreader.filesz() == 0 {
198✔
1159
            def1x!("empty file; return FileErrEmpty");
×
1160
            return ResultFixedStructReaderScoreFileError::FileErrEmpty;
×
1161
        }
198✔
1162

1163
        let types_to_bonus: FixedStructTypeSet = match filesz_to_types(
198✔
1164
            blockreader.filesz(),
198✔
1165
            filetype_fixedstruct,
198✔
1166
        ) {
198✔
1167
            Some(set) => set,
198✔
1168
            None => {
1169
                de_wrn!("FixedStructReader::filesz_to_types({}) failed; file {:?}",
×
1170
                        blockreader.filesz(), blockreader.path());
×
1171
                def1x!("filesz_to_types returned None; return FileErrNoValidFixedStruct");
×
1172
                return ResultFixedStructReaderScoreFileError::FileErrNoValidFixedStruct;
×
1173
            }
1174
        };
1175
        def1o!("filesz_to_types returned {} types: {:?}", types_to_bonus.len(), types_to_bonus);
198✔
1176

1177
        let ret = FixedStructReader::score_file(blockreader, oneblock, types_to_bonus);
198✔
1178
        def1x!("score_file returned {:?}", ret);
198✔
1179

1180
        ret
198✔
1181
    }
198✔
1182

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

1209
        let tv_filter_after: Option<tv_pair_type> = match dt_filter_after {
190✔
1210
            Some(dt) => Some(convert_datetime_tvpair(dt)),
60✔
1211
            None => None,
130✔
1212
        };
1213
        defo!("tv_filter_after: {:?}", tv_filter_after);
190✔
1214
        let tv_filter_before: Option<tv_pair_type> = match dt_filter_before {
190✔
1215
            Some(dt) => Some(convert_datetime_tvpair(dt)),
34✔
1216
            None => None,
156✔
1217
        };
1218
        defo!("tv_filter_before: {:?}", tv_filter_before);
190✔
1219

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

1306
            fo += entry_sz;
1,094✔
1307
        }
1308
        // 6. return list of valid entries
1309
        defx!("map_tv_pair_fo len {}", map_tv_pair_fo.len());
190✔
1310

1311
        ResultTvFo::Ok((total_entries, invalid, valid_no_pass_filter, out_of_order, map_tv_pair_fo))
190✔
1312
    }
190✔
1313

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

1332
        let sz: FileOffset = self.fixedstruct_size_fo();
1,147✔
1333
        debug_assert_eq!(fo % sz, 0, "fileoffset {} not multiple of {}", fo, sz,);
1,147✔
1334
        let fileoffset: FileOffset = fo - (fo % sz);
1,147✔
1335

1336
        if fileoffset >= self.filesz() {
1,147✔
1337
            defx!("return ResultFindFixedStruct::Done; fileoffset {} >= filesz {}", fileoffset, self.filesz());
114✔
1338
            return ResultFindFixedStruct::Done;
114✔
1339
        }
1,033✔
1340

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

1378
            fo_next_
1,033✔
1379
        };
1380
        defo!("fo_next = {}", fo_next);
1,033✔
1381

1382
        // check if the entry is already stored
1383
        if let Some(fixedstruct) = self.remove_cache_entry(fileoffset) {
1,033✔
1384
            self.dt_first_last_update(fixedstruct.dt());
454✔
1385
            // try to drop blocks associated with the entry
1386
            self.drop_entry(&fixedstruct);
454✔
1387
            defx!("remove_cache_entry found fixedstruct at fileoffset {}; return Found({}, …)", fileoffset, fo_next,);
454✔
1388
            return ResultFindFixedStruct::Found((fo_next, fixedstruct));
454✔
1389
        }
579✔
1390

1391
        // the entry was not in the cache so read the raw bytes from the file
1392
        // and transform them into a `FixedStruct`
1393

1394
        // check the buffer size
1395
        if buffer.len() < sz as usize {
579✔
1396
            defx!("return ResultFindFixedStruct::Err");
×
1397
            return ResultFindFixedStruct::Err((
×
1398
                None,
×
1399
                Error::new(
×
1400
                    ErrorKind::InvalidData,
×
1401
                    format!(
×
1402
                        "buffer size {} less than fixedstruct size {} at fileoffset {}, file {:?}",
×
1403
                        buffer.len(), sz, fileoffset, self.path(),
×
1404
                    ),
×
1405
                ),
×
1406
            ));
×
1407
        }
579✔
1408

1409
        // zero out the slice
1410
        defo!("zero buffer[‥{}]", sz);
579✔
1411
        let slice_: &mut [u8] = &mut buffer[..sz as usize];
579✔
1412
        slice_.iter_mut().for_each(|m| *m = 0);
579✔
1413

1414
        // read raw bytes into the slice
1415
        let _readn = match self
579✔
1416
            .blockreader
579✔
1417
            .read_data_to_buffer(fileoffset, fileoffset + sz, false, slice_)
579✔
1418
        {
1419
            ResultReadDataToBuffer::Found(val) => val,
579✔
1420
            ResultReadDataToBuffer::Done => {
×
1421
                defx!("return ResultFindFixedStruct::Done; read_data_to_buffer returned Done");
×
1422
                return ResultFindFixedStruct::Done;
×
1423
            }
1424
            ResultReadDataToBuffer::Err(err) => {
×
1425
                self.set_error(&err);
×
1426
                defx!("return ResultFindFixedStruct::Err({:?})", err);
×
1427
                // an error from `blockreader.read_data_to_buffer` is unlikely to improve
1428
                // with a retry so return `None` signifying no more processing of the file
1429
                return ResultFindFixedStruct::Err((None, err));
×
1430
            }
1431
        };
1432
        debug_assert_eq!(_readn, sz as usize, "read {} bytes, expected {} bytes", _readn, sz);
579✔
1433

1434
        // create a FixedStruct from the slice
1435
        let fs: FixedStruct = match FixedStruct::new(
579✔
1436
            fileoffset,
579✔
1437
            &self.tz_offset,
579✔
1438
            &slice_,
579✔
1439
            self.fixedstruct_type(),
579✔
1440
        ) {
579✔
1441
            Ok(val) => val,
579✔
1442
            Err(err) => {
×
1443
                defx!("return ResultFindFixedStruct::Done; FixedStruct::new returned Err({:?})", err);
×
1444
                return ResultFindFixedStruct::Err((Some(fo_next), err));
×
1445
            }
1446
        };
1447
        // update various statistics/counters
1448
        self.entries_processed += 1;
579✔
1449
        defo!("entries_processed = {}", self.entries_processed);
579✔
1450
        self.dt_first_last_update(fs.dt());
579✔
1451
        // try to drop blocks associated with the entry
1452
        self.drop_entry(&fs);
579✔
1453

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

1456
        ResultFindFixedStruct::Found((fo_next, fs))
579✔
1457
    }
1,147✔
1458

1459
    /// Wrapper function for call to [`datetime::dt_after_or_before`] using the
1460
    /// [`FixedStruct::dt`] of the `entry`.
1461
    ///
1462
    /// [`datetime::dt_after_or_before`]: crate::data::datetime::dt_after_or_before
1463
    /// [`FixedStruct::dt`]: crate::data::fixedstruct::FixedStruct::dt
1464
    pub fn entry_dt_after_or_before(
×
1465
        entry: &FixedStruct,
×
1466
        dt_filter: &DateTimeLOpt,
×
1467
    ) -> Result_Filter_DateTime1 {
×
1468
        defñ!("({:?})", dt_filter);
×
1469

1470
        dt_after_or_before(entry.dt(), dt_filter)
×
1471
    }
×
1472

1473
    /// Wrapper function for call to [`datetime::dt_pass_filters`] using the
1474
    /// [`FixedStruct::dt`] of the `entry`.
1475
    ///
1476
    /// [`datetime::dt_pass_filters`]: crate::data::datetime::dt_pass_filters
1477
    /// [`FixedStruct::dt`]: crate::data::fixedstruct::FixedStruct::dt
1478
    #[inline(always)]
1479
    pub fn entry_pass_filters(
×
1480
        entry: &FixedStruct,
×
1481
        dt_filter_after: &DateTimeLOpt,
×
1482
        dt_filter_before: &DateTimeLOpt,
×
1483
    ) -> Result_Filter_DateTime2 {
×
1484
        defn!("({:?}, {:?})", dt_filter_after, dt_filter_before);
×
1485

1486
        let result: Result_Filter_DateTime2 = dt_pass_filters(
×
1487
            entry.dt(),
×
1488
            dt_filter_after,
×
1489
            dt_filter_before
×
1490
        );
1491
        defx!("(…) return {:?};", result);
×
1492

1493
        result
×
1494
    }
×
1495

1496
    /// Return an up-to-date [`SummaryFixedStructReader`] instance for this
1497
    /// `FixedStructReader`.
1498
    ///
1499
    /// [`SummaryFixedStructReader`]: SummaryFixedStructReader
1500
    #[allow(non_snake_case)]
1501
    pub fn summary(&self) -> SummaryFixedStructReader {
94✔
1502
        let fixedstructreader_fixedstructtype_opt = Some(self.fixedstruct_type());
94✔
1503
        let fixedstructreader_filetypefixedstruct_opt = Some(self.filetype_fixedstruct);
94✔
1504
        let fixedstructreader_high_score: Score = self.high_score;
94✔
1505
        let fixedstructreader_utmp_entries: Count = self.entries_processed;
94✔
1506
        let fixedstructreader_first_entry_fileoffset: FileOffset = self.first_entry_fileoffset;
94✔
1507
        let fixedstructreader_entries_out_of_order: usize = self.entries_out_of_order;
94✔
1508
        let fixedstructreader_utmp_entries_max: Count = self.entries_stored_highest as Count;
94✔
1509
        let fixedstructreader_utmp_entries_hit: Count = self.entries_hits as Count;
94✔
1510
        let fixedstructreader_utmp_entries_miss: Count = self.entries_miss as Count;
94✔
1511
        let fixedstructreader_drop_entry_ok: Count = self.drop_entry_ok;
94✔
1512
        let fixedstructreader_drop_entry_errors: Count = self.drop_entry_errors;
94✔
1513
        let fixedstructreader_datetime_first = self.dt_first;
94✔
1514
        let fixedstructreader_datetime_last = self.dt_last;
94✔
1515
        let fixedstructreader_map_tvpair_fo_max_len: usize = self.map_tvpair_fo_max_len;
94✔
1516

1517
        SummaryFixedStructReader {
94✔
1518
            fixedstructreader_fixedstructtype_opt,
94✔
1519
            fixedstructreader_filetypefixedstruct_opt,
94✔
1520
            fixedstructreader_fixedstruct_size: self.fixedstruct_size(),
94✔
1521
            fixedstructreader_high_score,
94✔
1522
            fixedstructreader_utmp_entries,
94✔
1523
            fixedstructreader_first_entry_fileoffset,
94✔
1524
            fixedstructreader_entries_out_of_order,
94✔
1525
            fixedstructreader_utmp_entries_max,
94✔
1526
            fixedstructreader_utmp_entries_hit,
94✔
1527
            fixedstructreader_utmp_entries_miss,
94✔
1528
            fixedstructreader_drop_entry_ok,
94✔
1529
            fixedstructreader_drop_entry_errors,
94✔
1530
            fixedstructreader_datetime_first,
94✔
1531
            fixedstructreader_datetime_last,
94✔
1532
            fixedstructreader_map_tvpair_fo_max_len,
94✔
1533
        }
94✔
1534
    }
94✔
1535

1536
    /// Return an up-to-date [`Summary`] instance for this `FixedStructReader`.
1537
    ///
1538
    /// [`Summary`]: crate::readers::summary::Summary
1539
    pub fn summary_complete(&self) -> Summary {
93✔
1540
        let path = self.path().clone();
93✔
1541
        let path_ntf = None;
93✔
1542
        let filetype = self.filetype();
93✔
1543
        let logmessagetype = filetype.to_logmessagetype();
93✔
1544
        let summaryblockreader = self.blockreader.summary();
93✔
1545
        let summaryutmpreader = self.summary();
93✔
1546
        let error: Option<String> = self.error.clone();
93✔
1547

1548
        Summary::new(
93✔
1549
            path,
93✔
1550
            path_ntf,
93✔
1551
            filetype,
93✔
1552
            logmessagetype,
93✔
1553
            Some(summaryblockreader),
93✔
1554
            None,
93✔
1555
            None,
93✔
1556
            None,
93✔
1557
            Some(summaryutmpreader),
93✔
1558
            None,
93✔
1559
            None,
93✔
1560
            error,
93✔
1561
        )
1562
    }
93✔
1563
}
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