diff --git a/genericMarshaller.go b/genericMarshaller.go index 995ae3f..b0f9c28 100644 --- a/genericMarshaller.go +++ b/genericMarshaller.go @@ -133,6 +133,16 @@ func genericMarshal(in interface{}) ([]byte, error) { } buf.Write(encodeSliceValue(attributeName, values)) + case reflect.Float32: + for _, val := range valField.Interface().([]float32) { + v, err := float2sii(val) + if err != nil { + return nil, errors.Wrap(err, "Unable to encode float32") + } + values = append(values, string(v)) + } + buf.Write(encodeSliceValue(attributeName, values)) + case reflect.Int: for _, val := range valField.Interface().([]int) { values = append(values, strconv.FormatInt(int64(val), 10)) diff --git a/genericUnmarshaller.go b/genericUnmarshaller.go index 14d5302..d9685b5 100644 --- a/genericUnmarshaller.go +++ b/genericUnmarshaller.go @@ -173,6 +173,17 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error { } valField.Set(reflect.ValueOf(v)) + case reflect.Float32: + var v []float32 + for _, bv := range ba { + pbv, err := sii2float(bv) + if err != nil { + return errors.Wrapf(err, "Unable to parse float32 for attribute %q", attributeName) + } + v = append(v, pbv) + } + valField.Set(reflect.ValueOf(v)) + case reflect.Int: var v []int for _, bv := range ba { diff --git a/helpers.go b/helpers.go index 70f5616..da4d48c 100644 --- a/helpers.go +++ b/helpers.go @@ -17,7 +17,7 @@ func float2sii(f float32) ([]byte, error) { err error ) - if math.Floor(float64(f)) == float64(f) { + if math.Floor(float64(f)) == float64(f) && f < 1000 { return []byte(fmt.Sprintf("%.0f", f)), nil }