1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-10-18 05:14:19 +00:00

Add unit reference to pointers

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-11-10 15:03:08 +01:00
parent 74df37832e
commit 15b5c77be7
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 4 additions and 4 deletions

View file

@ -21,7 +21,7 @@ func genericMarshal(in interface{}) ([]byte, error) {
return nil, errors.New("Not implemented")
}
func genericUnmarshal(in []byte, out interface{}) error {
func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
if reflect.TypeOf(out).Kind() != reflect.Ptr {
return errors.New("Calling parser with non-pointer")
}
@ -45,7 +45,7 @@ func genericUnmarshal(in []byte, out interface{}) error {
case reflect.TypeOf(Ptr{}):
data := getSingleValue(in, attributeName)
v := Ptr{}
v := Ptr{unit: unit}
if err := v.UnmarshalSII(data); err != nil {
return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName)
}
@ -107,7 +107,7 @@ func genericUnmarshal(in []byte, out interface{}) error {
case reflect.TypeOf(Ptr{}):
var v []Ptr
for _, bv := range ba {
e := Ptr{}
e := Ptr{unit: unit}
if err := e.UnmarshalSII(bv); err != nil {
return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName)
}

View file

@ -129,7 +129,7 @@ func processBlock(unit *Unit, blockClass, blockName string, blockContent []byte)
if reflect.TypeOf(block).Implements(reflect.TypeOf((*Unmarshaler)(nil)).Elem()) {
err = block.(Unmarshaler).UnmarshalSII(blockContent)
} else {
err = genericUnmarshal(blockContent, block)
err = genericUnmarshal(blockContent, block, unit)
}
if err != nil {