Skip to content

Commit c3e9140

Browse files
committed
tools: ynl: support packing binary arrays of scalars
We support decoding a binary type with a scalar subtype already, add support for sending such arrays to the kernel. While at it also support using "None" to indicate that the binary attribute should be empty. I couldn't decide whether empty binary should be [] or None, but there should be no harm in supporting both. Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1560af5 commit c3e9140

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tools/net/ynl/pyynl/lib/ynl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ def _add_attr(self, space, name, value, search_attrs):
575575
elif attr["type"] == 'string':
576576
attr_payload = str(value).encode('ascii') + b'\x00'
577577
elif attr["type"] == 'binary':
578-
if isinstance(value, bytes):
578+
if value is None:
579+
attr_payload = b''
580+
elif isinstance(value, bytes):
579581
attr_payload = value
580582
elif isinstance(value, str):
581583
if attr.display_hint:
@@ -584,6 +586,9 @@ def _add_attr(self, space, name, value, search_attrs):
584586
attr_payload = bytes.fromhex(value)
585587
elif isinstance(value, dict) and attr.struct_name:
586588
attr_payload = self._encode_struct(attr.struct_name, value)
589+
elif isinstance(value, list) and attr.sub_type in NlAttr.type_formats:
590+
format = NlAttr.get_format(attr.sub_type)
591+
attr_payload = b''.join([format.pack(x) for x in value])
587592
else:
588593
raise Exception(f'Unknown type for binary attribute, value: {value}')
589594
elif attr['type'] in NlAttr.type_formats or attr.is_auto_scalar:

0 commit comments

Comments
 (0)