From 25e15baa2b77dd07cabb337f649673a9eed138bb Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Wed, 3 Apr 2024 13:38:49 +0100 Subject: [PATCH] Compress the debug data for quite a large saving --- agb-gbafix/Cargo.lock | 32 ++++++++++++++++++++++++++++++++ agb-gbafix/Cargo.toml | 1 + agb-gbafix/src/lib.rs | 6 +++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/agb-gbafix/Cargo.lock b/agb-gbafix/Cargo.lock index 74b92ff4..8212dcdd 100644 --- a/agb-gbafix/Cargo.lock +++ b/agb-gbafix/Cargo.lock @@ -9,6 +9,7 @@ dependencies = [ "anyhow", "clap", "elf", + "lz4_flex", "rmp-serde", ] @@ -78,6 +79,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "clap" version = "4.5.3" @@ -117,6 +124,15 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b" +[[package]] +name = "lz4_flex" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75761162ae2b0e580d7e7c390558127e5f01b4194debd6221fd8c207fc80e3f5" +dependencies = [ + "twox-hash", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -192,6 +208,12 @@ dependencies = [ "syn", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.11.0" @@ -209,6 +231,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "static_assertions", +] + [[package]] name = "unicode-ident" version = "1.0.12" diff --git a/agb-gbafix/Cargo.toml b/agb-gbafix/Cargo.toml index 153466f3..a0099926 100644 --- a/agb-gbafix/Cargo.toml +++ b/agb-gbafix/Cargo.toml @@ -12,6 +12,7 @@ elf = "0.7" anyhow = "1" clap = "4" rmp-serde = "1" +lz4_flex = "0.11" [profile.dev] opt-level = 3 diff --git a/agb-gbafix/src/lib.rs b/agb-gbafix/src/lib.rs index ed86b1db..f2636550 100644 --- a/agb-gbafix/src/lib.rs +++ b/agb-gbafix/src/lib.rs @@ -165,7 +165,11 @@ fn write_debug( } let mut debug_data = vec![]; - rmp_serde::encode::write(&mut debug_data, &debug_sections)?; + { + let mut compressed_writer = lz4_flex::frame::FrameEncoder::new(&mut debug_data); + rmp_serde::encode::write(&mut compressed_writer, &debug_sections)?; + compressed_writer.flush()?; + } output.write_all(&debug_data)?; output.write_all(&(debug_data.len() as u32).to_le_bytes())?;