-
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
Getting the value of a union #997
Comments
I was able to work around this by using fmt.Sprintf() to force the value into a string like so:
It prints it with an & and wrapped in {}, but I can strip those out, so it's better than nothing. |
Sorry -- yes, this is ugly. We generate a getter for this leaf if you use If you want to get this value back, do you already know what the type that you have set it to is? For example, could we improve this by generating something like the getters that proto does for If you didn't know the type, we could (thinking about it as I type) do something like: v, ok := area.GetIdentifier_Uint32()
if !ok {
// handle a non-uint32 type
} which seems quite idiomatic for a type assertion. |
Hi Rob, Thanks for the info. In my particular situation I do know what type it will be, so the first solution would be quite suitable. In any case, handling different types with the val, ok syntax seems good as well. Ian |
Once a union value is set, is it possible to get the value it was set to again as a "standard" type without marshalling to JSON?
I'm working with NetworkInstance_Protocol_Ospfv2_Area_Identifier_Union, which is a union of string and uint32. Let's say I set it like this:
I would like to retrieve the value of area.Identifier as a uint32 of 10 elsewhere in my code, but nothing I try works, because this variable is of type NetworkInstance_Protocol_Ospfv2_Area_Identifier_Union, and I haven't found anything in ygot that will give us back the value. I am also relatively new to go, so I might be missing something obvious about converting values as well.
The text was updated successfully, but these errors were encountered: