Skip to content

Commit d55b9b6

Browse files
committed
Add comments for the json interface
Signed-off-by: Stephen Sun <[email protected]>
1 parent 4d06910 commit d55b9b6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

common/json.h

+39
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,49 @@ namespace swss {
1212
class JSon
1313
{
1414
private:
15+
/*
16+
* el_count represents the number of elements in each object,
17+
* which means each object have exactly 2 elements: the data and the operator
18+
*/
1519
static const int el_count = 2;
1620
public:
1721
static std::string buildJson(const std::vector<FieldValueTuple> &fv);
1822
static void readJson(const std::string &json, std::vector<FieldValueTuple> &fv);
23+
/*
24+
bool loadJsonFromFile(std::ifstream &fs, std::vector<KeyOpFieldsValuesTuple> &db_items);
25+
26+
parse the json file and construct a vector of KeyOpFieldsValuesTuple as the result
27+
the json file should be a list objects with each consisting of a data field and an operator field
28+
- the data should be a dictionary
29+
- the operator field should be a string, "SET" or "DEL"
30+
an example:
31+
[
32+
{
33+
"QOS_TABLE:TC_TO_QUEUE_MAP_TABLE:AZURE": {
34+
"5": "1",
35+
"6": "1"
36+
},
37+
"OP": "SET"
38+
},
39+
{
40+
"QOS_TABLE:DSCP_TO_TC_MAP_TABLE:AZURE": {
41+
"7":"5",
42+
"6":"5",
43+
"3":"3",
44+
"8":"7",
45+
"9":"8"
46+
},
47+
"OP": "SET"
48+
}
49+
]
50+
51+
parameters:
52+
fs: the input ifstream representing the json file
53+
fv: the output vector
54+
return: boolean
55+
True: the input json file has been succefully parsed
56+
False: there are some errors found
57+
*/
1958
static bool loadJsonFromFile(std::ifstream &fs, std::vector<KeyOpFieldsValuesTuple> &db_items);
2059
};
2160

0 commit comments

Comments
 (0)