[plum] Utility Reference: unpack_from_and_dump()

plum.unpack_from_and_dump(fmt, buffer, offset=None)

Unpack item from within a bytes buffer and produce packed bytes summary.

Parameters:
  • fmt (Plum, tuple of Plum, or dict) – plum type, tuple of types, or dict of types
  • buffer (bytes-like (e.g. bytes, bytearray, memoryview) or binary file) – bytes buffer
  • offset (int) – starting byte offset (None indicates current file position)
Returns:

tuple of (unpacked items, bytes summary)

Return type:

Plum (or tuple of Plum, or dict of Plum, dependent on fmt), Dump

Raises:

UnpackError if insufficient bytes or value error

For example:
>>> from plum import unpack_from_and_dump
>>> from plum.int.little import UInt8
>>>
>>> buffer = b'\x99\x01\x99'
>>> offset = 1
>>>
>>> value, dump = unpack_from_and_dump(UInt8, buffer, offset)
>>> value
1
>>> print(dump)
+--------+-------+-------+-------+
| Offset | Value | Bytes | Type  |
+--------+-------+-------+-------+
| 1      | 1     | 01    | UInt8 |
+--------+-------+-------+-------+