refactor unpack, add unpack_from

This commit is contained in:
Bob Ippolito 2006-05-24 15:32:06 +00:00
parent d5e0dc51cf
commit eb62127842
3 changed files with 168 additions and 69 deletions

View file

@ -73,3 +73,15 @@ def unpack(fmt, s):
except KeyError:
o = _compile(fmt)
return o.unpack(s)
def unpack_from(fmt, buf, offset=0):
"""
Unpack the buffer, containing packed C structure data, according to
fmt starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).
See struct.__doc__ for more on format strings.
"""
try:
o = _cache[fmt]
except KeyError:
o = _compile(fmt)
return o.unpack_from(buf, offset)