This commit is contained in:
2026-01-26 13:53:51 -05:00
parent e1eff49be9
commit 53ed4775ae
19 changed files with 565 additions and 350 deletions

View File

@@ -1,12 +1,10 @@
use std::{
fs::{self, File},
io::Write,
path::Path,
};
use directories_next::ProjectDirs;
use ed25519_dalek::VerifyingKey;
use crate::net::BINCODE_CONFIG;
#[derive(Clone)]
pub struct DataDir {
@@ -21,7 +19,7 @@ impl Default for DataDir {
}
}
pub trait DataRsc: bincode::Encode + bincode::Decode<()> + Default {
pub trait DataRsc: bitcode::Encode + bitcode::DecodeOwned + Default {
fn path() -> &'static str;
}
@@ -33,8 +31,8 @@ impl DataDir {
pub fn load<T: DataRsc>(&self) -> T {
let path = self.get().join(T::path());
match fs::read(path) {
Ok(bytes) => match bincode::decode_from_slice(&bytes, BINCODE_CONFIG) {
Ok((data, _)) => data,
Ok(bytes) => match bitcode::decode(&bytes) {
Ok(data) => data,
Err(_) => todo!(),
},
Err(_) => T::default(),
@@ -45,8 +43,8 @@ impl DataDir {
let dir = self.get();
fs::create_dir_all(dir).unwrap();
let mut file = File::create(dir.join(T::path())).unwrap();
bincode::encode_into_std_write(data, &mut file, BINCODE_CONFIG).unwrap();
// TODO: used to use encode_into_std_write from bincode here
let data = bitcode::encode(data);
file.write_all(&data).unwrap();
}
}
pub struct DevicePublicKey(VerifyingKey);