-
Notifications
You must be signed in to change notification settings - Fork 106
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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.
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)