From b39286ecf540ab88740fc946d8b1f7e93e6e7999 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sat, 6 Jul 2019 21:14:41 -0700 Subject: [PATCH] Fix unmarshal of empty type leaf value for gNMI encoding --- ytypes/leaf.go | 4 ++-- ytypes/leaf_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ytypes/leaf.go b/ytypes/leaf.go index 971137736..3fc4e4ffc 100644 --- a/ytypes/leaf.go +++ b/ytypes/leaf.go @@ -854,7 +854,7 @@ func sanitizeGNMI(parent interface{}, schema *yang.Entry, fieldName string, tv * } switch ykind { - case yang.Ybool: + case yang.Ybool, yang.Yempty: return tv.GetBoolVal(), nil case yang.Ystring: return tv.GetStringVal(), nil @@ -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: _, ok = tv.GetValue().(*gpb.TypedValue_BoolVal) case yang.Ystring, yang.Yenum, yang.Yidentityref: _, ok = tv.GetValue().(*gpb.TypedValue_StringVal) diff --git a/ytypes/leaf_test.go b/ytypes/leaf_test.go index 8d0181aa1..00ce92dc8 100644 --- a/ytypes/leaf_test.go +++ b/ytypes/leaf_test.go @@ -1657,6 +1657,16 @@ func TestUnmarshalLeafGNMIEncoding(t *testing.T) { }, wantVal: &LeafContainerStruct{BoolLeaf: ygot.Bool(true)}, }, + { + desc: "success gNMI BoolVal to Yempty", + inSchema: typeToLeafSchema("empty-leaf", yang.Yempty), + inVal: &gpb.TypedValue{ + Value: &gpb.TypedValue_BoolVal{ + BoolVal: true, + }, + }, + wantVal: &LeafContainerStruct{EmptyLeaf: YANGEmpty(true)}, + }, { desc: "success gNMI StringVal to Ystring", inSchema: typeToLeafSchema("string-leaf", yang.Ystring),