p4lang / tutorials

P4 language tutorials
Apache License 2.0
1.31k stars 875 forks source link

Added a decode function to convert.py for MAC, IPs, and numeric values. #589

Open Abhinavcode13 opened 3 months ago

Abhinavcode13 commented 3 months ago
jafingerhut commented 3 months ago

I withdraw (and deleted) my previous comment. If you happen to see it in email, you can ignore it.

Is there a example use case you expect where this new decode function would be used?

Abhinavcode13 commented 3 months ago

I withdraw (and deleted) my previous comment. If you happen to see it in email, you can ignore it.

Is there a example use case you expect where this new decode function would be used?

@jafingerhut

The main reason for including this decode function is as follows:

jafingerhut commented 3 months ago

So the thing that seems strange to me about this new function is that you give it a byte string, with presumably no knowledge whatsoever of what that byte string is intended to represent. This new decode function assumes it is either an IPv6 address, an IPv4 address, or a MAC address, and opportunistically tries to decode it to a human-readable string representing that address, even if the byte string is just some other 128-, 32-, or 48-bit value that has nothing to do with one of those address types. It seems difficult for me to imagine when one would find that useful. At least with the existing decodeIPv4, decodeIPv6, and decodeMac, the caller knows that the byte string is supposed to represent an address of the given kind, and tries to decode it with that assumption.

Abhinavcode13 commented 3 months ago

Thank you for pointing that out! I'll revisit my implementation for this decode function to ensure it aligns with the intended use case.