summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-11 12:01:38 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-11 12:01:38 +0100
commit427374cab40dd1b658d3b7cf219a709062d79b8c (patch)
treecc51c5a6cbcb420dcaa0e32591fc7db1859b79e9 /lib
parentc6e50eea97ca03bfd096aad23747659a216c9b78 (diff)
add int value length (does int fit into 1/2/4 bytes?)
Diffstat (limited to 'lib')
-rw-r--r--lib/data_parameters.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/data_parameters.py b/lib/data_parameters.py
index 5be363e..611a191 100644
--- a/lib/data_parameters.py
+++ b/lib/data_parameters.py
@@ -20,6 +20,22 @@ def _string_value_length(json):
return 0
+def _int_value_length(json):
+ if type(json) == int:
+ if json < 256:
+ return 1
+ if json < 65536:
+ return 2
+ return 4
+
+ if type(json) == dict:
+ return sum(map(_int_value_length, json.values()))
+
+ if type(json) == list:
+ return sum(map(_int_value_length, json))
+
+ return 0
+
def _string_key_length(json):
if type(json) == dict:
return sum(map(len, json.keys())) + sum(map(_string_key_length, json.values()))
@@ -52,7 +68,7 @@ def json_to_param(json):
ret['strlen_keys'] = _string_key_length(json)
ret['strlen_values'] = _string_value_length(json)
- #ret['num_keys'] = _num_keys(json)
+ ret['bytelen_int'] = _int_value_length(json)
ret['num_int'] = _num_of_type(json, int)
ret['num_float'] = _num_of_type(json, float)
ret['num_str'] = _num_of_type(json, str)