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

Fix unmarshal of empty type leaf value for gNMI encoding #292

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cho-m
Copy link
Contributor

@cho-m cho-m commented Jul 7, 2019

Possibly fixes #291

Need to confirm if any special handling of bool_val:false for empty type since YANG empty type really only has 2 possible states ([1]doesn't exist, or [2]true) while YANG boolean type has 3 possible states ([1]doesn't exist, [2]true, or [3]false)

@googlebot googlebot added the cla: yes This PR author has signed the CLA label Jul 7, 2019
@coveralls
Copy link

coveralls commented Jul 7, 2019

Coverage Status

Coverage remained the same at 90.976% when pulling be89046 on cho-m:fix-unmarshal-gnmi-empty-leaf into ef8f2a1 on openconfig:master.

Copy link
Contributor

@robshakir robshakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change -- I think the general shape of it is right, but I think the assumption that we can handle any value of an empty and just hand it on to the struct seems like it might have some challenges. Please see the question below.

@@ -902,7 +902,7 @@ func sanitizeGNMI(parent interface{}, schema *yang.Entry, fieldName string, tv *
func gNMIToYANGTypeMatches(ykind yang.TypeKind, tv *gpb.TypedValue) bool {
var ok bool
switch ykind {
case yang.Ybool:
case yang.Ybool, yang.Yempty:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that we really need to make yang.Yempty always set the field to true if we receive this. Since YANGEmpty isn't a pointer in the generated code, then if we receive an empty field that has a bool value of false then this won't be something that the client application can tell was received. Could you add this handling as a special case please?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there already appears to be handling for this case:

ygot/util/reflect.go

Lines 256 to 262 in f01913a

// YANG empty fields are represented as a derived bool value defined in the
// generated code. Here we cast the value to the type in the generated code.
if ft.Type.Kind() == reflect.Bool && t.Kind() == reflect.Bool {
nv := reflect.New(ft.Type).Elem()
nv.SetBool(v.Bool())
v = nv
}

When unmarshalling an empty leaf from a TypedValue in the current code, unmarshalScalar returns the non-pointer bool value, which unmarshalLeaf then takes and then feeds into InsertIntoStruct (directly or indirectly) to reach this special handling code.

This change doesn't support unmarshalling empty leafs (either JSON or gNMI) into a union type. However given its complexity I think it deserves to be addressed separately.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explored the question of unions containing empty in #582.

@robshakir robshakir added this to the 1.0.0 milestone Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This PR author has signed the CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to unmarshal BoolVal to Yempty (GNMIEncoding)
5 participants