diff mbox series

[net-next,v1,2/7] tools/net/ynl: support decoding indexed arrays as enums

Message ID 20241203130655.45293-3-donald.hunter@gmail.com
State Superseded
Headers show
Series netlink: specs: add a spec for nl80211 wiphy | expand

Commit Message

Donald Hunter Dec. 3, 2024, 1:06 p.m. UTC
When decoding an indexed-array with a scalar subtype, it is currently
only possible to add a display-hint. Add support for decoding each value
as an enum.

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
 tools/net/ynl/lib/ynl.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski Dec. 4, 2024, 2 a.m. UTC | #1
On Tue,  3 Dec 2024 13:06:50 +0000 Donald Hunter wrote:
> When decoding an indexed-array with a scalar subtype, it is currently
> only possible to add a display-hint. Add support for decoding each value
> as an enum.

Makes me wonder if we should factor this code out into a helper.
But there aren't too many sites with this code so fine either way:

Acked-by: Jakub Kicinski <kuba@kernel.org>
Donald Hunter Dec. 4, 2024, 1:20 p.m. UTC | #2
On Wed, 4 Dec 2024 at 02:00, Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Tue,  3 Dec 2024 13:06:50 +0000 Donald Hunter wrote:
> > When decoding an indexed-array with a scalar subtype, it is currently
> > only possible to add a display-hint. Add support for decoding each value
> > as an enum.
>
> Makes me wonder if we should factor this code out into a helper.
> But there aren't too many sites with this code so fine either way:

I'll look at potential refactoring as a follow up.

> Acked-by: Jakub Kicinski <kuba@kernel.org>

Thanks,
Donald.
diff mbox series

Patch

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index dbc7a0a6ae68..0d39a83574d5 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -650,7 +650,9 @@  class YnlFamily(SpecFamily):
                 decoded.append(subattr)
             elif attr_spec["sub-type"] in NlAttr.type_formats:
                 subattr = item.as_scalar(attr_spec['sub-type'], attr_spec.byte_order)
-                if attr_spec.display_hint:
+                if 'enum' in attr_spec:
+                    subattr = self._decode_enum(subattr, attr_spec)
+                elif attr_spec.display_hint:
                     subattr = self._formatted_string(subattr, attr_spec.display_hint)
                 decoded.append(subattr)
             else: