Nyx Node
Loading...
Searching...
No Matches
Collaboration diagram for JSON Dict Object:

Classes

struct  nyx_dict_iter_t
 Struct describing a JSON dict iterator. More...
struct  nyx_dict_t
 Struct describing a JSON dict object. More...

Macros

#define NYX_DICT_ITER(dict)
 Initializes a JSON dict iterator.

Functions

nyx_dict_tnyx_dict_t::nyx_dict_new (void)
 Allocates a new JSON dict object.
void nyx_dict_t::nyx_dict_clear (nyx_dict_t *object)
 Clears the content of the provided JSON dict object.
void nyx_dict_t::nyx_dict_del (nyx_dict_t *object, STR_t key)
 Deletes the entry of the provided key.
bool nyx_dict_t::nyx_dict_iterate (nyx_dict_iter_t *iter, STR_t *key, nyx_object_t **object)
 Iterates over a JSON dict object.
nyx_object_tnyx_dict_t::nyx_dict_get (const nyx_dict_t *object, STR_t key)
 Gets the JSON object of the provided key.
bool nyx_dict_t::nyx_dict_set (nyx_dict_t *object, STR_t key, void *value)
 Sets a JSON object in the provided JSON dict object.
size_t nyx_dict_t::nyx_dict_size (const nyx_dict_t *object)
 Gets the number of items in the provided JSON dict object.
str_t nyx_dict_t::nyx_dict_to_string (const nyx_dict_t *object)
 Returns a string representing the provided JSON dict object.
__NYX_INLINE__ bool nyx_dict_t::nyx_dict_get_boolean (const nyx_dict_t *object, STR_t key)
 Gets a boolean value of the provided key.
__NYX_INLINE__ double nyx_dict_t::nyx_dict_get_number (const nyx_dict_t *dict, STR_t key)
 Gets a number value of the provided key.
__NYX_INLINE__ STR_t nyx_dict_t::nyx_dict_get_string (const nyx_dict_t *dict, STR_t key)
 Gets a text value of the provided key.
