ygot
ygot copied to clipboard
Any means to convert gnmi.Notification to related GoStructs?
Similar to the library func ygot.TogNMINotifications
, is there any func to achieve set of Notification
s to related GoStruct
s? When I tried to come up with a generic way to achieve this, came across certain challenges e.g., as Notification encodes primitve types in generic Typed_U/Int_Vals, its difficult determine the actual datatype of the leaf entity. This needs reflection and YANG-Schema based inspection similar to the way its done in TogNMINotifications
. I could not find any exported functions in the library. Possible that, I could be overlooking. If so, please point me to the same. Otherwise, are there any means to achieve this so that it fits and leverages existing code? Thanks.
You can use ytypes.SetNode
(godoc) which allows you to hand the root, along with the gNMI Path
message and the value that you have. This allows unmarshalling of gNMI Notifications into a generated struct.
Thanks @robshakir . I had a similar issue while using ygot.Diff. I wanted to apply the notification produced, to the original GoStruct object.
There is a ygot. MergeStructInto
(godoc) that allows you to merge the fields of a different struct into the original GoStruct. Does that do what you want to achieve?
@wenovus My requirement is to generate the notification using the diff and apply selected updates and/or deletes on the original struct.
Thanks for the tip though. MergeStructInfo
can be used if I had to merge the entire modified GoStruct to the original GoStruct.
Extremely late post here, but there is now a ytypes.UnmarshalNotifications function for this.