Skip to content

Commit 82fee20

Browse files
committed
Add almost all the documentation about the structures and types
1 parent cd041f8 commit 82fee20

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

doc/user_manual.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,82 @@
11
# JSON
22
## JSON types
3+
The JSON standard features a plethora of types, like **strings**, **booleans**, **numbers** (both floating points and integers), and **null**. Moreover, it features some more complex data structures such as **arrays** and **objects**. To accommodate this, cjlib has implemented the following enum, which is used to differentiate between the forenamed types and data structures.
4+
5+
```C
6+
enum cjlib_json_datatypes
7+
{
8+
CJLIB_STRING,
9+
CJLIB_NUMBER,
10+
CJLIB_ARRAY,
11+
CJLIB_BOOLEAN,
12+
CJLIB_OBJECT,
13+
CJLIB_NULL
14+
};
15+
```
16+
17+
The user may use this enum with some other elements that will be discussed in the following sections, to perform various manipulations on the JSON contents.
18+
19+
`File: cjlib.h`
320

421
## JSON structures
22+
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
523

6-
# Errors
24+
```C
25+
struct cjlib_json
26+
{
27+
cjlib_json_fd c_fp; // The file pointer of the json file.
28+
cjlib_json_object *c_dict; // The dictionary that contains the values of the json.
29+
char *c_path; // The path to the respective file.
30+
};
31+
```
32+
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).`
34+
35+
`File: cjlib.h`
36+
37+
# Errors
738

839
## 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.
41+
42+
``` C
43+
enum cjlib_json_error_types
44+
{
45+
NO_ERROR,
46+
UNDEFINED,
47+
INVALID_TYPE,
48+
INVALID_JSON,
49+
DUPLICATE_NAME,
50+
INVALID_PROPERTY,
51+
MISSING_SEPERATOR,
52+
MEMORY_ERROR,
53+
INCOMPLETE_CURLY_BRACKETS,
54+
INCOMPLETE_SQUARE_BRACKETS,
55+
INCOMPLETE_DOUBLE_QUOTES,
56+
MISSING_COMMA,
57+
INVALID_NUMBER
58+
};
59+
60+
```
61+
62+
`File: cjlib_error.h`
963

1064
## Error structure
65+
To help discover the cause of an error and therefore handle it with the appropriate actions, cjlib provides the following structure with as much information as possible for the error that is caused. In some cases, some fields of this structure may be left empty, because the internal function builds the errors while parsing or editing the JSON file. Depending on the state where the error occurred, more or less information may be available about the error.
1166

67+
```C
68+
struct cjlib_json_error
69+
{
70+
char *c_property_name; // The name of the property in which the error occurred.
71+
char *c_property_value; // The value of the property in which the error occurred.
72+
enum cjlib_json_error_types c_error_code; // A error code indicating the error.
73+
};
74+
75+
```
76+
`File: cjlib_error.h`
1277

1378
# Error related functions
79+
Cjlib provides the errors by manipulating an internal (private) variable in the implementation of cjlib_error.c file. This is done to protect it from mistaken actions. To access the private variable that has the information about the error that occurred, the library provides the following functions. Each of the following functions is **thread safe**, as it uses mutex, to allow multiple threads to check for errors (if this is necessary).
1480

1581
___
1682
## cjlib_json_error_init

include/cjlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ enum cjlib_json_datatypes
125125
};
126126

127127
/**
128-
* The json object. !Library user must ignore this!.
128+
* The json object.
129129
*/
130130
struct cjlib_json
131131
{

0 commit comments

Comments
 (0)