Subject: Re: [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array

From: Jakub Kicinski <[email-masked]>
Date: Mon, 1 Apr 2024 21:43:31 -0700

On Mon,  1 Apr 2024 11:56:51 +0800 Hangbin Liu wrote:
> +Other ``sub-type`` like ``u32`` means there is only one member as described
> +in ``sub-type`` in the ``ENTRY``. The structure looks like::
> +
> +  [SOME-OTHER-ATTR]
> +  [ARRAY-ATTR]
> +    [ENTRY]
> +      [MEMBER1]
> +    [ENTRY]
> +      [MEMBER1]

I think that elsewhere in the doc we use [SOMETHING] to mean
TLV of type SOMETHING, here MEMBER1/2 are presumably just
payloads of each ENTRY? Maybe this is better:

  [SOME-OTHER-ATTR]
  [ARRAY-ATTR]
    [ENTRY u32]
    [ENTRY u32]

?

>  type-value
>  ~~~~~~~~~~
> diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> index e5ad415905c7..aa7077cffe74 100644
> --- a/tools/net/ynl/lib/ynl.py
> +++ b/tools/net/ynl/lib/ynl.py
> @@ -640,6 +640,11 @@ class YnlFamily(SpecFamily):
>              if attr_spec["sub-type"] == 'nest':
>                  subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
>                  decoded.append({ item.type: subattrs })
> +            elif attr_spec["sub-type"] == 'binary' or attr_spec["sub-type"] == 'u32':
> +                subattrs = item.as_bin()

Are you sure that as_bin() will work for all u32s?
Or just when there's a hint...

> +                if attr_spec.display_hint:
> +                    subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
> +                decoded.append(subattrs)