-
Notifications
You must be signed in to change notification settings - Fork 107
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
Can enum preserve their defined values while converting yang to gostruct using openconfig/ygot\@v0.25.4/generator/generator.go ? #935
Comments
Currently the Go-generated code does not respect the YANG enum value and we do not support it. This has been brought up before (#286) and the solution would be a flag-protected feature. We currently don't have plans to add this ourselves since JSON (RFC7951) and gNMI both use strings instead of this number for configuration and telemetry, rather than the enum value. However we would welcome any contributions. There is a concern I can see right now if any implementation is done -- if any of the enum values uses 0, then the UNSET value must be a different value, and then any uninitialized enum field would not be 0. This would not be good Go style and choosing a value may cause a conflict later on if more values are added. One solution is to add 1 to every positive generated value and subtract 1 for every negative generated value from the YANG value. |
Thank you @wenovus for the quick reply! If you can share more details on an idea of flag-protected feature, that will be really helpful. |
Some quick tips:
See if you can figure out how the values are currently populated, and then tweak it to meet your needs, taking into account the design consideration above. I'm going to be out for a week, I can follow-up afterwards.
I'm not quite sure what you mean here, I'm assuming you're the feature requester, so you would know how you can use it :-) ? |
I am using openconfig/ygot@v0.25.4/generator/generator.go to convert yang to gostruct.
But the enum values are not converted as it is.
Example:
typedef enum_example {
type enumeration {
enum five
{ value 5; }
enum eight
{value 8;}
}
}
Generated Go Code
const (
EnumExample_UNSET E_EnumExample = 0
EnumExample_five E_EnumExample = 1
EnumExample_eight E_EnumExample = 2
)
The Go code that I expect:
const (
EnumExample_UNSET E_EnumExample = 0
EnumExample_five E_EnumExample = 5
EnumExample_eight E_EnumExample = 8
)
Is there any way I can generate go enums with the values same as defined in yang file?
The text was updated successfully, but these errors were encountered: