From: Jakub Kicinski <kuba@kernel.org>
To: Jiri Pirko <jiri@resnulli.us>
Cc: netdev@vger.kernel.org, pabeni@redhat.com, davem@davemloft.net,
edumazet@google.com, jacob.e.keller@intel.com,
swarupkotikalapudi@gmail.com, donald.hunter@gmail.com,
sdf@google.com, lorenzo@kernel.org,
alessandromarcolini99@gmail.com
Subject: Re: [patch net-next v2 3/3] tools: ynl: allow user to pass enum string instead of scalar value
Date: Wed, 21 Feb 2024 10:49:36 -0800 [thread overview]
Message-ID: <20240221104936.7c836f83@kernel.org> (raw)
In-Reply-To: <20240221155415.158174-4-jiri@resnulli.us>
On Wed, 21 Feb 2024 16:54:15 +0100 Jiri Pirko wrote:
> + def _encode_enum(self, attr_spec, value):
> + try:
> + return int(value)
> + except (ValueError, TypeError) as e:
> + if 'enum' not in attr_spec:
> + raise e
> + enum = self.consts[attr_spec['enum']]
> + if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
> + scalar = 0
> + if isinstance(value, str):
> + value = [value]
> + for single_value in value:
> + scalar += enum.entries[single_value].user_value(as_flags = True)
> + return scalar
> + else:
> + return enum.entries[value].user_value()
That's not symmetric with _decode_enum(), I said:
vvvvvvvvvvvvvvvvvvvvvv
It'd be cleaner to make it more symmetric with _decode_enum(), and
call it _encode_enum().
How about you go back to your _get_scalar name and only factor out the
parts which encode the enum to be a _encode_enum() ?
next prev parent reply other threads:[~2024-02-21 18:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 15:54 [patch net-next v2 0/3] tools: ynl: couple of cmdline enhancements Jiri Pirko
2024-02-21 15:54 ` [patch net-next v2 1/3] tools: ynl: allow user to specify flag attr with bool values Jiri Pirko
2024-02-21 18:07 ` Donald Hunter
2024-02-22 13:17 ` Jiri Pirko
2024-02-21 15:54 ` [patch net-next v2 2/3] tools: ynl: process all scalar types encoding in single elif statement Jiri Pirko
2024-02-21 18:12 ` Donald Hunter
2024-02-21 15:54 ` [patch net-next v2 3/3] tools: ynl: allow user to pass enum string instead of scalar value Jiri Pirko
2024-02-21 18:14 ` Donald Hunter
2024-02-21 18:49 ` Jakub Kicinski [this message]
2024-02-22 13:14 ` Jiri Pirko
2024-02-21 22:29 ` [patch net-next v2 0/3] tools: ynl: couple of cmdline enhancements Keller, Jacob E
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240221104936.7c836f83@kernel.org \
--to=kuba@kernel.org \
--cc=alessandromarcolini99@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jiri@resnulli.us \
--cc=lorenzo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=swarupkotikalapudi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).