From ec0bc289295b46ac82d09a362e10fd3890cf5baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Stefa=C5=84ski?= Date: Sat, 23 May 2026 19:05:48 +0200 Subject: [PATCH] Split decode, decode_to_motec --- libsvld/src/lib.rs | 52 ++++++++++++++++++++++++++++++++------------- svldcli/src/main.rs | 2 +- svldgui/src/main.rs | 2 +- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/libsvld/src/lib.rs b/libsvld/src/lib.rs index fa04a80..57bed30 100644 --- a/libsvld/src/lib.rs +++ b/libsvld/src/lib.rs @@ -164,9 +164,15 @@ pub struct DecodeProcessInfo { pub chunk_size: usize, } +pub struct DecodeResult { + pub data: HashMap>, + pub metadata: HashMap, + + pub info: DecodeProcessInfo, +} + pub fn decode(dbc: &Dbc, - asc_path: &Path, - output_dir: &Path) -> DecodeProcessInfo { + asc_path: &Path) -> DecodeResult { let thread_count = std::thread::available_parallelism().unwrap().get(); let file = File::open(asc_path).unwrap(); @@ -178,10 +184,6 @@ pub fn decode(dbc: &Dbc, mmap.advise(Advice::WillNeed).unwrap(); let date = parse_asc_date(&mmap[..memchr::memchr(b'\r', &mmap).unwrap()]).unwrap(); - - let date_str = date - .and_utc() - .to_rfc3339_opts(chrono::SecondsFormat::Secs, true); // println!("Date: {}", date); let page_size = page_size::get(); @@ -253,8 +255,36 @@ pub fn decode(dbc: &Dbc, // println!("{:?}", unknown_ids); // println!("{:?}", error_frames); + DecodeResult { + data, + metadata, + info: DecodeProcessInfo { + unknown_ids, + error_frames, + date, + thread_count, + page_size, + pages_per_chunk, + chunk_size, + } + } +} + +pub fn decode_to_motec(dbc: &Dbc, + asc_path: &Path, + output_dir: &Path) -> DecodeProcessInfo { + let DecodeResult { + mut data, + metadata, + info, + } = decode(dbc, asc_path); + println!("Post processing"); + let date_str = info.date + .and_utc() + .to_rfc3339_opts(chrono::SecondsFormat::Secs, true); + for (_, frames) in &mut data { // frames.voracious_mt_sort(thread_count); frames.voracious_sort(); @@ -271,13 +301,5 @@ pub fn decode(dbc: &Dbc, motec::write(&output_dir.join(out_name), &msgs, data); println!("Finished!"); - DecodeProcessInfo { - unknown_ids, - error_frames, - date, - thread_count, - page_size, - pages_per_chunk, - chunk_size, - } + info } diff --git a/svldcli/src/main.rs b/svldcli/src/main.rs index b2167e4..673ba27 100644 --- a/svldcli/src/main.rs +++ b/svldcli/src/main.rs @@ -12,5 +12,5 @@ fn main() { let asc_path = Path::new(&args[2]); let output_dir = Path::new(&args[3]); - libsvld::decode(&dbc, asc_path, output_dir); + libsvld::decode_to_motec(&dbc, asc_path, output_dir); } diff --git a/svldgui/src/main.rs b/svldgui/src/main.rs index ffcad24..f2847cb 100644 --- a/svldgui/src/main.rs +++ b/svldgui/src/main.rs @@ -317,7 +317,7 @@ fn main() { .map_err(|e| format!("Failed to parse DBC: {:?}", e))?; let mut out = Vec::with_capacity(total); for (i, asc) in asc_paths.iter().enumerate() { - let info = libsvld::decode(&dbc, asc, &output_dir); + let info = libsvld::decode_to_motec(&dbc, asc, &output_dir); out.push(build_file_result(asc, info)); let done = i + 1; let w = window_weak.clone();