mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
refactor unpack, add unpack_from
This commit is contained in:
parent
d5e0dc51cf
commit
eb62127842
3 changed files with 168 additions and 69 deletions
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue