Skip to main content

SegbRecord

Enum SegbRecord 

Source
pub enum SegbRecord {
    V1(SegbV1Record),
    V2(SegbV2Record),
}
Expand description

A version-neutral SEGB record, produced by read_segb.

Variants§

§

V1(SegbV1Record)

A record from a SEGB v1 file.

§

V2(SegbV2Record)

A record from a SEGB v2 file.

Implementations§

Source§

impl SegbRecord

Source

pub fn state(&self) -> EntryState

The logical state of this record.

Examples found in repository?
examples/dump_structure.rs (line 22)
9fn main() {
10    let path = std::env::args()
11        .nth(1)
12        .expect("usage: dump_structure <segb-file>");
13    let data = std::fs::read(&path).expect("read file");
14    let mut cur = std::io::Cursor::new(data);
15    let records = segb::read_segb(&mut cur).expect("parse SEGB");
16    println!("records: {}", records.len());
17    for (i, r) in records.iter().enumerate() {
18        // `crc_ok` is emitted so the differential harness can reconcile our
19        // CRC verdict against ccl-segb's `crc_passed` (Written records only).
20        println!(
21            "  [{i}] state={:?} ts_unix={:?} crc_ok={} payload_len={}",
22            r.state(),
23            r.timestamp_unix(),
24            r.crc_ok(),
25            r.payload().len()
26        );
27    }
28}
More examples
Hide additional examples
examples/dump_menuitems.rs (line 30)
21fn main() {
22    let path = std::env::args()
23        .nth(1)
24        .expect("usage: dump_menuitems <segb-file>");
25    let data = std::fs::read(&path).expect("read file");
26    let mut cur = std::io::Cursor::new(data);
27    let records = segb::read_segb(&mut cur).expect("parse SEGB");
28    let mut decoded = 0usize;
29    for (i, r) in records.iter().enumerate() {
30        if r.state() != EntryState::Written {
31            continue;
32        }
33        match segb::menuitem::decode_app_menu_item(r.payload(), r.timestamp_unix()) {
34            Ok(m) => {
35                println!(
36                    "  [{i}] application={:?} menu_item={:?} ts_unix={:?}",
37                    m.application, m.menu_item, m.timestamp_unix
38                );
39                decoded += 1;
40            }
41            Err(e) => println!("  [{i}] decode_error={e}"),
42        }
43    }
44    println!("menu_items: {decoded}");
45}
Source

pub fn timestamp_unix(&self) -> Option<f64>

The primary timestamp as Unix seconds (seconds since 1970-01-01T00:00:00Z).

  • For v1: timestamp1.
  • For v2: the trailer creation timestamp.

Returns None if the stored f64 is not finite.

Examples found in repository?
examples/dump_structure.rs (line 23)
9fn main() {
10    let path = std::env::args()
11        .nth(1)
12        .expect("usage: dump_structure <segb-file>");
13    let data = std::fs::read(&path).expect("read file");
14    let mut cur = std::io::Cursor::new(data);
15    let records = segb::read_segb(&mut cur).expect("parse SEGB");
16    println!("records: {}", records.len());
17    for (i, r) in records.iter().enumerate() {
18        // `crc_ok` is emitted so the differential harness can reconcile our
19        // CRC verdict against ccl-segb's `crc_passed` (Written records only).
20        println!(
21            "  [{i}] state={:?} ts_unix={:?} crc_ok={} payload_len={}",
22            r.state(),
23            r.timestamp_unix(),
24            r.crc_ok(),
25            r.payload().len()
26        );
27    }
28}
More examples
Hide additional examples
examples/dump_menuitems.rs (line 33)
21fn main() {
22    let path = std::env::args()
23        .nth(1)
24        .expect("usage: dump_menuitems <segb-file>");
25    let data = std::fs::read(&path).expect("read file");
26    let mut cur = std::io::Cursor::new(data);
27    let records = segb::read_segb(&mut cur).expect("parse SEGB");
28    let mut decoded = 0usize;
29    for (i, r) in records.iter().enumerate() {
30        if r.state() != EntryState::Written {
31            continue;
32        }
33        match segb::menuitem::decode_app_menu_item(r.payload(), r.timestamp_unix()) {
34            Ok(m) => {
35                println!(
36                    "  [{i}] application={:?} menu_item={:?} ts_unix={:?}",
37                    m.application, m.menu_item, m.timestamp_unix
38                );
39                decoded += 1;
40            }
41            Err(e) => println!("  [{i}] decode_error={e}"),
42        }
43    }
44    println!("menu_items: {decoded}");
45}
Source

