-
Notifications
You must be signed in to change notification settings - Fork 104
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
Union field has nil value after xml.Unmarshal #961
Comments
identities and enumerations are represented as strings per https://datatracker.ietf.org/doc/html/rfc7951, |
Yes, value is generated using ygot. I also dont know how to distinguish between values as if it for first enum or second and also how to give value in tag as whatever I am giving it is not accepting and converting to nil after unmarshal. |
Here I would be expecting ygot to accept the string "A", "B", "C", or "D" since these seem to be the enum names in YANG. How did you get |
Inside each enums we have Identity. That might be causing values to be generated as 0,1,2 ? |
In your code you have err := xml.Unmarshal([]byte(xmlData), &gostruct) I'm not quite sure where the |
I have generated go code using ygot generator for my yang files.
Here is the sample generated go struct which I am using to Unmarshal. Union is always converted as nil.
Note: "Type" is union of two enums (and each enums has multiple identity) in my yang
package main
import (
"encoding/xml"
"fmt"
)
type State struct {
Description *string
Type Type_Union
}
type Type_Union interface {
Is_Type_Union()
}
type Type_Union_E_HARDWARE struct {
E_HARDWARE E_HARDWARE
}
func (*Type_Union_E_HARDWARE) Is_Type_Union() {}
type Type_Union_E_SOFTWARE struct {
E_SOFTWARE E_SOFTWARE
}
func (*Type_Union_E_SOFTWARE) Is_Type_Union() {}
type E_HARDWARE int64
func (E_HARDWARE) IsYANGGoEnum() {}
const (
HARDWARE_UNSET E_HARDWARE = 0
HARDWARE_A E_HARDWARE = 1
HARDWARE_B E_HARDWARE = 2
)
type E_SOFTWARE int64
func (E_SOFTWARE) IsYANGGoEnum() {}
const (
SOFTWARE_UNSET E_SOFTWARE = 0
SOFTWARE_C E_SOFTWARE = 1
SOFTWARE_D E_SOFTWARE = 2
)
func main() {
xmlData :=
<abc> <Description>Hello</Description> <Type>2</Type> </abc>
}
Output:
Description: Hello
type:
Let me know what modification is needed in the input to get the correct value.
The text was updated successfully, but these errors were encountered: