1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-12-21 08:21:16 +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") 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 { if reflect.TypeOf(out).Kind() != reflect.Ptr {
return errors.New("Calling parser with non-pointer") return errors.New("Calling parser with non-pointer")
} }
@ -45,7 +45,7 @@ func genericUnmarshal(in []byte, out interface{}) error {
case reflect.TypeOf(Ptr{}): case reflect.TypeOf(Ptr{}):
data := getSingleValue(in, attributeName) data := getSingleValue(in, attributeName)
v := Ptr{} v := Ptr{unit: unit}
if err := v.UnmarshalSII(data); err != nil { if err := v.UnmarshalSII(data); err != nil {
return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName) 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{}): case reflect.TypeOf(Ptr{}):
var v []Ptr var v []Ptr
for _, bv := range ba { for _, bv := range ba {
e := Ptr{} e := Ptr{unit: unit}
if err := e.UnmarshalSII(bv); err != nil { if err := e.UnmarshalSII(bv); err != nil {
return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName) 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()) { if reflect.TypeOf(block).Implements(reflect.TypeOf((*Unmarshaler)(nil)).Elem()) {
err = block.(Unmarshaler).UnmarshalSII(blockContent) err = block.(Unmarshaler).UnmarshalSII(blockContent)
} else { } else {
err = genericUnmarshal(blockContent, block) err = genericUnmarshal(blockContent, block, unit)
} }
if err != nil { if err != nil {