ygot icon indicating copy to clipboard operation
ygot copied to clipboard

Any means to convert gnmi.Notification to related GoStructs?

Open gsindigi opened this issue 4 years ago • 4 comments

Similar to the library func ygot.TogNMINotifications, is there any func to achieve set of Notifications to related GoStructs? 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.

gsindigi avatar Apr 12 '20 11:04 gsindigi

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.

robshakir avatar Apr 12 '20 21:04 robshakir

Thanks @robshakir . I had a similar issue while using ygot.Diff. I wanted to apply the notification produced, to the original GoStruct object.

soumiksamanta avatar Jun 21 '20 01:06 soumiksamanta

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 avatar Jun 21 '20 16:06 wenovus

@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.

soumiksamanta avatar Jun 21 '20 17:06 soumiksamanta

Extremely late post here, but there is now a ytypes.UnmarshalNotifications function for this.

wenovus avatar Jun 05 '23 20:06 wenovus