|
|
|
@ -35,13 +35,12 @@ extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <stdbool.h> |
|
|
|
|
#include <stdint.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#define json_container_of(ptr, type, member) ({ \ |
|
|
|
|
void *__mptr = (void *)(ptr); \
|
|
|
|
|
((type *)(__mptr - offsetof(type, member))); }) |
|
|
|
|
#define json_containerOf( ptr, type, member ) \ |
|
|
|
|
((type*)( (char*)ptr - offsetof( type, member ) )) |
|
|
|
|
|
|
|
|
|
/** @defgroup tinyJson Tiny JSON parser.
|
|
|
|
|
* @{ */ |
|
|
|
@ -66,13 +65,6 @@ typedef struct json_s { |
|
|
|
|
jsonType_t type; |
|
|
|
|
} json_t; |
|
|
|
|
|
|
|
|
|
/** Structure to handle a heap of JSON properties. */ |
|
|
|
|
typedef struct jsonPool_s jsonPool_t; |
|
|
|
|
typedef struct jsonPool_s { |
|
|
|
|
json_t* (*init) ( jsonPool_t* pool ); |
|
|
|
|
json_t* (*new) ( jsonPool_t* pool ); |
|
|
|
|
} jsonPool_t; |
|
|
|
|
|
|
|
|
|
/** Parse a string to get a json.
|
|
|
|
|
* @param str String pointer with a JSON object. It will be modified. |
|
|
|
|
* @param mem Array of json properties to allocate. |
|
|
|
@ -82,14 +74,6 @@ typedef struct jsonPool_s { |
|
|
|
|
* This property is always unnamed and its type is JSON_OBJ. */ |
|
|
|
|
json_t const* json_create( char* str, json_t mem[], unsigned int qty ); |
|
|
|
|
|
|
|
|
|
/** Parse a string to get a json.
|
|
|
|
|
* @param str String pointer with a JSON object. It will be modified. |
|
|
|
|
* @param pool Custom json pool pointer. |
|
|
|
|
* @retval Null pointer if any was wrong in the parse process. |
|
|
|
|
* @retval If the parser process was successfully a valid handler of a json. |
|
|
|
|
* This property is always unnamed and its type is JSON_OBJ. */ |
|
|
|
|
json_t const* json_create_pool( char* str, jsonPool_t *pool ); |
|
|
|
|
|
|
|
|
|
/** Get the name of a json property.
|
|
|
|
|
* @param json A valid handler of a json property. |
|
|
|
|
* @retval Pointer to null-terminated if property has name. |
|
|
|
@ -156,7 +140,7 @@ static inline bool json_getBoolean( json_t const* property ) { |
|
|
|
|
* @param property A valid handler of a json object. Its type must be JSON_INTEGER. |
|
|
|
|
* @return The value stdint. */ |
|
|
|
|
static inline int64_t json_getInteger( json_t const* property ) { |
|
|
|
|
return (int64_t)atoll( property->u.value ); |
|
|
|
|
return atoll( property->u.value ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Get the value of a json real property.
|
|
|
|
@ -166,6 +150,23 @@ static inline double json_getReal( json_t const* property ) { |
|
|
|
|
return atof( property->u.value ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Structure to handle a heap of JSON properties. */ |
|
|
|
|
typedef struct jsonPool_s jsonPool_t; |
|
|
|
|
struct jsonPool_s { |
|
|
|
|
json_t* (*init)( jsonPool_t* pool ); |
|
|
|
|
json_t* (*new)( jsonPool_t* pool ); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** Parse a string to get a json.
|
|
|
|
|
* @param str String pointer with a JSON object. It will be modified. |
|
|
|
|
* @param pool Custom json pool pointer. |
|
|
|
|
* @retval Null pointer if any was wrong in the parse process. |
|
|
|
|
* @retval If the parser process was successfully a valid handler of a json. |
|
|
|
|
* This property is always unnamed and its type is JSON_OBJ. */ |
|
|
|
|
json_t const* json_createWithPool( char* str, jsonPool_t* pool ); |
|
|
|
|
|
|
|
|
|
/** @ } */ |
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|