Commit ffe10a45 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

tools: ynl: process all scalar types encoding in single elif statement

As a preparation to handle enums for scalar values, unify the processing
of all scalar types in a single elif statement.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20240222134351.224704-3-jiri@resnulli.usSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ac95b1fc
...@@ -474,14 +474,14 @@ class YnlFamily(SpecFamily): ...@@ -474,14 +474,14 @@ class YnlFamily(SpecFamily):
attr_payload = self._encode_struct(attr.struct_name, value) attr_payload = self._encode_struct(attr.struct_name, value)
else: else:
raise Exception(f'Unknown type for binary attribute, value: {value}') raise Exception(f'Unknown type for binary attribute, value: {value}')
elif attr.is_auto_scalar: elif attr['type'] in NlAttr.type_formats or attr.is_auto_scalar:
scalar = int(value) scalar = int(value)
real_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64') if attr.is_auto_scalar:
format = NlAttr.get_format(real_type, attr.byte_order) attr_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64')
attr_payload = format.pack(int(value)) else:
elif attr['type'] in NlAttr.type_formats: attr_type = attr["type"]
format = NlAttr.get_format(attr['type'], attr.byte_order) format = NlAttr.get_format(attr_type, attr.byte_order)
attr_payload = format.pack(int(value)) attr_payload = format.pack(scalar)
elif attr['type'] in "bitfield32": elif attr['type'] in "bitfield32":
attr_payload = struct.pack("II", int(value["value"]), int(value["selector"])) attr_payload = struct.pack("II", int(value["value"]), int(value["selector"]))
elif attr['type'] == 'sub-message': elif attr['type'] == 'sub-message':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment