GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
C structure to JSON serializer and deserializer. More...
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <utils/gp_json_common.h>
Go to the source code of this file.
Data Structures | |
struct | gp_json_int_limits |
Serializer and deserializer integer limits. More... | |
struct | gp_json_float_limits |
Serializer and deserializer floating point limits. More... | |
struct | gp_json_struct |
Describe a single structure member for serializer and deserialzer. More... | |
Macros | |
#define | GP_JSON_SERDES_STR_CPY(struct, memb, flags, size, ...) |
Defines a string array. | |
#define | GP_JSON_SERDES_STR_DUP(struct, memb, flags, max_size, ...) |
Defines a string pointer. | |
#define | GP_JSON_SERDES_INT(struct, memb, flags, min, max, ...) |
Defines an integer. | |
#define | GP_JSON_SERDES_UINT(struct, memb, flags, min, max, ...) |
Defines an unsigned integer. | |
#define | GP_JSON_SERDES_LONG(struct, memb, flags, min, max, ...) |
Defines a long integer. | |
#define | GP_JSON_SERDES_ULONG(struct, memb, flags, min, max, ...) |
Defines an unsigned long integer. | |
#define | GP_JSON_SERDES_LLONG(struct, memb, flags, min, max, ...) |
Defines a long long integer. | |
#define | GP_JSON_SERDES_ULLONG(struct, memb, flags, min, max, ...) |
Defines an unsigned long long integer. | |
#define | GP_JSON_SERDES_INT8(struct, memb, flags, min, max, ...) |
Defines a 8-bit integer. | |
#define | GP_JSON_SERDES_UINT8(struct, memb, flags, min, max, ...) |
Defines an unsigned 8-bit integer. | |
#define | GP_JSON_SERDES_INT16(struct, memb, flags, min, max, ...) |
Defines a 16-bit integer. | |
#define | GP_JSON_SERDES_UINT16(struct, memb, flags, min, max, ...) |
Defines an unsigned 16-bit integer. | |
#define | GP_JSON_SERDES_BOOL(struct, memb, flags, ...) |
Defines an bool. | |
Typedefs | |
typedef struct gp_json_struct | gp_json_struct |
Describe a single structure member for serializer and deserialzer. | |
Enumerations | |
enum | json_serdes_type { } |
Value types, the complete type is determinted by both value and size. More... | |
Functions | |
int | gp_json_read_struct (gp_json_reader *json, gp_json_val *val, const gp_json_struct *desc, void *baseptr) |
Deserializes a JSON object into a C structure. | |
int | gp_json_load_struct (const char *path, const gp_json_struct *desc, void *baseptr) |
Deserializes a JSON object into a C structure. | |
int | gp_json_write_struct (gp_json_writer *json, const gp_json_struct *desc, const char *id, void *baseptr) |
Serializes a C structure into a JSON object. | |
int | gp_json_save_struct (const char *path, const gp_json_struct *desc, void *baseptr) |
Serializes a C structure to JSON and saves the result into a file. | |
C structure to JSON serializer and deserializer.
How to read a C struct from a JSON file:
Definition in file gp_json_serdes.h.
#define GP_JSON_SERDES_BOOL | ( | struct, | |
memb, | |||
flags, | |||
... | |||
) |
Defines an bool.
The memb has to be an bool type.
struct | A structure type. |
memb | An bool member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 576 of file gp_json_serdes.h.
#define GP_JSON_SERDES_INT | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines an integer.
The memb has to be an int type.
struct | A structure type. |
memb | An integer member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass INT_MIN for full range. |
max | An upper limit, pass INT_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 197 of file gp_json_serdes.h.
#define GP_JSON_SERDES_INT16 | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines a 16-bit integer.
The memb has to be an int16_t type.
struct | A structure type. |
memb | An int16_t member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass INT16_MIN for full range. |
max | An upper limit, pass INT16_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 469 of file gp_json_serdes.h.
#define GP_JSON_SERDES_INT8 | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines a 8-bit integer.
The memb has to be an int8_t type.
struct | A structure type. |
memb | An int8_t member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass INT8_MIN for full range. |
max | An upper limit, pass INT8_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 401 of file gp_json_serdes.h.
#define GP_JSON_SERDES_LLONG | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines a long long integer.
The memb has to be a long long type.
struct | A structure type. |
memb | A long long integer member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass LLONG_MIN for full range. |
max | An upper limit, pass LLONG_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 333 of file gp_json_serdes.h.
#define GP_JSON_SERDES_LONG | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines a long integer.
The memb has to be a long type.
struct | A structure type. |
memb | A long integer member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass LONG_MIN for full range. |
max | An upper limit, pass LONG_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 265 of file gp_json_serdes.h.
#define GP_JSON_SERDES_STR_CPY | ( | struct, | |
memb, | |||
flags, | |||
size, | |||
... | |||
) |
Defines a string array.
The memb has to be a fixed size char array.
struct | A structure type. |
memb | A fixed size char array member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
size | The array size. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 131 of file gp_json_serdes.h.
#define GP_JSON_SERDES_STR_DUP | ( | struct, | |
memb, | |||
flags, | |||
max_size, | |||
... | |||
) |
Defines a string pointer.
The memb has to be a char * pointer. The string is allocated with strdup() and has to be later freed with free().
struct | A structure type. |
memb | A char * member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
max_size | The maximal string size. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 164 of file gp_json_serdes.h.
#define GP_JSON_SERDES_UINT | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines an unsigned integer.
The memb has to be an unsigned int type.
struct | A structure type. |
memb | An unsigned integer member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass 0 for full range. |
max | An upper limit, pass UINT_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 231 of file gp_json_serdes.h.
#define GP_JSON_SERDES_UINT16 | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines an unsigned 16-bit integer.
The memb has to be an uint16_t type.
struct | A structure type. |
memb | An uint16_t member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass 0 for full range. |
max | An upper limit, pass UINT16_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 503 of file gp_json_serdes.h.
#define GP_JSON_SERDES_UINT8 | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines an unsigned 8-bit integer.
The memb has to be an uint8_t type.
struct | A structure type. |
memb | An uint8_t member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass 0 for full range. |
max | An upper limit, pass UINT8_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 435 of file gp_json_serdes.h.
#define GP_JSON_SERDES_ULLONG | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines an unsigned long long integer.
The memb has to be an unsigned long long type.
struct | A structure type. |
memb | An unsigned long integer member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass 0 for full range. |
max | An upper limit, pass ULLONG_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 367 of file gp_json_serdes.h.
#define GP_JSON_SERDES_ULONG | ( | struct, | |
memb, | |||
flags, | |||
min, | |||
max, | |||
... | |||
) |
Defines an unsigned long integer.
The memb has to be an unsigned long type.
struct | A structure type. |
memb | An unsigned long integer member of the structure. |
flags | Can be GP_JSON_SERDES_OPTIONAL if value does not have to be present. |
min | A lower limit, pass 0 for full range. |
max | An upper limit, pass ULONG_MAX for full range. |
... | Optional JSON id, if not set the member name is used instead. |
Example use:
Definition at line 299 of file gp_json_serdes.h.
typedef struct gp_json_struct gp_json_struct |
Describe a single structure member for serializer and deserialzer.
Serialization and deserialization functions take an array sorted by id of these structures that describe subset of a structure memebers.
The array is usually constructed with the help of the GP_JSON_SERDES_FOO() macros.
enum json_serdes_type |
Value types, the complete type is determinted by both value and size.
Enumerator | |
---|---|
GP_JSON_SERDES_OPTIONAL | If set parameter does not have to be present |
Definition at line 50 of file gp_json_serdes.h.
int gp_json_load_struct | ( | const char * | path, |
const gp_json_struct * | desc, | ||
void * | baseptr | ||
) |
Deserializes a JSON object into a C structure.
This is a simplified interface that loads just a single structure from a file.
path | A path to a file. |
desc | An alphabetically sorted by id and NULL id terminatred array of structure member descriptions. |
baseptr | A pointer to the deserialized C structure. |
int gp_json_read_struct | ( | gp_json_reader * | json, |
gp_json_val * | val, | ||
const gp_json_struct * | desc, | ||
void * | baseptr | ||
) |
Deserializes a JSON object into a C structure.
Consumes and JSON object and deserializes it into a C structure.
This function can be mixed with the rest of the JSON parser functions.
json | A json reader. |
val | A json reader value. |
desc | An alphabetically sorted by id and NULL id terminatred array of structure member descriptions. |
baseptr | A pointer to the deserialized C structure. |
int gp_json_save_struct | ( | const char * | path, |
const gp_json_struct * | desc, | ||
void * | baseptr | ||
) |
Serializes a C structure to JSON and saves the result into a file.
This is a simplified interface that saves just a single structure to a file.
path | A path to a file. |
desc | An alphabetically sorted by id and NULL id terminatred array of structure member descriptions. |
baseptr | A pointer to the serialized C structure. |
int gp_json_write_struct | ( | gp_json_writer * | json, |
const gp_json_struct * | desc, | ||
const char * | id, | ||
void * | baseptr | ||
) |
Serializes a C structure into a JSON object.
This function can be mixed with the rest of the JSON writer functions.
json | A json writer |
desc | An NULL id terminated array of structure member descriptions. |
id | An JSON id for the object, should be NULL if there is no id required in current context, e.g. inside of an JSON array. @baseptr A pointer to the serialized C structure. |