Skip to content
Snippets Groups Projects
Commit 7021e873 authored by Neil Schark's avatar Neil Schark
Browse files

test commit

parent 4b1e153c
No related branches found
No related tags found
No related merge requests found
Pipeline #125392 failed
...@@ -122,42 +122,56 @@ func (oc *OpenConfig) Unmarshal(bytes []byte, path *gpb.Path, goStruct ygot.GoSt ...@@ -122,42 +122,56 @@ func (oc *OpenConfig) Unmarshal(bytes []byte, path *gpb.Path, goStruct ygot.GoSt
return unmarshal(oc.Schema(), bytes, path, goStruct, opt...) return unmarshal(oc.Schema(), bytes, path, goStruct, opt...)
} }
// unmarshal parses a gNMI response to a go struct. // Generates an empty validated struct from a given schema and path
func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) error { func generateEmptyValidatedStructs(schema *ytypes.Schema, path *gpb.Path) (ygot.ValidatedGoStruct, ygot.ValidatedGoStruct, error) {
defer func() {
if r := recover(); r != nil {
log.Error(r.(error))
}
}()
// Load SBI definition // Load SBI definition
root, err := ygot.DeepCopy(schema.Root) root, err := ygot.DeepCopy(schema.Root)
if err != nil { if err != nil {
return err return nil, nil, err
} }
validatedDeepCopy, ok := root.(ygot.ValidatedGoStruct) validatedDeepCopy, ok := root.(ygot.ValidatedGoStruct)
if !ok { if !ok {
return &customerrs.InvalidTypeAssertionError{ return nil, nil, &customerrs.InvalidTypeAssertionError{
Value: root, Value: root,
Type: (*ygot.ValidatedGoStruct)(nil), Type: (*ygot.ValidatedGoStruct)(nil),
} }
} }
// returns the node we want to fill with the data contained in 'bytes', // returns the node we want to fill with the data contained in 'bytes', using the specified 'path'.
// using the specified 'path'.
createdNode, _, err := ytypes.GetOrCreateNode(schema.RootSchema(), validatedDeepCopy, path) createdNode, _, err := ytypes.GetOrCreateNode(schema.RootSchema(), validatedDeepCopy, path)
if err != nil { if err != nil {
return err return nil, nil, err
} }
validatedCreatedNode, ok := createdNode.(ygot.ValidatedGoStruct) validatedCreatedNode, ok := createdNode.(ygot.ValidatedGoStruct)
if !ok { if !ok {
return &customerrs.InvalidTypeAssertionError{ return nil, nil, &customerrs.InvalidTypeAssertionError{
Value: createdNode, Value: createdNode,
Type: (*ygot.ValidatedGoStruct)(nil), Type: (*ygot.ValidatedGoStruct)(nil),
} }
} }
if err := openconfig.Unmarshal(bytes, validatedCreatedNode, opt...); err != nil { return validatedDeepCopy, validatedCreatedNode, nil
}
// unmarshal parses a gNMI response to a go struct.
func unmarshal(schema *ytypes.Schema, bytes []byte, path *gpb.Path, goStruct ygot.GoStruct, opt ...ytypes.UnmarshalOpt) error {
defer func() {
if r := recover(); r != nil {
log.Error(r.(error))
}
}()
validatedDeepCopy, emptyValidatedCreatedNode, err := generateEmptyValidatedStructs(schema, path)
if err != nil {
return err
}
_, emptyValidatedCreatedNodeForDiff, err := generateEmptyValidatedStructs(schema, path)
if err != nil {
return err
}
if err := openconfig.Unmarshal(bytes, emptyValidatedCreatedNode, opt...); err != nil {
return err return err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment