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

jtmoon79 / super-speedy-syslog-searcher / 30326158672

28 Jul 2026 03:31AM UTC coverage: 70.857% (+1.9%) from 68.982%
30326158672

push

github

jtmoon79
(LIB) bump macro-string 0.3.0

19964 of 28175 relevant lines covered (70.86%)

1699356.33 hits per line

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

84.15
/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
    def2ñ,
50
    defn,
51
    defo,
52
    defx,
53
    defñ,
54
    den,
55
    deo,
56
    dex,
57
    deñ,
58
    pfn,
59
    pfo,
60
    pfx,
61
};
62

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

114
// -----------------
115
// FixedStructReader
116

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

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

131
pub type FoList = LinkedList<FileOffset>;
132

133
type MapTvPairToFo = BTreeMap<tv_pair_type, FileOffset>;
134

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

140
pub type ResultFindFixedStructProcZeroBlock = ResultFind<(FixedStructType, Score, ListFileOffsetFixedStructPtr), Error>;
141

142
pub type ResultTvFo = Result<(usize, usize, usize, Count, MapTvPairToFo)>;
143

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

147
type ListFileOffsetFixedStructPtr = LinkedList<(FileOffset, FixedStructDynPtr)>;
148

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

166
pub type ResultFixedStructReaderNewError = ResultFixedStructReaderNew<Error>;
167

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

183
pub type ResultFixedStructReaderScoreFileError = ResultFixedStructReaderScoreFile<Error>;
184

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

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

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

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

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

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

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

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

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

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

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

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

577
        def1x!("return FileOk(FixedStructReader)");
171✔
578

579
        ResultFixedStructReaderNew::FileOk(fixedstructreader)
171✔
580
    }
201✔
581

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

590
    /// See [`BlockReader::path_id`].
591
    ///
592
    /// [`BlockReader::path_id`]: crate::readers::blockreader::BlockReader#method.path_id
593
    #[inline(always)]
594
    pub const fn path_id(&self) -> PathId {
171✔
595
        self.blockreader.path_id()
171✔
596
    }
171✔
597

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

840
        defx!();
508✔
841
    }
508✔
842

843
    /// Update the statistic `DateTimeL` of
844
    /// `self.dt_first` and `self.dt_last`
845
    fn dt_first_last_update(
943✔
846
        &mut self,
943✔
847
        datetime: &DateTimeL,
943✔
848
    ) {
943✔
849
        if !summary_stats_enabled() {
943✔
850
            return;
×
851
        }
943✔
852
        defñ!("({:?})", datetime);
943✔
853
        match self.dt_first {
943✔
854
            Some(dt_first_) => {
789✔
855
                if &dt_first_ > datetime {
789✔
856
                    self.dt_first = Some(*datetime);
×
857
                }
789✔
858
            }
859
            None => {
154✔
860
                self.dt_first = Some(*datetime);
154✔
861
            }
154✔
862
        }
863
        match self.dt_last {
943✔
864
            Some(dt_last_) => {
789✔
865
                if &dt_last_ < datetime {
789✔
866
                    self.dt_last = Some(*datetime);
788✔
867
                }
788✔
868
            }
869
            None => {
154✔
870
                self.dt_last = Some(*datetime);
154✔
871
            }
154✔
872
        }
873
    }
943✔
874

875
    /// Proactively `drop` the [`Block`s] associated with the
876
    /// passed [`FixedStruct`]. Return count of dropped entries (0 or 1).
877
    ///
878
    /// _The caller must know what they are doing!_
879
    ///
880
    /// [`FixedStruct`]: crate::data::fixedstruct::FixedStruct
881
    /// [`Block`s]: crate::readers::blockreader::Block
882
    /// [`FileOffset`]: crate::common::FileOffset
