Flipper File Format helper library. More...
Go to the source code of this file.
Typedefs | |
typedef struct FlipperFormat | FlipperFormat |
Functions | |
FlipperFormat * | flipper_format_string_alloc (void) |
Allocate FlipperFormat as string. | |
FlipperFormat * | flipper_format_file_alloc (Storage *storage) |
Allocate FlipperFormat as file. | |
FlipperFormat * | flipper_format_buffered_file_alloc (Storage *storage) |
Allocate FlipperFormat as file, buffered mode. | |
bool | flipper_format_file_open_existing (FlipperFormat *flipper_format, const char *path) |
Open existing file. | |
bool | flipper_format_buffered_file_open_existing (FlipperFormat *flipper_format, const char *path) |
Open existing file, buffered mode. | |
bool | flipper_format_file_open_append (FlipperFormat *flipper_format, const char *path) |
Open existing file for writing and add values to the end of file. | |
bool | flipper_format_file_open_always (FlipperFormat *flipper_format, const char *path) |
Open file. | |
bool | flipper_format_buffered_file_open_always (FlipperFormat *flipper_format, const char *path) |
Open file. | |
bool | flipper_format_file_open_new (FlipperFormat *flipper_format, const char *path) |
Open file. | |
bool | flipper_format_file_close (FlipperFormat *flipper_format) |
Closes the file, use only if FlipperFormat allocated as a file. | |
bool | flipper_format_buffered_file_close (FlipperFormat *flipper_format) |
Closes the file, use only if FlipperFormat allocated as a buffered file. | |
void | flipper_format_free (FlipperFormat *flipper_format) |
Free FlipperFormat. | |
void | flipper_format_set_strict_mode (FlipperFormat *flipper_format, bool strict_mode) |
Set FlipperFormat mode. | |
bool | flipper_format_rewind (FlipperFormat *flipper_format) |
Rewind the RW pointer. | |
bool | flipper_format_seek_to_end (FlipperFormat *flipper_format) |
Move the RW pointer at the end. | |
bool | flipper_format_key_exist (FlipperFormat *flipper_format, const char *key) |
Check if the key exists. | |
bool | flipper_format_read_header (FlipperFormat *flipper_format, FuriString *filetype, uint32_t *version) |
Read the header (file type and version). | |
bool | flipper_format_write_header (FlipperFormat *flipper_format, FuriString *filetype, const uint32_t version) |
Write the header (file type and version). | |
bool | flipper_format_write_header_cstr (FlipperFormat *flipper_format, const char *filetype, const uint32_t version) |
Write the header (file type and version). | |
bool | flipper_format_get_value_count (FlipperFormat *flipper_format, const char *key, uint32_t *count) |
Get the count of values by key. | |
bool | flipper_format_read_string (FlipperFormat *flipper_format, const char *key, FuriString *data) |
Read a string by key. | |
bool | flipper_format_write_string (FlipperFormat *flipper_format, const char *key, FuriString *data) |
Write key and string. | |
bool | flipper_format_write_string_cstr (FlipperFormat *flipper_format, const char *key, const char *data) |
Write key and string. | |
bool | flipper_format_read_hex_uint64 (FlipperFormat *flipper_format, const char *key, uint64_t *data, const uint16_t data_size) |
Read array of uint64 in hex format by key. | |
bool | flipper_format_write_hex_uint64 (FlipperFormat *flipper_format, const char *key, const uint64_t *data, const uint16_t data_size) |
Write key and array of uint64 in hex format. | |
bool | flipper_format_read_uint32 (FlipperFormat *flipper_format, const char *key, uint32_t *data, const uint16_t data_size) |
Read array of uint32 by key. | |
bool | flipper_format_write_uint32 (FlipperFormat *flipper_format, const char *key, const uint32_t *data, const uint16_t data_size) |
Write key and array of uint32. | |
bool | flipper_format_read_int32 (FlipperFormat *flipper_format, const char *key, int32_t *data, const uint16_t data_size) |
Read array of int32 by key. | |
bool | flipper_format_write_int32 (FlipperFormat *flipper_format, const char *key, const int32_t *data, const uint16_t data_size) |
Write key and array of int32. | |
bool | flipper_format_read_bool (FlipperFormat *flipper_format, const char *key, bool *data, const uint16_t data_size) |
Read array of bool by key. | |
bool | flipper_format_write_bool (FlipperFormat *flipper_format, const char *key, const bool *data, const uint16_t data_size) |
Write key and array of bool. | |
bool | flipper_format_read_float (FlipperFormat *flipper_format, const char *key, float *data, const uint16_t data_size) |
Read array of float by key. | |
bool | flipper_format_write_float (FlipperFormat *flipper_format, const char *key, const float *data, const uint16_t data_size) |
Write key and array of float. | |
bool | flipper_format_read_hex (FlipperFormat *flipper_format, const char *key, uint8_t *data, const uint16_t data_size) |
Read array of hex-formatted bytes by key. | |
bool | flipper_format_write_hex (FlipperFormat *flipper_format, const char *key, const uint8_t *data, const uint16_t data_size) |
Write key and array of hex-formatted bytes. | |
bool | flipper_format_write_comment (FlipperFormat *flipper_format, FuriString *data) |
Write comment. | |
bool | flipper_format_write_comment_cstr (FlipperFormat *flipper_format, const char *data) |
Write comment. | |
bool | flipper_format_delete_key (FlipperFormat *flipper_format, const char *key) |
Removes the first matching key and its value. | |
bool | flipper_format_update_string (FlipperFormat *flipper_format, const char *key, FuriString *data) |
Updates the value of the first matching key to a string value. | |
bool | flipper_format_update_string_cstr (FlipperFormat *flipper_format, const char *key, const char *data) |
Updates the value of the first matching key to a string value. | |
bool | flipper_format_update_uint32 (FlipperFormat *flipper_format, const char *key, const uint32_t *data, const uint16_t data_size) |
Updates the value of the first matching key to a uint32 array value. | |
bool | flipper_format_update_int32 (FlipperFormat *flipper_format, const char *key, const int32_t *data, const uint16_t data_size) |
Updates the value of the first matching key to a int32 array value. | |
bool | flipper_format_update_bool (FlipperFormat *flipper_format, const char *key, const bool *data, const uint16_t data_size) |
Updates the value of the first matching key to a bool array value. | |
bool | flipper_format_update_float (FlipperFormat *flipper_format, const char *key, const float *data, const uint16_t data_size) |
Updates the value of the first matching key to a float array value. | |
bool | flipper_format_update_hex (FlipperFormat *flipper_format, const char *key, const uint8_t *data, const uint16_t data_size) |
Updates the value of the first matching key to an array of hex-formatted bytes. | |
bool | flipper_format_insert_or_update_string (FlipperFormat *flipper_format, const char *key, FuriString *data) |
Updates the value of the first matching key to a string value, or adds the key and value if the key did not exist. | |
bool | flipper_format_insert_or_update_string_cstr (FlipperFormat *flipper_format, const char *key, const char *data) |
Updates the value of the first matching key to a string value, or adds the key and value if the key did not exist. | |
bool | flipper_format_insert_or_update_uint32 (FlipperFormat *flipper_format, const char *key, const uint32_t *data, const uint16_t data_size) |
Updates the value of the first matching key to a uint32 array value, or adds the key and value if the key did not exist. | |
bool | flipper_format_insert_or_update_int32 (FlipperFormat *flipper_format, const char *key, const int32_t *data, const uint16_t data_size) |
Updates the value of the first matching key to a int32 array value, or adds the key and value if the key did not exist. | |
bool | flipper_format_insert_or_update_bool (FlipperFormat *flipper_format, const char *key, const bool *data, const uint16_t data_size) |
Updates the value of the first matching key to a bool array value, or adds the key and value if the key did not exist. | |
bool | flipper_format_insert_or_update_float (FlipperFormat *flipper_format, const char *key, const float *data, const uint16_t data_size) |
Updates the value of the first matching key to a float array value, or adds the key and value if the key did not exist. | |
bool | flipper_format_insert_or_update_hex (FlipperFormat *flipper_format, const char *key, const uint8_t *data, const uint16_t data_size) |
Updates the value of the first matching key to an array of hex-formatted bytes, or adds the key and value if the key did not exist. | |
Flipper File Format helper library.
Flipper File Format is a fairly simple format for storing data in a file.
Flipper file structure:
Lines starting with the # character are ignored (considered as comments). The separator between the name of the value and the value itself is the string ": ".
Currently supported types:
End of line is LF when writing, but CR is supported when reading.
The library is designed in such a way that comments and field values are completely ignored when searching for keys, that is, they do not consume memory.
File example:
Writing:
Reading:
FlipperFormat * flipper_format_buffered_file_alloc | ( | Storage * | storage | ) |
Allocate FlipperFormat as file, buffered mode.
storage | The storage |
bool flipper_format_buffered_file_close | ( | FlipperFormat * | flipper_format | ) |
Closes the file, use only if FlipperFormat allocated as a buffered file.
flipper_format | The flipper format |
bool flipper_format_buffered_file_open_always | ( | FlipperFormat * | flipper_format, |
const char * | path ) |
Open file.
Creates a new file, or deletes the contents of the file if it already exists, buffered mode. Use only if FlipperFormat allocated as a buffered file.
flipper_format | Pointer to a FlipperFormat instance |
path | File path |
bool flipper_format_buffered_file_open_existing | ( | FlipperFormat * | flipper_format, |
const char * | path ) |
Open existing file, buffered mode.
Use only if FlipperFormat allocated as a buffered file.
flipper_format | Pointer to a FlipperFormat instance |
path | File path |
bool flipper_format_delete_key | ( | FlipperFormat * | flipper_format, |
const char * | key ) |
Removes the first matching key and its value.
Sets the RW pointer to a position of deleted data.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
FlipperFormat * flipper_format_file_alloc | ( | Storage * | storage | ) |
Allocate FlipperFormat as file.
storage | The storage |
bool flipper_format_file_close | ( | FlipperFormat * | flipper_format | ) |
Closes the file, use only if FlipperFormat allocated as a file.
flipper_format | The flipper format |
bool flipper_format_file_open_always | ( | FlipperFormat * | flipper_format, |
const char * | path ) |
Open file.
Creates a new file, or deletes the contents of the file if it already exists. Use only if FlipperFormat allocated as a file.
flipper_format | Pointer to a FlipperFormat instance |
path | File path |
bool flipper_format_file_open_append | ( | FlipperFormat * | flipper_format, |
const char * | path ) |
Open existing file for writing and add values to the end of file.
Use only if FlipperFormat allocated as a file.
flipper_format | Pointer to a FlipperFormat instance |
path | File path |
bool flipper_format_file_open_existing | ( | FlipperFormat * | flipper_format, |
const char * | path ) |
Open existing file.
Use only if FlipperFormat allocated as a file.
flipper_format | Pointer to a FlipperFormat instance |
path | File path |
bool flipper_format_file_open_new | ( | FlipperFormat * | flipper_format, |
const char * | path ) |
Open file.
Creates a new file, fails if file already exists. Use only if FlipperFormat allocated as a file.
flipper_format | Pointer to a FlipperFormat instance |
path | File path |
void flipper_format_free | ( | FlipperFormat * | flipper_format | ) |
Free FlipperFormat.
flipper_format | Pointer to a FlipperFormat instance |
bool flipper_format_get_value_count | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
uint32_t * | count ) |
Get the count of values by key.
flipper_format | Pointer to a FlipperFormat instance |
key | The key |
count | The count |
bool flipper_format_insert_or_update_bool | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const bool * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a bool array value, or adds the key and value if the key did not exist.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_insert_or_update_float | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const float * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a float array value, or adds the key and value if the key did not exist.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_insert_or_update_hex | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint8_t * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to an array of hex-formatted bytes, or adds the key and value if the key did not exist.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_insert_or_update_int32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const int32_t * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a int32 array value, or adds the key and value if the key did not exist.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_insert_or_update_string | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
FuriString * | data ) |
Updates the value of the first matching key to a string value, or adds the key and value if the key did not exist.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_insert_or_update_string_cstr | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const char * | data ) |
Updates the value of the first matching key to a string value, or adds the key and value if the key did not exist.
Plain C version. Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_insert_or_update_uint32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint32_t * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a uint32 array value, or adds the key and value if the key did not exist.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_key_exist | ( | FlipperFormat * | flipper_format, |
const char * | key ) |
Check if the key exists.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
bool flipper_format_read_bool | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
bool * | data, | ||
const uint16_t | data_size ) |
Read array of bool by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_read_float | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
float * | data, | ||
const uint16_t | data_size ) |
Read array of float by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_read_header | ( | FlipperFormat * | flipper_format, |
FuriString * | filetype, | ||
uint32_t * | version ) |
Read the header (file type and version).
flipper_format | Pointer to a FlipperFormat instance |
filetype | File type string |
version | Version Value |
bool flipper_format_read_hex | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
uint8_t * | data, | ||
const uint16_t | data_size ) |
Read array of hex-formatted bytes by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_read_hex_uint64 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
uint64_t * | data, | ||
const uint16_t | data_size ) |
Read array of uint64 in hex format by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_read_int32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
int32_t * | data, | ||
const uint16_t | data_size ) |
Read array of int32 by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_read_string | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
FuriString * | data ) |
Read a string by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_read_uint32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
uint32_t * | data, | ||
const uint16_t | data_size ) |
Read array of uint32 by key.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_rewind | ( | FlipperFormat * | flipper_format | ) |
Rewind the RW pointer.
flipper_format | Pointer to a FlipperFormat instance |
bool flipper_format_seek_to_end | ( | FlipperFormat * | flipper_format | ) |
Move the RW pointer at the end.
Can be useful if you want to add some data after reading.
flipper_format | Pointer to a FlipperFormat instance |
void flipper_format_set_strict_mode | ( | FlipperFormat * | flipper_format, |
bool | strict_mode ) |
Set FlipperFormat mode.
flipper_format | Pointer to a FlipperFormat instance |
strict_mode | True obligates not to skip valid fields. False by default. |
FlipperFormat * flipper_format_string_alloc | ( | void | ) |
Allocate FlipperFormat as string.
bool flipper_format_update_bool | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const bool * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a bool array value.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_update_float | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const float * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a float array value.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_update_hex | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint8_t * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to an array of hex-formatted bytes.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_update_int32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const int32_t * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a int32 array value.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_update_string | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
FuriString * | data ) |
Updates the value of the first matching key to a string value.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_update_string_cstr | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const char * | data ) |
Updates the value of the first matching key to a string value.
Plain C version. Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_update_uint32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint32_t * | data, | ||
const uint16_t | data_size ) |
Updates the value of the first matching key to a uint32 array value.
Sets the RW pointer to a position at the end of inserted data.
flipper_format | Pointer to a FlipperFormat instance | |
key | Key | |
data | Value | |
[in] | data_size | The data size |
bool flipper_format_write_bool | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const bool * | data, | ||
const uint16_t | data_size ) |
Write key and array of bool.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_write_comment | ( | FlipperFormat * | flipper_format, |
FuriString * | data ) |
Write comment.
flipper_format | Pointer to a FlipperFormat instance |
data | Comment text |
bool flipper_format_write_comment_cstr | ( | FlipperFormat * | flipper_format, |
const char * | data ) |
Write comment.
Plain C string version.
flipper_format | Pointer to a FlipperFormat instance |
data | Comment text |
bool flipper_format_write_float | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const float * | data, | ||
const uint16_t | data_size ) |
Write key and array of float.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_write_header | ( | FlipperFormat * | flipper_format, |
FuriString * | filetype, | ||
const uint32_t | version ) |
Write the header (file type and version).
flipper_format | Pointer to a FlipperFormat instance |
filetype | File type string |
version | Version Value |
bool flipper_format_write_header_cstr | ( | FlipperFormat * | flipper_format, |
const char * | filetype, | ||
const uint32_t | version ) |
Write the header (file type and version).
Plain C string version.
flipper_format | Pointer to a FlipperFormat instance |
filetype | File type string |
version | Version Value |
bool flipper_format_write_hex | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint8_t * | data, | ||
const uint16_t | data_size ) |
Write key and array of hex-formatted bytes.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_write_hex_uint64 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint64_t * | data, | ||
const uint16_t | data_size ) |
Write key and array of uint64 in hex format.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_write_int32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const int32_t * | data, | ||
const uint16_t | data_size ) |
Write key and array of int32.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |
bool flipper_format_write_string | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
FuriString * | data ) |
Write key and string.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_write_string_cstr | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const char * | data ) |
Write key and string.
Plain C string version.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
bool flipper_format_write_uint32 | ( | FlipperFormat * | flipper_format, |
const char * | key, | ||
const uint32_t * | data, | ||
const uint16_t | data_size ) |
Write key and array of uint32.
flipper_format | Pointer to a FlipperFormat instance |
key | Key |
data | Value |
data_size | Values count |