Skip to content
Snippets Groups Projects
Commit e9316e4c authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

change southbound interface

parent 8741b88f
No related branches found
No related tags found
1 merge request!173Process response overhaul
This commit is part of merge request !173. Comments created here will be created in the context of that merge request.
......@@ -2,6 +2,7 @@ package southbound
import (
spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
"github.com/openconfig/ygot/ygot"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
......@@ -22,5 +23,5 @@ type SouthboundInterface interface { // nolint
Schema() *ytypes.Schema
ID() uuid.UUID
Type() spb.Type
Unmarshal() func([]byte, []string, interface{}, ...ytypes.UnmarshalOpt) error
Unmarshal() func([]byte, []string, ygot.GoStruct, ...ytypes.UnmarshalOpt) error
}
......@@ -5,7 +5,6 @@ import (
spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/southbound"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/errors"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"github.com/google/uuid"
......@@ -68,39 +67,15 @@ func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path
// Unmarshal injects OpenConfig specific model representation to the transport.
// Needed for type assertion.
func (oc *OpenConfig) Unmarshal() func([]byte, []string, interface{}, ...ytypes.UnmarshalOpt) error {
func (oc *OpenConfig) Unmarshal() func([]byte, []string, ygot.GoStruct, ...ytypes.UnmarshalOpt) error {
return unmarshal
}
// unmarshal parses a root or 1st level gNMI response to a go struct
// Named return to return appropriate recover error
func unmarshal(bytes []byte, fields []string, goStruct interface{}, opt ...ytypes.UnmarshalOpt) (err error) {
defer func() {
if r := recover(); r != nil {
err = r.(error)
}
}()
switch l := len(fields); l {
case 0:
return openconfig.Unmarshal(bytes, goStruct.(*openconfig.Device), opt...)
case 1:
default:
return &errors.ErrUnsupportedPath{Path: fields}
}
var c ygot.GoStruct
var field string
// Load SBI definition
d := openconfig.Device{}
c, field, err = iter(&d, fields)
if err != nil {
return
}
if err = openconfig.Unmarshal(bytes, c, opt...); err != nil {
return
}
reflect.ValueOf(goStruct.(*openconfig.Device)).Elem().FieldByName(field).Set(reflect.ValueOf(c))
return nil
func unmarshal(bytes []byte, fields []string, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) (err error) {
ygot.BuildEmptyTree(goStruct)
return openconfig.Unmarshal(bytes, goStruct.(*openconfig.Device), opt...)
}
// iter walks down the provided paths and initializes the ygot.GoStruct. It only works for
......@@ -170,7 +145,7 @@ func (csbi *Csbi) SetNode() func(schema *yang.Entry, root interface{}, path *gpb
// Unmarshal injects OpenConfig specific model representation to the transport.
// Needed for type assertion.
func (csbi *Csbi) Unmarshal() func([]byte, []string, interface{}, ...ytypes.UnmarshalOpt) error {
func (csbi *Csbi) Unmarshal() func([]byte, []string, ygot.GoStruct, ...ytypes.UnmarshalOpt) error {
return unmarshal
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment