Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Working htsmsg.py
  • Loading branch information
ckarrie authored and perexg committed Aug 17, 2016
1 parent 70db72b commit 6fa2995
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/py/tvh/htsmsg.py
Expand Up @@ -49,6 +49,8 @@ def bin2int ( d ):
HMF_STR = 3
HMF_BIN = 4
HMF_LIST = 5
HMF_DBL = 6
HMF_BOOL = 7

# Light wrapper for binary type
class hmf_bin(str):
Expand All @@ -57,9 +59,9 @@ class hmf_bin(str):
# Convert python to HTSMSG type
def hmf_type ( f ):
if type(f) == list:
return HMF_MAP
elif type(f) == dict:
return HMF_LIST
elif type(f) == dict:
return HMF_MAP
elif type(f) == str:
return HMF_STR
elif type(f) == int:
Expand All @@ -78,7 +80,7 @@ def _binary_count ( f ):
while (f):
ret = ret + 1
f = f >> 8
elif type(f) in [ list, map ]:
elif type(f) in [ list, dict ]:
ret = ret + binary_count(f)
else:
raise Exception('invalid data type')
Expand Down Expand Up @@ -157,6 +159,12 @@ def deserialize0 ( data, typ = HMF_MAP ):
i = i - 1
elif typ in [ HMF_LIST, HMF_MAP ]:
item = deserialize0(data[:dlen], typ)
elif typ == HMF_BOOL:
bool_val = data[:dlen]
if len(bool_val) > 0:
item = bool(ord(bool_val))
else:
item = None
else:
raise Exception('invalid data type %d' % typ)
if islist:
Expand Down

0 comments on commit 6fa2995

Please sign in to comment.