Closed gsindigi closed 4 years ago
This issue is prevalent for any of the generated structs, with *Int64 fields. Picked up a different struct with such a field and found same error. How do we use such fields and overcome the issue ? Any suggestions to address the issue will help.
test_int64.go:282] JSON: { "last-update": "345" } test_int64.go:287] Failed while converting to gNMINotifications: cannot represent field value 345 as TypedValue
// OpenconfigLldp_Lldp_Interfaces_Interface_Neighbors_Neighbor_State represents the /openconfig-lldp/lldp/interfaces/interface/neighbors/neighbor/state YANG schema element.
type OpenconfigLldp_Lldp_Interfaces_Interface_Neighbors_Neighbor_State struct {
...
LastUpdate *int64 `path:"last-update" module:"openconfig-lldp"`
...
}
func validateInt64() {
st := &ocd.OpenconfigLldp_Lldp_Interfaces_Interface_Neighbors_Neighbor_State{LastUpdate: ygot.Int64(345)}
ejc := &ygot.EmitJSONConfig{
Format: ygot.RFC7951,
Indent: " ",
RFC7951Config: &ygot.RFC7951JSONConfig{
AppendModuleName: false,
},
}
dJSON, e := ygot.EmitJSON(st, ejc)
if e != nil {
log.Errorf("failed converting to JSON: %v", e)
return
}
log.Infof("JSON: %v", dJSON)
cfg := ygot.GNMINotificationsConfig{UsePathElem: true}
now := time.Now().UnixNano()
g, err := ygot.TogNMINotifications(st, now, cfg)
if err != nil {
log.Fatalf("Failed while converting to gNMINotifications: %v", err)
}
log.Infof("Notifications: %v", g)
}
hi!
PTAL at #356 -- this adds a fix for the int64
rendering issue, there were a couple of defects in that codepath.
thanks, r.
Thanks @robshakir . Hope the fixes will be merged soon.
The GoStructs are generated in package "ocd" for OpenConfig-platform*yang modules, using
generator
tool as described. The generated code contains different GoStructs and utility functions to convert an appropriate value into corresponding GoStruct implementing the requisite interface for some specific yang types e.g., union; sample below.When such a GoStruct of such type or other GoStructs having such type as member are passed to ygot.TogNMINotifications, it results in an error "cannot represent field value as TypedValue". This is happening in
ygot/render.go
'sfunc EncodeTypedValue(val interface{}, enc gnmipb.Encoding) (*gnmipb.TypedValue, error)
line#640. Perhaps its expecting an Enum instead of Int64 here! but, the generated code do use Int64.Sample usage code below. Note that, no error is thrown while initializing the structs though. Could not figure out an easy way to put this as a test code with a YangUnion usage; hence posting with actual Structs usage.
Is anything wrong with the above usage ? If not, how to overcome this?
Thanks.