[plum] Utility Reference: unpack()

plum.unpack(fmt, buffer)

Unpack item(s) from bytes.

  • 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

unpacked items

Return type:

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


UnpackError if insufficient bytes, excess bytes, or value error

For example:
>>> from plum import unpack
>>> from plum.int.little import UInt8, UInt16
>>> unpack(UInt16, b'\x01\x02')
>>> unpack((UInt8, UInt16), b'\x00\x01\x02')
(0, 513)
>>> unpack({'a': UInt8, 'b': UInt16}, b'\x00\x01\x02')
{'a': 0, 'b': 513}