reference icon indicating copy to clipboard operation
reference copied to clipboard

Generate proto input message from json

Open shushukl-cisco opened this issue 5 years ago • 1 comments

Hi,

I want to generate proto inputs in this format from a json equivalent. Is there a way to do so?

path: < elem: < name: "a"

elem: < name: "b"

elem: < name: "c"

elem: < name: "d"

Or is there some proto structure / library I can use to dynamically populate proto structures like the above?

shushukl-cisco avatar Apr 01 '20 07:04 shushukl-cisco

What is the format of the JSON input that you have? There are two sets of functions that might be of interest in ygot for this:

  • ygot.StringToStructuredPath -- this will take an input path string (per this spec) and convert it to a gnmi.Path protobuf message.
  • <generated package>.Unmarshal combined with ygot.TogNMINotifications -- this will allow you to unmarshal an RFC7951-compliant JSON output into a ygot-generated Go struct, the TogNMINotifications will then marshal its contents as a set of gnmi.Notification messages containing both the path and value.

Cheers, r.

robshakir avatar Apr 01 '20 16:04 robshakir