[plum] Utility Reference: pack_into()

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

Pack values as bytes into a buffer following a format.

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

For example:

>>> from plum import pack_into
>>> from plum.int.little import UInt8, UInt16
>>>
>>> fmt = (UInt8, UInt16)
>>> buffer = bytearray(5)
>>> offset = 1
>>>
>>> pack_into(fmt, buffer, offset, 0x11, 0x0302)
>>> buffer
bytearray(b'\x00\x11\x02\x03\x00')