1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-12-20 16:11:17 +00:00

Support parsing left out attributes

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-12-24 15:00:16 +01:00
parent b26ae0d691
commit a48a514570
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 10 additions and 2 deletions

View file

@ -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)

View file

@ -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