aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorUjjwal Agarwal <ujjwalcoding012@gmail.com>2021-08-16 09:28:27 +0530
committerUjjwal Agarwal <ujjwalcoding012@gmail.com>2021-08-16 09:28:27 +0530
commit9afa5fe2d34ffb0dca6671e7087d17a554e68236 (patch)
tree89924d8193554fec10e703fcb0c9aad917548740 /docs
parente26f08da56be2c1412cdd7e3027a74cb2bd1c047 (diff)
downloadspdx-tools-9afa5fe2d34ffb0dca6671e7087d17a554e68236.tar.gz
Docs : Add docs for jsonparser and jsonsaver
Signed-off-by: Ujjwal Agarwal <ujjwalcoding012@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/jsonloader.md24
-rw-r--r--docs/jsonsaver.md28
2 files changed, 52 insertions, 0 deletions
diff --git a/docs/jsonloader.md b/docs/jsonloader.md
new file mode 100644
index 0000000..047c4b7
--- /dev/null
+++ b/docs/jsonloader.md
@@ -0,0 +1,24 @@
+SPDX-License-Identifier: CC-BY-4.0
+
+## Working
+
+A UnmarshallJSON function on the spdx.Document2_2 struct is defined so that when the JSON is unmarshalled in it the function is called and we can implement the process in a custom way . Then a new map[string]interface{} is deifined which temporarily holds the unmarshalled json . The map is then parsed into the spdx.Document2_2 using functions defined for it’s different sections .
+
+JSON → map[string]interface{} → spdx.Document2_2
+
+## Some Key Points
+
+- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that pacakge . The parses first parses all the files into the Unpackaged files map of the document and then when it parses the packages , it removes the respective files from the unpackaged files map and places it inside the files map of that package .
+
+- The snippets have a property "snippetFromFile" which has the SPDX identiifer of the file to which the snippet is related . Thus the snippets require the files to be parsed before them . Then the snippets are parsed one by one and inserted into the respective files using this property .
+
+
+The json file loader in `package jsonloader` makes the following assumptions:
+
+
+### Order of appearance of the properties
+* The parser does not make any pre-assumptions based on the order in which the properties appear .
+
+
+### Annotations
+* The json spdx schema does not define the SPDX Identifier property for the annotation object . The parser assumes the spdx Identifier of the parent property of the currently being parsed annotation array to be the SPDX Identifer for all the annotation objects of that array. \ No newline at end of file
diff --git a/docs/jsonsaver.md b/docs/jsonsaver.md
new file mode 100644
index 0000000..8531cd3
--- /dev/null
+++ b/docs/jsonsaver.md
@@ -0,0 +1,28 @@
+SPDX-License-Identifier: CC-BY-4.0
+
+## Working
+
+The spdx document is converted to map[string]interface{} and then the entire map is converted to json using a single json Marshall function call . The saver uses a tempoarary storage to store all the files (Paackaged and Unpackaged) together in a single data structure in order to comply with the json schema defined by spdx .
+
+spdx.Document2_2 → map[string]interface{} → JSON
+
+## Some Key Points
+
+- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that pacakge . The saver iterates through the files of a package and inserted all the SPDX Identifiers of the files in the "hasFiles" array . In addition it adds the file to a temporary storage map to store all the files of the entire document at a single place .
+
+- The files require the packages to be saved before them in order to ensure that the packaged files are added to the temporary storage before the files are saved .
+
+- The snippets are saved after the files and a property "snippetFromFile" identifies the file of the snippets.
+
+The json file loader in `package jsonsaver` makes the following assumptions:
+
+
+### Order of appearance of the properties
+* The saver does not make any pre-assumptions based on the order in which the properties are saved .
+
+
+### Annotations
+* The json spdx schema does not define the SPDX Identifier property for the annotation object . The saver inserts the annotation inside the element who spdx identifier mathches the annotation SPDX identifier .
+
+### Indentation
+* The jsonsaver uses the marshall indent function with "" as he prefix and "\t" as the indent character , passed as funtion parameters . \ No newline at end of file