Skip to content

Commit 1f17612

Browse files
committed
Added null value entry for bjson
1 parent 5955c8f commit 1f17612

File tree

6 files changed

+20
-1
lines changed

6 files changed

+20
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist
2-
/build
2+
/build
3+
/bjson/__pycache__

assets/full/null.png

1.78 KB
Loading

assets/null.png

1.02 KB
Loading
247 Bytes
Binary file not shown.

bjson/bjson.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def convertBjsonToJson(fp: str|Path):
6464
idx = i * 3 + 1
6565
type_extracted = int.from_bytes(extract_chunk(data_bytes, idx), "little", signed=False)
6666
if type_extracted == 6:
67+
# Object data type
6768
if json_dict == None:
6869
json_dict = {}
6970
tmp = []
@@ -128,6 +129,7 @@ def convertBjsonToJson(fp: str|Path):
128129
hash_database.addToDatabase(text_decode, hashlist)
129130
tmp[3] += 1
130131
elif type_extracted == 4:
132+
# Array data type
131133
if json_dict == None:
132134
json_dict = []
133135
tmp = []
@@ -152,6 +154,7 @@ def convertBjsonToJson(fp: str|Path):
152154
if tmp[3] >= tmp[2]:
153155
place_dir.pop(-2)
154156
elif type_extracted == 3:
157+
# Float data type
155158
tmp = place_dir[-1]
156159
dir = tmp[0]
157160
if tmp[1] == "array":
@@ -163,6 +166,7 @@ def convertBjsonToJson(fp: str|Path):
163166
dir.append(float("{:.2f}".format(float_num)))
164167
tmp[3] += 1
165168
elif type_extracted == 2:
169+
# Integer data type
166170
tmp = place_dir[-1]
167171
dir = tmp[0]
168172
if tmp[1] == "array":
@@ -172,6 +176,7 @@ def convertBjsonToJson(fp: str|Path):
172176
dir.append(bytes_to_int(extract_chunk(data_bytes, idx + 1), "little"))
173177
tmp[3] += 1
174178
elif type_extracted == 1:
179+
# Boolean data type
175180
tmp = place_dir[-1]
176181
dir = tmp[0]
177182
if tmp[1] == "array":
@@ -188,6 +193,16 @@ def convertBjsonToJson(fp: str|Path):
188193
elif bool_num == 1:
189194
dir.append(True)
190195
tmp[3] += 1
196+
elif type_extracted == 0:
197+
# None data type
198+
tmp = place_dir[-1]
199+
dir = tmp[0]
200+
if tmp[1] == "array":
201+
# With header
202+
dir[f"{headers[i-1]}"] = None
203+
elif tmp[1] == "list":
204+
dir.append(None)
205+
tmp[3] += 1
191206

192207
if len(place_dir) > 0:
193208
check = place_dir[-1]

main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def loadTreeviewFromBjson(root, tree: ttk.Treeview, fp: str|Path):
9393
tree.icons["textLogo"] = tkinter.PhotoImage(file=os.path.join(root.app_path, "assets/text.png"))
9494
tree.icons["numberLogo"] = tkinter.PhotoImage(file=os.path.join(root.app_path, "assets/number.png"))
9595
tree.icons["booleanLogo"] = tkinter.PhotoImage(file=os.path.join(root.app_path, "assets/boolean.png"))
96+
tree.icons["nullLogo"] = tkinter.PhotoImage(file=os.path.join(root.app_path, "assets/null.png"))
9697
setIcons(tree, tree.icons)
9798

9899
loading_label.grid_remove()
@@ -113,6 +114,8 @@ def setIcons(tree: ttk.Treeview, icons: dict, parent=""):
113114
tree.item(child, image=icons["numberLogo"])
114115
elif values[0] == "Boolean":
115116
tree.item(child, image=icons["booleanLogo"])
117+
elif values[0] == "null":
118+
tree.item(child, image=icons["nullLogo"])
116119
else:
117120
print(f"Not match: {values[0]}")
118121
setIcons(tree, icons, child)

0 commit comments

Comments
 (0)