diff --git a/genericMarshaller.go b/genericMarshaller.go index d30d83f..26e61ad 100644 --- a/genericMarshaller.go +++ b/genericMarshaller.go @@ -199,6 +199,51 @@ func genericMarshal(in interface{}) ([]byte, error) { } buf.Write(encodeSliceValue(attributeName, values)) + case reflect.Array: + + switch typeField.Type.Elem().Elem().Kind() { + + case reflect.Float32: + switch typeField.Type.Elem().Len() { + + case 3: + for _, val := range valField.Interface().([][3]float32) { + var vals [][]byte + for _, v := range val { + bv, err := float2sii(v) + if err != nil { + return nil, errors.Wrap(err, "Unable to encode float32") + } + vals = append(vals, bv) + } + values = append(values, fmt.Sprintf("(%s)", bytes.Join(vals, []byte(", ")))) + } + + case 4: + for _, val := range valField.Interface().([][4]float32) { + var vals [][]byte + for _, v := range val { + bv, err := float2sii(v) + if err != nil { + return nil, errors.Wrap(err, "Unable to encode float32") + } + vals = append(vals, bv) + } + values = append(values, fmt.Sprintf("(%s; %s)", vals[0], bytes.Join(vals[1:], []byte(", ")))) + } + + default: + return nil, errors.Errorf("Unsupported len of type: [][%d]%s", typeField.Type.Elem().Len(), typeField.Type.Elem().Elem().Kind()) + + } + + default: + return nil, errors.Errorf("Unsupported type: [][%d]%s", typeField.Type.Elem().Len(), typeField.Type.Elem().Elem().Kind()) + + } + + buf.Write(encodeSliceValue(attributeName, values)) + default: return nil, errors.Errorf("Unsupported type: []%s", typeField.Type.Elem().Kind()) diff --git a/genericUnmarshaller.go b/genericUnmarshaller.go index 46ab90b..69a83a3 100644 --- a/genericUnmarshaller.go +++ b/genericUnmarshaller.go @@ -253,6 +253,59 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error { } valField.Set(reflect.ValueOf(v)) + case reflect.Array: + + switch typeField.Type.Elem().Elem().Kind() { + + case reflect.Float32: + switch typeField.Type.Elem().Len() { + + case 3: + var v [][3]float32 + for _, bv := range ba { + grps := regexp.MustCompile(`^\(([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+)\)$`). + FindSubmatch(bv) + var sv [3]float32 + + for i := range sv { + val, err := sii2float(grps[i+1][:]) + if err != nil { + return errors.Wrapf(err, "Unable to parse float32 for attribute %q", attributeName) + } + sv[i] = val + } + v = append(v, sv) + } + valField.Set(reflect.ValueOf(v)) + + case 4: + var v [][4]float32 + for _, bv := range ba { + grps := regexp.MustCompile(`^\(([0-9.-]+|&[0-9a-f]+); ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+)\)$`). + FindSubmatch(bv) + var sv [4]float32 + + for i := range sv { + val, err := sii2float(grps[i+1][:]) + if err != nil { + return errors.Wrapf(err, "Unable to parse float32 for attribute %q", attributeName) + } + sv[i] = val + } + v = append(v, sv) + } + valField.Set(reflect.ValueOf(v)) + + default: + return errors.Errorf("Unsupported len of type: [][%d]%s", typeField.Type.Elem().Len(), typeField.Type.Elem().Elem().Kind()) + + } + + default: + return errors.Errorf("Unsupported type: [][%d]%s", typeField.Type.Elem().Len(), typeField.Type.Elem().Elem().Kind()) + + } + default: return errors.Errorf("Unsupported type: []%s", typeField.Type.Elem().Kind()) }