Migrate serialization from Bincode to Postcard

- Replaced Bincode with Postcard for serialization/deserialization across configs and save operations.
- Simplified struct derives by removing `bincode`-specific traits.
- Updated `Cargo.toml` and `Cargo.lock` to include `postcard` and dependencies.
- Added padding stripping for deserialization and improved error handling.
- Adjusted serialization logic in `savegame_manager.rs` and related modules.
This commit is contained in:
2026-04-26 20:46:52 +02:00
parent 097aff5360
commit f1c85d1d74
10 changed files with 91 additions and 38 deletions

View File

@@ -1,3 +1,4 @@
use alloc::string::ToString;
use alloc::vec::Vec;
use embedded_savegame::storage::{Flash, Storage};
use embedded_storage::nor_flash::{NorFlash, ReadNorFlash};
@@ -32,6 +33,19 @@ struct ParsedSave<'a> {
data: &'a [u8],
}
fn strip_padding(data: &[u8]) -> &[u8] {
let mut end = data.len();
while end > 0 {
let b = data[end - 1];
if b == 0x00 || b == 0xFF {
end -= 1;
} else {
break;
}
}
&data[..end]
}
fn parse_save(data: &[u8]) -> FatResult<ParsedSave<'_>> {
if data.len() < SAVE_HEADER_LEN {
return Err(FatError::String {
@@ -60,7 +74,7 @@ fn parse_save(data: &[u8]) -> FatResult<ParsedSave<'_>> {
Ok(ParsedSave {
created_at,
data: &data[timestamp_end..],
data: strip_padding(&data[timestamp_end..]),
})
}
@@ -240,7 +254,7 @@ impl SavegameManager {
saves.push(SaveInfo {
idx,
len: 0,
created_at: None,
created_at: Some(err.to_string()),
});
}
}