diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-09 13:40:36 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-09 20:36:39 +0000 |
commit | c8697ccc20e12b0f4a2394c10f01ce147eeca269 (patch) | |
tree | 88a2fbf4455b9fdfc58d15865340b1a184191483 /toxcore/state.h | |
parent | 751d0948abfd69629d32fabb1f505ff7ad7fb078 (diff) |
Move `load_state` and its helper functions to their own module.
Diffstat (limited to 'toxcore/state.h')
-rw-r--r-- | toxcore/state.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/toxcore/state.h b/toxcore/state.h new file mode 100644 index 00000000..3f7ff043 --- /dev/null +++ b/toxcore/state.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /** | ||
2 | * The state module is responsible for parsing the Tox save data format and for | ||
3 | * saving state in that format. | ||
4 | * | ||
5 | * This module provides functions for iterating over serialised data sections | ||
6 | * and reading/writing numbers in the correct format (little endian). | ||
7 | * | ||
8 | * Note that unlike the Tox network protocol, the save data stores its values in | ||
9 | * little endian, which is native to most desktop and server architectures in | ||
10 | * 2018. | ||
11 | */ | ||
12 | #ifndef C_TOXCORE_TOXCORE_STATE_H | ||
13 | #define C_TOXCORE_TOXCORE_STATE_H | ||
14 | |||
15 | #include "logger.h" | ||
16 | |||
17 | #ifdef __cplusplus | ||
18 | extern "C" { | ||
19 | #endif | ||
20 | |||
21 | // Returned by the state_load_cb to instruct the loader on what to do next. | ||
22 | typedef enum State_Load_Status { | ||
23 | // Continue loading state data sections. | ||
24 | STATE_LOAD_STATUS_CONTINUE, | ||
25 | // An error occurred. Stop loading sections. | ||
26 | STATE_LOAD_STATUS_ERROR, | ||
27 | // We're at the end of the save data, terminate loading successfully. | ||
28 | STATE_LOAD_STATUS_END, | ||
29 | } State_Load_Status; | ||
30 | |||
31 | typedef State_Load_Status state_load_cb(void *outer, const uint8_t *data, uint32_t len, uint16_t type); | ||
32 | |||
33 | // state load/save | ||
34 | int state_load(const Logger *log, state_load_cb *state_load_callback, void *outer, | ||
35 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); | ||
36 | |||
37 | // Utilities for state data serialisation. | ||
38 | |||
39 | uint16_t lendian_to_host16(uint16_t lendian); | ||
40 | #define host_tolendian16(x) lendian_to_host16(x) | ||
41 | |||
42 | void host_to_lendian32(uint8_t *dest, uint32_t num); | ||
43 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian); | ||
44 | |||
45 | #ifdef __cplusplus | ||
46 | } // extern "C" | ||
47 | #endif | ||
48 | |||
49 | #endif // C_TOXCORE_TOXCORE_STATE_H | ||