Skip to main content

kernel/event/record/
log.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! What the ledger records about itself.
7
8use serde::{Deserialize, Serialize};
9
10/// `log_truncated`: how many bytes a crash left behind that the opening
11/// procedure could not read as records.
12///
13/// The line is written by the city, because opening the ledger is the
14/// city's own work rather than any run's.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
17pub struct LogTruncated {
18    pub dropped_bytes: u64,
19}
20
21#[cfg(test)]
22#[allow(clippy::unwrap_used, clippy::expect_used, reason = "test code")]
23mod tests {
24    use super::*;
25    use crate::event::Payload;
26
27    /// The bytes `storage::jsonl::append::append_log_truncated` wrote by hand.
28    #[test]
29    fn a_truncation_line_writes_the_one_key_the_hand_written_map_wrote() {
30        let mut hand = serde_json::Map::new();
31        hand.insert("dropped_bytes".to_owned(), serde_json::Value::from(191u64));
32        let hand = Payload::new(hand).unwrap();
33        let typed = Payload::of(&LogTruncated { dropped_bytes: 191 }).unwrap();
34        assert_eq!(
35            serde_json::to_string(&typed).unwrap(),
36            serde_json::to_string(&hand).unwrap()
37        );
38        assert_eq!(typed.read::<LogTruncated>().unwrap().dropped_bytes, 191);
39    }
40}