Skip to content

Commit

Permalink
Merge pull request #18 from ythadhani/nokia-master
Browse files Browse the repository at this point in the history
Unmarshal fixes
  • Loading branch information
ythadhani authored Aug 4, 2022
2 parents 738c041 + 855ae44 commit a6e32b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
5 changes: 2 additions & 3 deletions util/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"reflect"

"github.com/kylelemons/godebug/pretty"
"github.com/openconfig/goyang/pkg/yang"

log "github.com/golang/glog"
Expand Down Expand Up @@ -210,8 +209,8 @@ func InsertIntoSlice(parentSlice interface{}, value interface{}) error {

// InsertIntoMap inserts value with key into parent which must be a map.
func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error {
DbgPrint("InsertIntoMap into parent type %T with key %v(%T) value \n%s\n (%T)",
parentMap, ValueStrDebug(key), key, pretty.Sprint(value), value)
// DbgPrint("InsertIntoMap into parent type %T with key %v(%T) value \n%s\n (%T)",
// parentMap, ValueStrDebug(key), key, pretty.Sprint(value), value)

v := reflect.ValueOf(parentMap)
t := reflect.TypeOf(parentMap)
Expand Down
3 changes: 1 addition & 2 deletions ytypes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strings"

log "github.com/golang/glog"
"github.com/kylelemons/godebug/pretty"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/util"
"github.com/openconfig/ygot/yext"
Expand Down Expand Up @@ -258,7 +257,7 @@ func unmarshalStruct(schema *yang.Entry, parent interface{}, jsonTree map[string
}
}

util.DbgPrint("container after unmarshal:\n%s\n", pretty.Sprint(destv.Interface()))
// util.DbgPrint("container after unmarshal:\n%s\n", pretty.Sprint(destv.Interface()))
return nil
}

Expand Down
26 changes: 12 additions & 14 deletions ytypes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"reflect"
"strings"

"github.com/kylelemons/godebug/pretty"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/util"
)
Expand Down Expand Up @@ -337,22 +336,21 @@ func unmarshalList(schema *yang.Entry, parent interface{}, jsonList interface{},

switch {
case util.IsTypeMap(t):
var newKey reflect.Value
// var present bool
var (
newKey reflect.Value
present bool
)
newKey, err = makeKeyForInsert(schema, parent, newVal)
if err != nil {
return err
}
// TODO(ythadhani) Uncomment once express passes
/*
present, err = util.MapContainsKey(parent, newKey.Interface())
if err != nil {
return err
}
if present {
return fmt.Errorf("duplicate value: %v encountered for key(s): %s of list: %s", newKey.Interface(), schema.Key, schema.Name)
}
*/
present, err = util.MapContainsKey(parent, newKey.Interface())
if err != nil {
return err
}
if present {
return fmt.Errorf("duplicate value: '%v' encountered for key(s): '%s' of list: '%s'", newKey.Interface(), schema.Key, schema.Name)
}
err = util.InsertIntoMap(parent, newKey.Interface(), newVal.Interface())
case util.IsTypeSlicePtr(t):
err = util.InsertIntoSlice(parent, newVal.Interface())
Expand All @@ -363,7 +361,7 @@ func unmarshalList(schema *yang.Entry, parent interface{}, jsonList interface{},
return err
}
}
util.DbgPrint("list after unmarshal:\n%s\n", pretty.Sprint(parent))
// util.DbgPrint("list after unmarshal:\n%s\n", pretty.Sprint(parent))

return nil
}
Expand Down

0 comments on commit a6e32b4

Please sign in to comment.