[plum] Utility Reference: pack()

plum.pack(fmt, *args, **kwargs)

Pack values as bytes following a format.

Parameters:
  • fmt (Plum, tuple/list of Plum, or dict of Plum) – byte format of values
  • args (tuple) – packable values
  • kwargs – packable values
Returns:

bytes buffer

Return type:

bytearray

For example:

>>> from plum import pack
>>> from plum.int.little import UInt8, UInt16
>>> pack(UInt8, 1)
bytearray(b'\x01')
>>> pack((UInt8, UInt8), 1, 2)
bytearray(b'\x01\x02')
>>> pack({'a': UInt8, 'b': UInt8}, a=1, b=2)
bytearray(b'\x01\x02')