-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to specify preferred string representation of types #458
Comments
A little bit of semi-related history here. The It might be possible to modify open source |
By the way, if anyone has not tried defining a |
Note: Chris, your initial comment is good, but one of my main questions for ergonomics of such a feature is "where would you expect to have to write the @REPR annotation in your P4_16 source code". If you are happy adding If you want |
It'd be handy to be able to specify, in one place, the preferred string representation of selected data types, e.g. IPv4 should be represented as dotted-decimal, etc. Use-cases would be to enable P4Runtime clients (CLIs, GUIs) and even server-side debug logs to format data in the appropriate human-readable format. Various ad hoc techniques are already solving this problem one way or another (custom annotations in P4 code; annotation APIs in vendor runtime libraries; etc.). A standardized way of solving this would be very useful. The oft-heard response to this perennial issue has been "use an annotation," so we might as well begin defining some standardized ones and present to the LDWG as a proposal for a new reserved annotation.
I hereby propose to:
@repr(format)
in the P4-16 language spec. I chose this based on the familiar Python__repr__
attribute (plus it's short). it can be anything we like but it should be concise!format
can be one of:ipv4
- IPv4 dotted decimal, e.g.192.168.1.1
ipv6
- IPv6 quad notation e.g.1234:5678::abcd
cidr
- Ternary/LPM value as an IP Prefix e.g.192.168.1.0/24
or2001:db8::/48
auto-selected based on size (32 bits or 128 bits)mac
- MAC address, e.g.01:23:45:67:89:ab
dec
- decimal e.g.4095
hex
- hexadecimal e.g.0xdeadbeef
bin
- binary e.g.01011010
bool
- boolean, e.g.true
ascii
- ASCII text, e.g.Hello
These annotations would appear in P4Info and can be consumed by clients as well as servers to use or not at their discretion. The only impact of this proposal would be to reserve and document a new annotation in the P4-16 language spec.
The text was updated successfully, but these errors were encountered: