Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Improvements #130

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ crc16 = "0.4"
clap = { version = "4.5", features = ["derive"], optional = true }
parse-display = "0.10"
thiserror = "2.0"
quick-xml = { version = "0.37.2", features = ["serialize", "serde-types"] }
serde = { version = "1.0", features = ["derive"] }
chrono = "0.4"
quick-xml = { version = "0.37.2", features = ["serialize", "serde-types"], optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_repr = { version = "0.1.19", optional = true }
chrono = { version = "0.4", features = ["serde"], optional = true }
rgb = { version = "0.8.50", no-default-featurs = true, optional = true }

[build-dependencies]
glob = "0.3"

Expand All @@ -29,8 +32,9 @@ pretty-hex = "0.4"
pretty_assertions = "1"

[features]
default = ["cli"]
default = ["cli", "xml"]
cli = ["dep:clap"]
xml = ["dep:serde", "dep:serde_repr", "dep:quick-xml", "dep:chrono", "dep:rgb"]

[[bin]]
name = "rekordcrate"
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use rekordcrate::setting::Setting;
"./tests/tests_setting.rs.in"
);

#[cfg(feature = "xml")]
write_test!(
out_dir.join("tests_xml.rs"),
"data/xml/*.xml",
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use clap::{Parser, Subcommand};
use rekordcrate::anlz::ANLZ;
use rekordcrate::pdb::{Header, PageType, Row};
use rekordcrate::setting::Setting;
use rekordcrate::xml::Document;
use std::path::PathBuf;

#[derive(Parser)]
Expand Down Expand Up @@ -49,6 +48,7 @@ enum Commands {
path: PathBuf,
},
/// Parse and dump a Pioneer XML (`*.xml`) file.
#[cfg(feature = "xml")]
DumpXML {
/// File to parse.
#[arg(value_name = "XML_FILE")]
Expand Down Expand Up @@ -166,10 +166,12 @@ fn dump_setting(path: &PathBuf) -> rekordcrate::Result<()> {
Ok(())
}

#[cfg(feature = "xml")]
fn dump_xml(path: &PathBuf) -> rekordcrate::Result<()> {
let file = std::fs::File::open(path)?;
let reader = std::io::BufReader::new(file);
let document: Document = quick_xml::de::from_reader(reader).expect("failed to deserialize XML");
let document: rekordcrate::xml::Document =
quick_xml::de::from_reader(reader).expect("failed to deserialize XML");
Comment on lines +173 to +174
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you figured out how to avoid the expect here yet? (the thing I criticized in the previous PR).

println!("{:#?}", document);

Ok(())
Expand All @@ -183,6 +185,7 @@ fn main() -> rekordcrate::Result<()> {
Commands::DumpPDB { path } => dump_pdb(path),
Commands::DumpANLZ { path } => dump_anlz(path),
Commands::DumpSetting { path } => dump_setting(path),
#[cfg(feature = "xml")]
Commands::DumpXML { path } => dump_xml(path),
}
}
Loading
Loading