Browse Source

melib: fix bincode serialization

Previous commit changed bincode deserializes in maildir and sqlite3.rs
from bincode::deserialize_from to using bincode::config::DefaultOptions
and bincode::Options trait's method deserialize_from.

However, these two different deserializes use a different default
settings: https://github.com/servo/bincode/issues/348

Specifically, varint encoding for integers is the default for
DefaultOptions but not when using bincode::{de,}serialize_* functions.
That means that serialized structs were not able to be deserialized.
This commit makes all {de,}serializations use the DefaultOptions
interface rather than the top level functions.
jmap-eventsource
Manos Pitsidianakis 1 year ago
parent
commit
a34f0aac5b
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 8
      melib/src/backends/maildir/backend.rs
  2. 6
      melib/src/backends/maildir/stream.rs
  3. 6
      melib/src/collection.rs
  4. 7
      melib/src/sqlite3.rs
  5. 6
      src/conf/accounts.rs

8
melib/src/backends/maildir/backend.rs

@ -289,7 +289,11 @@ impl MailBackend for MaildirType {
f.set_permissions(permissions)?;
let writer = io::BufWriter::new(f);
bincode::serialize_into(writer, &env)?;
bincode::Options::serialize_into(
bincode::config::DefaultOptions::new(),
writer,
&env,
)?;
}
(sender)(
account_hash,
@ -1366,7 +1370,7 @@ fn add_path_to_index(
permissions.set_mode(0o600); // Read/write for owner only.
f.set_permissions(permissions)?;
let writer = io::BufWriter::new(f);
bincode::serialize_into(writer, &env)?;
bincode::Options::serialize_into(bincode::config::DefaultOptions::new(), writer, &env)?;
}
Ok(env)
}

6
melib/src/backends/maildir/stream.rs

@ -162,7 +162,11 @@ impl MaildirStream {
f.set_permissions(permissions)?;
let writer = io::BufWriter::new(f);
bincode::serialize_into(writer, &env)?;
bincode::Options::serialize_into(
bincode::config::DefaultOptions::new(),
writer,
&env,
)?;
}
if !env.is_seen() {
unseen_total += 1;

6
melib/src/collection.rs

@ -88,7 +88,11 @@ impl Drop for Collection {
}
};
let writer = io::BufWriter::new(f);
bincode::serialize_into(writer, &self.threads).unwrap();
let _ = bincode::Options::serialize_into(
bincode::config::DefaultOptions::new(),
writer,
&self.thread,
);
}
}
}

7
melib/src/sqlite3.rs

@ -135,9 +135,10 @@ pub fn reset_db(description: &DatabaseDescription, identifier: Option<&str>) ->
impl ToSql for Envelope {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput> {
let v: Vec<u8> = bincode::serialize(self).map_err(|e| {
rusqlite::Error::ToSqlConversionFailure(Box::new(MeliError::new(e.to_string())))
})?;
let v: Vec<u8> = bincode::Options::serialize(bincode::config::DefaultOptions::new(), self)
.map_err(|e| {
rusqlite::Error::ToSqlConversionFailure(Box::new(MeliError::new(e.to_string())))
})?;
Ok(ToSqlOutput::from(v))
}
}

6
src/conf/accounts.rs

@ -406,7 +406,11 @@ impl Drop for Account {
permissions.set_mode(0o600); // Read/write for owner only.
f.set_permissions(permissions).unwrap();
let writer = io::BufWriter::new(f);
if let Err(err) = bincode::serialize_into(writer, &self.collection) {
if let Err(err) = bincode::Options::serialize_into(
bincode::config::DefaultOptions::new(),
writer,
&self.collection,
) {
eprintln!("{}", err);
};
};

Loading…
Cancel
Save