Skip to content

Commit b334f5e

Browse files
liuhangbinkuba-moo
authored andcommitted
ynl: support hex display_hint for integer
Some times it would be convenient to read the integer as hex, like mask values. Suggested-by: Donald Hunter <[email protected]> Reviewed-by: Donald Hunter <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 51cf49f commit b334f5e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/net/ynl/lib/ynl.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,10 @@ def _formatted_string(self, raw, display_hint):
819819
if display_hint == 'mac':
820820
formatted = ':'.join('%02x' % b for b in raw)
821821
elif display_hint == 'hex':
822-
formatted = bytes.hex(raw, ' ')
822+
if isinstance(raw, int):
823+
formatted = hex(raw)
824+
else:
825+
formatted = bytes.hex(raw, ' ')
823826
elif display_hint in [ 'ipv4', 'ipv6' ]:
824827
formatted = format(ipaddress.ip_address(raw))
825828
elif display_hint == 'uuid':

0 commit comments

Comments
 (0)