883
    fn drop_entry(
1,033✔
884
        &mut self,
1,033✔
885
        fixedstruct: &FixedStruct,
1,033✔
886
    ) -> usize {
1,033✔
887
        let bsz: BlockSz = self.blocksz();
1,033✔
888
        defn!(
1,033✔
889
            "(fixedstruct@{}); offsets [{}‥{}), blocks [{}‥{}]",
890
            fixedstruct.fileoffset_begin(),
1,033✔
891
            fixedstruct.fileoffset_begin(),
1,033✔
892
            fixedstruct.fileoffset_end(),
1,033✔
893
            fixedstruct.blockoffset_begin(bsz),
1,033✔
894
            fixedstruct.blockoffset_end(bsz),
1,033✔
895
        );
896
        let mut dropped_ok: usize = 0;
1,033✔
897
        let mut dropped_err: usize = 0;
1,033✔
898
        let mut bo_at: BlockOffset = fixedstruct.blockoffset_begin(bsz);
1,033✔
899
        let bo_end: BlockOffset = fixedstruct.blockoffset_end(bsz);
1,033✔
900
        debug_assert_le!(bo_at, bo_end);
1,033✔
901
        while bo_at <= bo_end {
3,525✔
902
            defo!("block_use_count.get_mut({})", bo_at);
2,492✔
903
            match self.block_use_count.get_mut(&bo_at) {
2,492✔
904
                Some(count) => {
2,481✔
905
                    if *count <= 1 {
2,481✔
906
                        defo!(
1,575✔
907
                            "block_use_count[{}] found; count=={}; total span [{}‥{})",
908
                            bo_at, count,
909
                            BlockReader::file_offset_at_block_offset(bo_at, bsz),
1,575✔
910
                            BlockReader::file_offset_at_block_offset(bo_end + 1, bsz),
1,575✔
911
                        );
912
                        if self
1,575✔
913
                            .blockreader
1,575✔
914
                            .drop_block(bo_at)
1,575✔
915
                        {
916
                            defo!(
1,572✔
917
                                "dropped block {}; total span [{}‥{})",
918
                                bo_at,
919
                                BlockReader::file_offset_at_block_offset(bo_at, bsz),
1,572✔
920
                                BlockReader::file_offset_at_block_offset(bo_end + 1, bsz),
1,572✔
921
                            );
922
                            self.block_use_count.remove(&bo_at);
1,572✔
923
                            #[cfg(test)]
924
                            self.dropped_blocks.push_back(bo_at);
1,502✔
925
                            dropped_ok += 1;
1,572✔
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);
11✔
937
                }
938
            }
939
            bo_at += 1;
2,492✔
940
        }
941
        summary_stat!(
1,033✔
942
            if dropped_ok > 0 {
943✔
943
                self.drop_entry_ok += 1;
162✔
944
            }
846✔
945
        );
946
        summary_stat!(
1,033✔
947
            if dropped_err > 0 {
943✔
948
                self.drop_entry_errors += 1;
2✔
949
            }
941✔
950
        );
951
        defx!("return {}", dropped_ok);
1,033✔
952

953
        dropped_ok
1,033✔
954
    }
1,033✔
955

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

968
                Some(fixedstruct)
454✔
969
            }
970
            None => {
971
                defñ!("({}): not found in store", fileoffset);
579✔
972
                self.entries_miss += 1;
579✔
973

974
                None
579✔
975
            }
976
        }
977
    }
1,033✔
978

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

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

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

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

1135
                ResultFixedStructReaderScoreFileError::FileOk(highest_score_type, highest_score, highest_score_entries)
190✔
1136
            }
1137
        }
1138
    }
198✔
1139

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

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

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

1181
        let ret = FixedStructReader::score_file(blockreader, oneblock, types_to_bonus);
198✔
1182
        def1x!("score_file returned {:?}", ret);
198✔
1183

1184
        ret
198✔
1185
    }
198✔
1186

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1494
        result
×
1495
    }
×
1496

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

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

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

1549
        Summary::new(
93✔
1550
            path,
93✔
1551
            path_ntf,
93✔
1552
            filetype,
93✔
1553
            logmessagetype,
93✔
1554
            Some(summaryblockreader),
93✔
1555
            None,
93✔
1556
            None,
93✔
1557
            None,
93✔
1558
            Some(summaryfixedstructreader),
93✔
1559
            None,
93✔
1560
            None,
93✔
1561
            None,
93✔
1562
            error,
93✔
1563
        )
1564
    }
93✔
1565
}
1566

1567
impl Drop for FixedStructReader {
1568
    fn drop(&mut self) {
171✔
1569
        def2ñ!("FixedStructReader: PathID {} Path {:?}", self.path_id(), self.path());
171✔
1570
    }
171✔
1571
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc