From a48a51457013b61b037de3f30a692eb3bf8678fa Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 24 Dec 2019 15:00:16 +0100 Subject: [PATCH] Support parsing left out attributes Signed-off-by: Knut Ahlers --- genericUnmarshaller.go | 8 ++++++-- helpers.go | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/genericUnmarshaller.go b/genericUnmarshaller.go index 4e3c3fd..30d0574 100644 --- a/genericUnmarshaller.go +++ b/genericUnmarshaller.go @@ -85,7 +85,7 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error { case reflect.Int, reflect.Int64: bv := getSingleValue(in, attributeName) - if isNilValue(bv) { + if isNilValue(bv) || len(bv) == 0 { continue } v, err := strconv.ParseInt(string(bv), 10, 64) @@ -164,7 +164,7 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error { case reflect.Int64: bv := getSingleValue(in, attributeName) - if !isNilValue(bv) { + if !isNilValue(bv) && len(bv) > 0 { v, err := strconv.ParseInt(string(bv), 10, 64) if err != nil { return errors.Wrapf(err, "Unable to parse int for attribute %q", attributeName) @@ -260,6 +260,10 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error { case reflect.Int64: var v []int64 for _, bv := range ba { + if len(bv) == 0 { + v = append(v, 0) + continue + } pbv, err := strconv.ParseInt(string(bv), 10, 64) if err != nil { return errors.Wrapf(err, "Unable to parse int for attribute %q", attributeName) diff --git a/helpers.go b/helpers.go index 83d530d..a34aa77 100644 --- a/helpers.go +++ b/helpers.go @@ -33,6 +33,10 @@ func float2sii(f float32) ([]byte, error) { } func sii2float(f []byte) (float32, error) { + if len(f) == 0 { + return 0, nil + } + if f[0] != '&' { out, err := strconv.ParseFloat(string(f), 32) return float32(out), err