def _pack_array(values, definition, fmt_string, num_bytes):
"""
Pack an array item defined by a dictionary entry into a bytearray
Args:
values (tuple): 1d or 2d tuple of values to pack
definition (dict): definition of the data item
fmt_string (str): struct.unpack format string for an element
num_bytes (int): number of bytes of each element
"""
packet_part = bytearray()
if definition['DIM_2_SIZE']:
for dim1 in values:
for value in dim1:
buff = bytearray(num_bytes)
struct.pack_into(fmt_string, buff, 0, value)
packet_part += buff
else:
for value in values:
buff = bytearray(num_bytes)
struct.pack_into(fmt_string, buff, 0, value)
packet_part += buff
return packet_part
评论列表
文章目录