2024-03-25 18:48:18 +00:00
|
|
|
/**
|
|
|
|
* @file saved_struct.h
|
|
|
|
* @brief SavedStruct - data serialization/de-serialization
|
|
|
|
*
|
|
|
|
*/
|
2021-11-03 17:22:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2024-03-25 18:48:18 +00:00
|
|
|
/** 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
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
bool saved_struct_load(const char* path, void* data, size_t size, uint8_t magic, uint8_t version);
|
2021-11-03 17:22:49 +00:00
|
|
|
|
2024-03-25 18:48:18 +00:00
|
|
|
/** 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(
|
2022-12-20 12:32:24 +00:00
|
|
|
const char* path,
|
2024-03-25 18:48:18 +00:00
|
|
|
const void* data,
|
|
|
|
size_t size,
|
2022-12-20 12:32:24 +00:00
|
|
|
uint8_t magic,
|
2024-03-25 18:48:18 +00:00
|
|
|
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,
|
2022-12-20 12:32:24 +00:00
|
|
|
size_t* payload_size);
|
|
|
|
|
2022-09-14 16:11:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|