pub fn payload(&self) -> &[u8]

The raw protobuf (or other format) payload bytes.

Examples found in repository?
examples/dump_structure.rs (line 25)
9fn main() {
10    let path = std::env::args()
11        .nth(1)
12        .expect("usage: dump_structure <segb-file>");
13    let data = std::fs::read(&path).expect("read file");
14    let mut cur = std::io::Cursor::new(data);
15    let records = segb::read_segb(&mut cur).expect("parse SEGB");
16    println!("records: {}", records.len());
17    for (i, r) in records.iter().enumerate() {
18        // `crc_ok` is emitted so the differential harness can reconcile our
19        // CRC verdict against ccl-segb's `crc_passed` (Written records only).
20        println!(
21            "  [{i}] state={:?} ts_unix={:?} crc_ok={} payload_len={}",
22            r.state(),
23            r.timestamp_unix(),
24            r.crc_ok(),
25            r.payload().len()
26        );
27    }
28}
More examples
Hide additional examples
examples/dump_menuitems.rs (line 33)
21fn main() {
22    let path = std::env::args()
23        .nth(1)
24        .expect("usage: dump_menuitems <segb-file>");
25    let data = std::fs::read(&path).expect("read file");
26    let mut cur = std::io::Cursor::new(data);
27    let records = segb::read_segb(&mut cur).expect("parse SEGB");
28    let mut decoded = 0usize;
29    for (i, r) in records.iter().enumerate() {
30        if r.state() != EntryState::Written {
31            continue;
32        }
33        match segb::menuitem::decode_app_menu_item(r.payload(), r.timestamp_unix()) {
34            Ok(m) => {
35                println!(
36                    "  [{i}] application={:?} menu_item={:?} ts_unix={:?}",
37                    m.application, m.menu_item, m.timestamp_unix
38                );
39                decoded += 1;
40            }
41            Err(e) => println!("  [{i}] decode_error={e}"),
42        }
43    }
44    println!("menu_items: {decoded}");
45}
Source

pub fn data_offset(&self) -> u64

File offset of the first byte of Self::payload.

Source

pub fn stored_crc32(&self) -> u32

The CRC-32 stored in the record header.

Source

pub fn computed_crc32(&self) -> u32

The CRC-32 computed over the payload bytes as read.

Source

pub fn crc_ok(&self) -> bool

Returns true if stored and computed CRC-32 values match.

Examples found in repository?
examples/dump_structure.rs (line 24)
9fn main() {
10    let path = std::env::args()
11        .nth(1)
12        .expect("usage: dump_structure <segb-file>");
13    let data = std::fs::read(&path).expect("read file");
14    let mut cur = std::io::Cursor::new(data);
15    let records = segb::read_segb(&mut cur).expect("parse SEGB");
16    println!("records: {}", records.len());
17    for (i, r) in records.iter().enumerate() {
18        // `crc_ok` is emitted so the differential harness can reconcile our
19        // CRC verdict against ccl-segb's `crc_passed` (Written records only).
20        println!(
21            "  [{i}] state={:?} ts_unix={:?} crc_ok={} payload_len={}",
22            r.state(),
23            r.timestamp_unix(),
24            r.crc_ok(),
25            r.payload().len()
26        );
27    }
28}

Trait Implementations§

Source§

impl Clone for SegbRecord

Source§

fn clone(&self) -> SegbRecord

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SegbRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.