You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/user_manual.md
+49-2Lines changed: 49 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,8 @@ The user may use this enum with some other elements that will be discussed in th
19
19
`File: cjlib.h`
20
20
21
21
## JSON structures
22
+
23
+
## cjlib_json
22
24
To group all the information required for the JSON to be represented in the memory, cjlib has implemented a structure called **cjlib_json** which is defined as follows
23
25
24
26
```C
@@ -30,14 +32,59 @@ struct cjlib_json
30
32
};
31
33
```
32
34
33
-
`The user should not modify the contents of this structure in the code, as it may break the internal operation of the library, leading to memory leaks and memory corruption. Only the library functions must have the right to modify the contents of this structure. Where it is required, the user may access, it for read purposes only (of course I would like to make the declaration of the structure private, but in this case, it is less flexible and requires more memory allocations and systemcalls, therefore is less efficient in this way).`
35
+
`The user should not modify the contents of this structure in the code, as it may break the internal operation of the library, leading to memory leaks and memory corruption. Only the library functions must have the right to modify the contents of this structure. If it is required, the user may access it for read purposes only (of course I would like to make the declaration of the structure private, but in this case, it is less flexible and requires more memory allocations and systemcalls, therefore is less efficient in this way).`
36
+
37
+
`File: cjlib.h`
38
+
39
+
## cjlib_json_data
40
+
The most important structure for the library user is the **cjlib_json_data** structure. This structure consists of the information needed to save the required data to the internal data structure of the cjlib. The structure is defined as shown below:
41
+
42
+
```C
43
+
struct cjlib_json_data
44
+
{
45
+
union cjlib_json_data_disting c_value; // The data to store/retrieve.
46
+
enum cjlib_json_datatypes c_datatype; // The type of the data.
47
+
};
48
+
```
49
+
50
+
This structure consists of two elements. The first is the **c_value** which represents the JSON data to be saved/retrieved (boolean, number, object, arrays). The second represents the type of data stored in the **c_value** member. The **c_datatype** member will not be discussed further, as the **Json types** section described the available types that could be stored in this member. The member to which the focus will be pointed is the c_value member. As shown in the definition of the structure, this field/member is another built-in data structure of C, which is a union, that helps to distinguish between the available types of the JSON, using only one single and simple data structure. Shown below is the definition of the union that represents the data of the JSON.
51
+
52
+
```C
53
+
union cjlib_json_data_disting
54
+
{
55
+
char *c_str; // string
56
+
cjlib_json_num c_num; // Number
57
+
cjlib_json_bool c_boolean; // Boolean.
58
+
cjlib_json_object *c_obj; // json object.
59
+
void *c_null; // null
60
+
cjlib_json_array *c_arr; // array.
61
+
};
62
+
63
+
```
64
+
65
+
The user may use both the cjlib_json_data structure and the cjlib_json_data_disting union to determine 1) the type of the data that was stored/retrieved from the internal representation of the JSON in the memory and 2) to receive/store the respective value from/in the corresponding field of the union. Following, there is an illustrative example that creates simple data, a number, using the definitions presented here.
66
+
67
+
```C
68
+
#include"cjlib.h"
69
+
70
+
intmain(void) {
71
+
struct cjlib_json_data my_data; // Where the data are stored.
72
+
73
+
my_data.c_datatype = CJLIB_NUMBER; // The type of the data.
74
+
my_data.c_value = 50; // The actual data.
75
+
// store the data in the internal data structure...
76
+
}
77
+
```
78
+
79
+
Further details on how to store/retrieve the data to/from the Internal data structure are described in the following sections.
80
+
34
81
35
82
`File: cjlib.h`
36
83
37
84
# Errors
38
85
39
86
## Error types
40
-
The library provides the user with a plethora of errors for the correct error handling. To do this, it provides the following types of errors that may appear when manipulating JSON files.
87
+
The library provides the user with a plethora of errors for error handling. To do this, it provides the following types of errors that may appear when manipulating JSON files.
0 commit comments