Skip to content

Commit

Permalink
Reduce string allocations by using a writer pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
RainerZ committed Sep 28, 2024
1 parent 0eeb374 commit b72553a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/reg/registry/a2l_reader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
// Module a2l_reader
// Simplified A2L reader for integration testing
// Uses a2lfile crate to load A2L file

#![allow(dead_code)]

#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};

use a2lfile::A2lError;

pub fn a2l_load(filename: &str) -> Result<a2lfile::A2lFile, a2lfile::A2lError> {
trace!("Load A2L file {}", filename);
let input_filename = &std::ffi::OsString::from(filename);
let mut logmsgs = Vec::<A2lError>::new();
let res = a2lfile::load(input_filename, None, &mut logmsgs, true);
for log_msg in logmsgs {
warn!("A2l Loader: {}", log_msg);
}
match res {
Ok(a2l_file) => {
// Perform a consistency check
let mut logmsgs = Vec::<String>::new();
a2l_file.check(&mut logmsgs);
for log_msg in logmsgs {
warn!("A2l Checker: {}", log_msg);
}
Ok(a2l_file)
}

Err(e) => {
error!("a2lfile::load failed: {:?}", e);
Err(e)
}
}
}

0 comments on commit b72553a

Please sign in to comment.