SavedStruct: Introduce saved_struct_get_metadata (#3392)

* SavedStruct: Replace saved_struct_get_payload_size with saved_struct_get_metadata
  This new function can obtain the magic value, version and payload size
  all at once. This makes the function useful e.g.
  for backwards compatibility.
* SavedStruct: const-qualify saved_struct_save
* Toolbox: add saved struct documentation

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Silent
2024-03-25 19:48:18 +01:00
committed by GitHub
parent 84beb9b23e
commit 8ec1c74baf
9 changed files with 86 additions and 38 deletions

View File

@@ -72,16 +72,19 @@ bool bt_keys_storage_load(BtKeysStorage* instance) {
bool loaded = false;
do {
// Get payload size
uint8_t magic = 0, version = 0;
size_t payload_size = 0;
if(!saved_struct_get_payload_size(
furi_string_get_cstr(instance->file_path),
BT_KEYS_STORAGE_MAGIC,
BT_KEYS_STORAGE_VERSION,
&payload_size)) {
if(!saved_struct_get_metadata(
furi_string_get_cstr(instance->file_path), &magic, &version, &payload_size)) {
FURI_LOG_E(TAG, "Failed to read payload size");
break;
}
if(magic != BT_KEYS_STORAGE_MAGIC || version != BT_KEYS_STORAGE_VERSION) {
FURI_LOG_E(TAG, "Saved data version is mismatched");
break;
}
if(payload_size > instance->nvm_sram_buff_size) {
FURI_LOG_E(TAG, "Saved data doesn't fit ram buffer");
break;