[plum] Utility Reference: unpack_and_dump()

plum.unpack_and_dump(fmt, buffer)

Unpack item(s) from bytes 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
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, excess bytes, or value error

For example:
>>> from plum import unpack_and_dump
>>> from plum.int.little import UInt8, UInt16
>>>
>>> value, dump = unpack_and_dump((UInt8, UInt16), b'\x00\x01\x02')
>>> value
(0, 513)
>>> print(dump)
+--------+--------+-------+-------+--------+
| Offset | Access | Value | Bytes | Type   |
+--------+--------+-------+-------+--------+
| 0      | [0]    | 0     | 00    | UInt8  |
| 1      | [1]    | 513   | 01 02 | UInt16 |
+--------+--------+-------+-------+--------+