1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

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

@@ -1,3 +1,8 @@
/**
* @file saved_struct.h
* @brief SavedStruct - data serialization/de-serialization
*
*/
#pragma once
#include <stdint.h>
@@ -8,14 +13,50 @@
extern "C" {
#endif
/** Load data from the file in saved structure format
*
* @param[in] path The path to the file
* @param[out] data Pointer to the memory where to load data
* @param[in] size The size of the data
* @param[in] magic The magic to embed into metadata
* @param[in] version The version to embed into metadata
*
* @return true on success, false otherwise
*/
bool saved_struct_load(const char* path, void* data, size_t size, uint8_t magic, uint8_t version);
bool saved_struct_save(const char* path, void* data, size_t size, uint8_t magic, uint8_t version);
bool saved_struct_get_payload_size(
/** Save data in saved structure format
*
* @param[in] path The path to the file
* @param[in] data Pointer to the memory where data
* @param[in] size The size of the data
* @param[in] magic The magic to embed into metadata
* @param[in] version The version to embed into metadata
*
* @return true on success, false otherwise
*/
bool saved_struct_save(
const char* path,
const void* data,
size_t size,
uint8_t magic,
uint8_t version,
uint8_t version);
/** Get SavedStructure file metadata
*
* @param[in] path The path to the file
* @param[out] magic Pointer to store magic or NULL if you don't need it
* @param[out] version Pointer to store version or NULL if you don't need
* it
* @param[out] payload_size Pointer to store payload size or NULL if you don't
* need it
*
* @return true on success, false otherwise
*/
bool saved_struct_get_metadata(
const char* path,
uint8_t* magic,
uint8_t* version,
size_t* payload_size);
#ifdef __cplusplus