Skip to content

Commit

Permalink
replace bincode with rmp-serde
Browse files Browse the repository at this point in the history
bincode does not support serde(default) which ain't good for forward/backward compatibility
  • Loading branch information
SeaDve committed Dec 29, 2023
1 parent 94b125e commit 51c9eab
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
54 changes: 44 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ lto = true
adw = { package = "libadwaita", version = "0.5", features = ["v1_4"] }
anyhow = "1.0.75"
async-lock = "3.2"
bincode = "1"
futures-util = { version = "0.3.29", features = ["io"] }
futures-channel = "0.3.29"
fuzzy-matcher = "0.3.7"
Expand All @@ -20,6 +19,7 @@ gtk = { version = "0.7", package = "gtk4", features = ["gnome_45"] }
gtk_source = { package = "sourceview5", version = "0.7", features = ["v5_10"] }
indexmap = "2.1"
regex = "1.10.2"
rmp-serde = "1.1.2"
serde = { version = "1", features = ["derive"] }
tracing = "0.1.37"
tracing-subscriber = "0.3"
Expand Down
6 changes: 3 additions & 3 deletions src/recent_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod imp {

fn new() -> Self {
Self {
state_file: gio::File::for_path(APP_DATA_DIR.join("recents.bin")),
state_file: gio::File::for_path(APP_DATA_DIR.join("recents.msgpack")),
list: RefCell::new(IndexMap::new()),
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ impl RecentList {
let imp = this.imp();

let state = match imp.state_file.load_bytes_future().await {
Ok((bytes, _)) => bincode::deserialize::<State>(&bytes)?,
Ok((bytes, _)) => rmp_serde::from_slice::<State>(&bytes)?,
Err(err) => {
if !err.matches(gio::IOErrorEnum::NotFound) {
return Err(err.into());
Expand Down Expand Up @@ -128,7 +128,7 @@ impl RecentList {
let state = State {
recents: recent_states,
};
let bytes = bincode::serialize(&state)?;
let bytes = rmp_serde::to_vec_named(&state)?;

imp.state_file
.replace_contents_future(
Expand Down
6 changes: 3 additions & 3 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod imp {

fn new() -> Self {
Self {
state_file: gio::File::for_path(APP_DATA_DIR.join("state.bin")),
state_file: gio::File::for_path(APP_DATA_DIR.join("state.msgpack")),
default_window_width: Cell::new(DEFAULT_WINDOW_WIDTH),
default_window_height: Cell::new(DEFAULT_WINDOW_HEIGHT),
windows: RefCell::default(),
Expand Down Expand Up @@ -357,7 +357,7 @@ impl Session {
let now = Instant::now();

let state = match imp.state_file.load_bytes_future().await {
Ok((bytes, _)) => bincode::deserialize::<State>(&bytes)?,
Ok((bytes, _)) => rmp_serde::from_slice::<State>(&bytes)?,
Err(err) => {
if !err.matches(gio::IOErrorEnum::NotFound) {
return Err(err.into());
Expand Down Expand Up @@ -417,7 +417,7 @@ impl Session {
default_window_width: imp.default_window_width.get(),
default_window_height: imp.default_window_height.get(),
};
let bytes = bincode::serialize(&state)?;
let bytes = rmp_serde::to_vec_named(&state)?;

imp.state_file
.replace_contents_future(
Expand Down

0 comments on commit 51c9eab

Please sign in to comment.