[plum] Utility Reference: pack_into_and_dump()

plum.pack_into_and_dump(fmt, buffer, offset, *args, **kwargs)

Pack values as bytes into a buffer following a format and produce bytes summary.

Parameters:
  • fmt (Plum, tuple/list of Plum, or dict of Plum) – byte format of values
  • buffer (bytes-like (e.g. bytearray, memoryview)) – bytes buffer
  • offset (int) – start location within bytes buffer
  • args (tuple) – packable values
  • kwargs – packable values
Returns:

packed bytes summary

Return type:

Dump

For example:

>>> from plum import pack_into_and_dump
>>> from plum.int.little import UInt8, UInt16
>>>
>>> fmt = (UInt8, UInt16)
>>> buffer = bytearray(5)
>>> offset = 1
>>>
>>> dump = pack_into_and_dump(fmt, buffer, offset, 0x11, 0x0302)
>>> print(dump)
+--------+--------+-------+-------+--------+
| Offset | Access | Value | Bytes | Type   |
+--------+--------+-------+-------+--------+
| 1      | [0]    | 17    | 11    | UInt8  |
| 2      | [1]    | 770   | 02 03 | UInt16 |
+--------+--------+-------+-------+--------+
>>> buffer
bytearray(b'\x00\x11\x02\x03\x00')