Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ygot diff output to JSON IETF #581

Open
adelshafiei opened this issue Sep 7, 2021 · 1 comment
Open

Convert ygot diff output to JSON IETF #581

adelshafiei opened this issue Sep 7, 2021 · 1 comment

Comments

@adelshafiei
Copy link

I am working with a gNMI server which only supports JSON IETF encodings. So I am trying to convert the output of ygot diff API to JSON IETF Encodings:

type TypedValue struct {
// One of the fields within the val oneof is populated with the value
// of the update. The type of the value being included in the Update
// determines which field should be populated. In the case that the
// encoding is a particular form of the base protobuf type, a specific
// field is used to store the value (e.g., json_val).
//
// Types that are assignable to Value:
// *TypedValue_StringVal
// *TypedValue_IntVal
// *TypedValue_UintVal
// *TypedValue_BoolVal
// *TypedValue_BytesVal
// *TypedValue_FloatVal
// *TypedValue_DecimalVal
// *TypedValue_LeaflistVal
// *TypedValue_AnyVal
// *TypedValue_JsonVal
// *TypedValue_JsonIetfVal
// *TypedValue_AsciiVal
// *TypedValue_ProtoBytes
Value isTypedValue_Value protobuf_oneof:"value"
// contains filtered or unexported fields
}

Is there an API that gets TypedValue of different formats and converts them to JSON IETF?

Thanks,

@wenovus
Copy link
Collaborator

wenovus commented Sep 7, 2021

Unforunately I don't think there is a function that converts TypedValue to JSON, even if all of these are leafs.

One way is to unmarshal these one-by-one back into a GoStruct using ytypes' SetNode, and then getting each value via GetNode, and then calling ygot.Marshal7951.

Another way is to unmarshal all of them into a GoStruct using ytypes' SetNode, and then simply calling ygot.Marshal7951 that gives you a bigger piece of JSON.

Another way is to add to the implementation a new DiffOpt for ygot.Diff that encodes the values using Marshal7951 instead of EncodeTypedValue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants