Closed Sneh-Prabha closed 4 months ago
identities and enumerations are represented as strings per https://datatracker.ietf.org/doc/html/rfc7951, 2
is ambiguous.
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
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 2
in the output? ygot would not be able to unmarshal that.
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 xml
library is, nor where xmlData
comes from or why those two things has to do with ygot. The data is not RFC7951 compliant, so I would recommend understanding how it was generated.
ygot doesn't support XML marshalling and unmarshalling, solely RFC7951 JSON. If you would like to add support for this, we would welcome a contribution.
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 := `
}
Output: Description: Hello type:
Let me know what modification is needed in the input to get the correct value.