__NYX_INLINE__ void nyx_dict_t::nyx_dict_get_buff (const nyx_dict_t *dict, STR_t key, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
 Gets the content of the provided key as a byte buffer.
__NYX_INLINE__ bool nyx_dict_t::nyx_dict_set_boolean (const nyx_dict_t *dict, STR_t key, bool value)
 Sets a boolean value of an existing key holding a boolean.
__NYX_INLINE__ bool nyx_dict_t::nyx_dict_set_number (const nyx_dict_t *dict, STR_t key, double value)
 Sets a number value of an existing key holding a number.
__NYX_INLINE__ bool nyx_dict_t::nyx_dict_set_string (const nyx_dict_t *dict, STR_t key, STR_t value, bool managed)
 Sets a text value of an existing key holding a string.
__NYX_INLINE__ bool nyx_dict_t::nyx_dict_set_buff (const nyx_dict_t *dict, STR_t key, size_t size, BUFF_t buff, bool managed)
 Sets the content of an existing key holding a string from a byte buffer.

Detailed Description

JSON Dict Object.


Class Documentation

◆ nyx_dict_iter_t

struct nyx_dict_iter_t

Struct describing a JSON dict iterator.

Definition at line 1111 of file nyx_node.h.

Public Attributes

size_t idx
 Current zero-based iteration index.
struct nyx_dict_node_s * head
 Next JSON object to visit.

◆ nyx_dict_t

struct nyx_dict_t

Struct describing a JSON dict object.

Public Member Functions

nyx_dict_tnyx_dict_new (void)
 Allocates a new JSON dict object.
void nyx_dict_clear (nyx_dict_t *object)
 Clears the content of the provided JSON dict object.
void nyx_dict_del (nyx_dict_t *object, STR_t key)
 Deletes the entry of the provided key.
bool nyx_dict_iterate (nyx_dict_iter_t *iter, STR_t *key, nyx_object_t **object)
 Iterates over a JSON dict object.
nyx_object_tnyx_dict_get (const nyx_dict_t *object, STR_t key)
 Gets the JSON object of the provided key.
bool nyx_dict_set (nyx_dict_t *object, STR_t key, void *value)
 Sets a JSON object in the provided JSON dict object.
size_t nyx_dict_size (const nyx_dict_t *object)
 Gets the number of items in the provided JSON dict object.
str_t nyx_dict_to_string (const nyx_dict_t *object)
 Returns a string representing the provided JSON dict object.
__NYX_INLINE__ bool nyx_dict_get_boolean (const nyx_dict_t *object, STR_t key)
 Gets a boolean value of the provided key.
__NYX_INLINE__ double nyx_dict_get_number (const nyx_dict_t *dict, STR_t key)
 Gets a number value of the provided key.
__NYX_INLINE__ STR_t nyx_dict_get_string (const nyx_dict_t *dict, STR_t key)
 Gets a text value of the provided key.
__NYX_INLINE__ void nyx_dict_get_buff (const nyx_dict_t *dict, STR_t key, __NYX_NULLABLE__ size_t *result_size, __NYX_NULLABLE__ buff_t *result_buff)
 Gets the content of the provided key as a byte buffer.
__NYX_INLINE__ bool nyx_dict_set_boolean (const nyx_dict_t *dict, STR_t key, bool value)
 Sets a boolean value of an existing key holding a boolean.
__NYX_INLINE__ bool nyx_dict_set_number (const nyx_dict_t *dict, STR_t key, double value)
 Sets a number value of an existing key holding a number.
__NYX_INLINE__ bool nyx_dict_set_string (const nyx_dict_t *dict, STR_t key, STR_t value, bool managed)
 Sets a text value of an existing key holding a string.
__NYX_INLINE__ bool nyx_dict_set_buff (const nyx_dict_t *dict, STR_t key, size_t size, BUFF_t buff, bool managed)
 Sets the content of an existing key holding a string from a byte buffer.

Macro Definition Documentation

◆ NYX_DICT_ITER

#define NYX_DICT_ITER ( dict)
Value:
((nyx_dict_iter_t) {0, ((nyx_dict_t *) (dict))->head})
Struct describing a JSON dict iterator.
Definition nyx_node.h:1112
Struct describing a JSON dict object.

Initializes a JSON dict iterator.

Parameters
dictJSON dict.

Definition at line 1126 of file nyx_node.h.

Function Documentation

◆ nyx_dict_new()

nyx_dict_t * nyx_dict_new ( void )

Allocates a new JSON dict object.

Returns
The new JSON dict object.

Definition at line 20 of file json_dict.c.

◆ nyx_dict_clear()

void nyx_dict_clear ( nyx_dict_t * object)

Clears the content of the provided JSON dict object.

Parameters
objectJSON dict object.

Definition at line 84 of file json_dict.c.

◆ nyx_dict_del()

void nyx_dict_del ( nyx_dict_t * object,
STR_t key )

Deletes the entry of the provided key.

Parameters
objectJSON dict object.
keyKey.

Definition at line 91 of file json_dict.c.

◆ nyx_dict_iterate()

bool nyx_dict_iterate ( nyx_dict_iter_t * iter,
STR_t * key,
nyx_object_t ** object )

Iterates over a JSON dict object.

Parameters
iterDict iterator.
keyPointer to the current element key.
objectPointer to the current JSON object.
Returns
true while elements remain, false otherwise.
STR_t key;
nyx_object_t *object;
for(nyx_dict_iter_t iter = NYX_DICT_ITER(dict); nyx_dict_iterate(&iter, &key, &object);)
{
...
}
bool nyx_dict_iterate(nyx_dict_iter_t *iter, STR_t *key, nyx_object_t **object)
Iterates over a JSON dict object.
Definition json_dict.c:136
#define NYX_DICT_ITER(dict)
Initializes a JSON dict iterator.
Definition nyx_node.h:1126
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
Struct describing a JSON object.

Definition at line 136 of file json_dict.c.

◆ nyx_dict_get()

nyx_object_t * nyx_dict_get ( const nyx_dict_t * object,
STR_t key )

Gets the JSON object of the provided key.

Parameters
objectJSON dict object.
keyKey.
Returns
The JSON object or NULL.

Definition at line 159 of file json_dict.c.

◆ nyx_dict_set()

bool nyx_dict_set ( nyx_dict_t * object,
STR_t key,
void * value )

Sets a JSON object in the provided JSON dict object.

Parameters
objectJSON dict object.
keyKey.
valueJSON object to be added.
Returns
true if the value was modified, false otherwise.

Definition at line 178 of file json_dict.c.

◆ nyx_dict_size()

size_t nyx_dict_size ( const nyx_dict_t * object)

Gets the number of items in the provided JSON dict object.

Parameters
objectJSON dict object.
Returns
The number of items in the provided JSON dict object.

Definition at line 260 of file json_dict.c.

◆ nyx_dict_to_string()

str_t nyx_dict_to_string ( const nyx_dict_t * object)

Returns a string representing the provided JSON dict object.

Parameters
objectJSON dict object.
Returns
A newly allocated string that represents the provided JSON dict object.
Note
Must be freed with nyx_memory_free.

Definition at line 275 of file json_dict.c.

◆ nyx_dict_get_boolean()

__NYX_INLINE__ bool nyx_dict_get_boolean ( const nyx_dict_t * object,
STR_t key )

Gets a boolean value of the provided key.

Parameters
objectJSON dict object.
keyKey.
Returns
The related boolean value or false if absent or wrong type.

Definition at line 1261 of file nyx_node.h.

◆ nyx_dict_get_number()

__NYX_INLINE__ double nyx_dict_get_number ( const nyx_dict_t * dict,
STR_t key )

Gets a number value of the provided key.

Parameters
dictJSON dict object.
keyKey.
Returns
The related number value or NaN if absent or wrong type.

Definition at line 1280 of file nyx_node.h.

◆ nyx_dict_get_string()

__NYX_INLINE__ STR_t nyx_dict_get_string ( const nyx_dict_t * dict,
STR_t key )

Gets a text value of the provided key.

Parameters
dictJSON dict object.
keyKey.
Returns
The related text value or NULL if absent or wrong type.
Note
The returned text value remains valid until the related string object is modified or released.

Definition at line 1300 of file nyx_node.h.

◆ nyx_dict_get_buff()

__NYX_INLINE__ void nyx_dict_get_buff ( const nyx_dict_t * dict,
STR_t key,
__NYX_NULLABLE__ size_t * result_size,
__NYX_NULLABLE__ buff_t * result_buff )

Gets the content of the provided key as a byte buffer.

Parameters
dictJSON dict object.
keyKey.
result_sizePointer receiving the number of content bytes.
result_buffPointer receiving the content buffer.
Note
The returned buffer remains valid until the related string object is modified or released.

Definition at line 1321 of file nyx_node.h.

◆ nyx_dict_set_boolean()

__NYX_INLINE__ bool nyx_dict_set_boolean ( const nyx_dict_t * dict,
STR_t key,
bool value )

Sets a boolean value of an existing key holding a boolean.

Parameters
dictJSON dict object.
keyKey.
valueBoolean value to set.
Returns
true if the value was modified, false otherwise.

Definition at line 1339 of file nyx_node.h.

◆ nyx_dict_set_number()

__NYX_INLINE__ bool nyx_dict_set_number ( const nyx_dict_t * dict,
STR_t key,
double value )

Sets a number value of an existing key holding a number.

Parameters
dictJSON dict object.
keyKey.
valueNumber value to set.
Returns
true if the value was modified, false otherwise.

Definition at line 1359 of file nyx_node.h.

◆ nyx_dict_set_string()

__NYX_INLINE__ bool nyx_dict_set_string ( const nyx_dict_t * dict,
STR_t key,
STR_t value,
bool managed )

Sets a text value of an existing key holding a string.

Parameters
dictJSON dict object.
keyKey.
valueText value to set.
managedIf true, ownership of the provided value is transferred to the object.
Returns
true if the value was modified, false otherwise.

Definition at line 1380 of file nyx_node.h.

◆ nyx_dict_set_buff()

__NYX_INLINE__ bool nyx_dict_set_buff ( const nyx_dict_t * dict,
STR_t key,
size_t size,
BUFF_t buff,
bool managed )

Sets the content of an existing key holding a string from a byte buffer.

Parameters
dictJSON dict object.
keyKey.
sizeNumber of content bytes.
buffContent buffer.
managedIf true, ownership of the provided buffer is transferred to the object.
Returns
true if the value was modified, false otherwise.

Definition at line 1402 of file nyx_node.h.