diff options
author | Don Anderson <dda@ddanderson.com> | 2011-10-06 07:06:08 -0400 |
---|---|---|
committer | Don Anderson <dda@ddanderson.com> | 2011-10-06 07:06:08 -0400 |
commit | fd857970339083427df6d3fd8a2b6f34f41994d7 (patch) | |
tree | 5534831cbe71379df005feac21a79dbc15513e8b /lang | |
parent | e78bcf9a86027dae388d0cded6789e7b932e53c2 (diff) | |
download | mongo-fd857970339083427df6d3fd8a2b6f34f41994d7.tar.gz |
Added support to pack type 't', needed for 'fix' tables.
Added a simple test for fix tables.
refs #31
refs #16
--HG--
extra : rebase_source : 26f08d2b3715df318a0965e9c0d0f8b437cd8240
Diffstat (limited to 'lang')
-rw-r--r-- | lang/python/packing.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lang/python/packing.py b/lang/python/packing.py index ff4b2b60678..720b48d50b8 100644 --- a/lang/python/packing.py +++ b/lang/python/packing.py @@ -46,6 +46,12 @@ def unpack(fmt, s): if f == 'S' and not havesize: size += 1 s = s[size:] + elif f in 't': + # bit type, size is number of bits + if not havesize: + size = 1 + result.append(ord(s[0:1])) + s = s[1:] else: # integral type if not havesize: @@ -93,6 +99,18 @@ def pack(fmt, *values): elif size > l: result += '\0' * (size - l) i += 1 + elif f in 't': + # bit type, size is number of bits + if not havesize: + size = 1 + if size > 8: + raise ValueError("bit count cannot be greater than 8 for 't' encoding") + mask = (1 << size) - 1 + val = values[i] + if (mask & val) != val: + raise ValueError("value out of range for 't' encoding") + result += chr(val) + i += 1 else: # integral type if not havesize: |