|
Anjay Lite
|
Persistence API for storing and restoring Anjay Lite state. More...
Go to the source code of this file.
Data Structures | |
| struct | anj_persistence_context_t |
Macros | |
| #define | ANJ_PERSISTENCE_MAGIC_MAX_SIZE 16 |
Typedefs | |
| typedef int | anj_persistence_read_cb_t(void *ctx, void *buf, size_t size) |
| typedef int | anj_persistence_write_cb_t(void *ctx, const void *buf, size_t size) |
Enumerations | |
| enum | anj_persistence_direction_t { ANJ_PERSISTENCE_STORE = 0 , ANJ_PERSISTENCE_RESTORE } |
Persistence API for storing and restoring Anjay Lite state.
Provides a generic context/stream abstraction with read/write callbacks. Used by higher-level modules to serialize internal state, security information, or application data to a platform-specific medium.
Supports storing/restoring primitive types, strings, fixed-size buffers, and validating blobs with “magic” tags.
| #define ANJ_PERSISTENCE_MAGIC_MAX_SIZE 16 |
Maximum number of bytes accepted by anj_persistence_magic() as the “magic” tag used to identify a blob format/version.
| typedef int anj_persistence_read_cb_t(void *ctx, void *buf, size_t size) |
Read callback type. Implementations must read exactly size bytes into buf.
| ctx | User context provided at context creation. | |
| [out] | buf | Destination buffer. |
| size | Number of bytes to read. |
| typedef int anj_persistence_write_cb_t(void *ctx, const void *buf, size_t size) |
Write callback type. Implementations must write exactly size bytes from buf.
| ctx | User context provided at context creation. |
| buf | Source buffer. |
| size | Number of bytes to write. |
|
inlinestatic |
Stores/restores a boolean value.
| int anj_persistence_bytes | ( | const anj_persistence_context_t * | ctx, |
| void * | inout_buffer, | ||
| size_t | buffer_size | ||
| ) |
Stores or restores a fixed-size byte buffer.
buffer_size bytes from inout_buffer.buffer_size bytes into inout_buffer.| ctx | Persistence context. | |
| [in,out] | inout_buffer | Buffer to write or fill. |
| buffer_size | Number of bytes to transfer. |
|
inlinestatic |
Returns the direction of the persistence context.
|
inlinestatic |
Stores/restores a signed 16-bit value.
|
inlinestatic |
Stores/restores a signed 32-bit value.
|
inlinestatic |
Stores/restores a signed 64-bit value.
|
inlinestatic |
Stores/restores a signed 8-bit value.
| int anj_persistence_magic | ( | const anj_persistence_context_t * | ctx, |
| const void * | magic, | ||
| size_t | magic_size | ||
| ) |
Writes or verifies a “magic” tag.
magic of size magic_size.magic_size bytes and verifies they are identical to magic.Typical use is to guard persisted blobs with a short prefix describing the expected format/version.
| ctx | Persistence context. |
| magic | Pointer to expected/actual magic bytes. |
| magic_size | Number of bytes (<= ANJ_PERSISTENCE_MAGIC_MAX_SIZE). |
| anj_persistence_context_t anj_persistence_restore_context_create | ( | anj_persistence_read_cb_t * | read_cb, |
| void * | ctx | ||
| ) |
Creates a persistence context for restoring data.
| read_cb | Callback to use for reading data. |
| ctx | User context passed to the read callback. |
| anj_persistence_context_t anj_persistence_store_context_create | ( | anj_persistence_write_cb_t * | write_cb, |
| void * | ctx | ||
| ) |
Creates a persistence context for storing data.
| write_cb | Callback to use for writing data. |
| ctx | User context passed to the write callback. |
| int anj_persistence_string | ( | const anj_persistence_context_t * | ctx, |
| char * | inout_str, | ||
| size_t | out_max_size | ||
| ) |
Stores or restores a NUL-terminated string.
inout_str excluding the terminating NUL byte, and its length as a 64-bit unsigned integer.inout_str, writing at most out_max_size bytes (including the terminator). The result is guaranteed to be NUL-terminated if the call succeeds.| ctx | Persistence context. | |
| [in,out] | inout_str | String to write or destination buffer. |
| out_max_size | Size of inout_str (RESTORE). Ignored in STORE. |
|
inlinestatic |
Stores/restores an unsigned 16-bit value.
|
inlinestatic |
Stores/restores an unsigned 32-bit value.
|
inlinestatic |
Stores/restores an unsigned 64-bit value.
|
inlinestatic |
Stores/restores an unsigned 8-bit value.