Get config false only nodes from tree
Is there a built-in or preferred way to get only config false nodes from a data tree?
The background here is that I'm writing a gNMI server component that serializes a ygot structure with some config false and some config true nodes. I'd like to be able to faithfully get either the CONFIG or OPERATIONAL leafs accordingly via a gNMI GetRequest. So I'm envisioning an option for EmitJSON or something that only outputs one or the other.
I see that there's PruneConfigFalse() in ygot, but this is the opposite of what I'd like to do. I could probably diff the output before and after running PruneConfigFalse() and determine it from there, but it seems rather hacky. I also see the IsConfig() function in util, but this would also require building something from scratch.
Today, there's not such an option -- it should be possible to write such a function that does the opposite of PruneConfigFalse as you note.
To do this as an option to EmitJSON or Marshal7951 is unfortunately not super-trivial -- since EmitJSON and Marshal7951 today don't have access to the schematree that we store in the generated code.
Probably the cleanest way to do this is to:
- implement
PruneConfigTrueusing the same logic asPruneConfigFalse(likely with apruneByConfigFlaginternal function so we don't really duplicate the logic). - in the calling code call
ygot.PruneConfigTrue(ygot.DeepCopy(yourGoStructGoesHere)) - call
EmitJSON/Marshal7951based on the returned de-configed clone.
This requires no change in the marshalling logic (which is the goal since having the schema available and walking it at the same time as marshalling is quite expensive), yet gets what you need.
Thanks for the info, @robshakir. If I get some time I will give this a shot and submit a PR if I get it working suitably.