MostAwesomeDude/construct — Issue #11: CString sizeof with context throws "can't calculate size" SizeofError
Author: HazimGazov
Created: 2011-11-14 15:29:41+00:00
State: open

This seems to be an issue with CString being an adapted RepeatUntil, which always throws an error for sizeof calls.

>>> from construct import *
>>> str = CString("a_string")
>>> str_parsed = str.parse("foo\x00")
>>> print str_parsed
foo
>>> str.sizeof()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/construct-2.06-py2.7.egg/construct/core.py", line 242, in sizeof
raise SizeofError(e)
construct.core.SizeofError: can't calculate size
>>> str.sizeof(str_parsed)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/construct-2.06-py2.7.egg/construct/core.py", line 242, in sizeof
raise SizeofError(e)
construct.core.SizeofError: can't calculate size