mirror of
https://github.com/Luzifer/sii.git
synced 2024-10-18 05:14:19 +00:00
Support parsing left out attributes
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
b26ae0d691
commit
a48a514570
2 changed files with 10 additions and 2 deletions
|
@ -85,7 +85,7 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
|
||||||
|
|
||||||
case reflect.Int, reflect.Int64:
|
case reflect.Int, reflect.Int64:
|
||||||
bv := getSingleValue(in, attributeName)
|
bv := getSingleValue(in, attributeName)
|
||||||
if isNilValue(bv) {
|
if isNilValue(bv) || len(bv) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
v, err := strconv.ParseInt(string(bv), 10, 64)
|
v, err := strconv.ParseInt(string(bv), 10, 64)
|
||||||
|
@ -164,7 +164,7 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
|
||||||
|
|
||||||
case reflect.Int64:
|
case reflect.Int64:
|
||||||
bv := getSingleValue(in, attributeName)
|
bv := getSingleValue(in, attributeName)
|
||||||
if !isNilValue(bv) {
|
if !isNilValue(bv) && len(bv) > 0 {
|
||||||
v, err := strconv.ParseInt(string(bv), 10, 64)
|
v, err := strconv.ParseInt(string(bv), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Unable to parse int for attribute %q", attributeName)
|
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:
|
case reflect.Int64:
|
||||||
var v []int64
|
var v []int64
|
||||||
for _, bv := range ba {
|
for _, bv := range ba {
|
||||||
|
if len(bv) == 0 {
|
||||||
|
v = append(v, 0)
|
||||||
|
continue
|
||||||
|
}
|
||||||
pbv, err := strconv.ParseInt(string(bv), 10, 64)
|
pbv, err := strconv.ParseInt(string(bv), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Unable to parse int for attribute %q", attributeName)
|
return errors.Wrapf(err, "Unable to parse int for attribute %q", attributeName)
|
||||||
|
|
|
@ -33,6 +33,10 @@ func float2sii(f float32) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func sii2float(f []byte) (float32, error) {
|
func sii2float(f []byte) (float32, error) {
|
||||||
|
if len(f) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
if f[0] != '&' {
|
if f[0] != '&' {
|
||||||
out, err := strconv.ParseFloat(string(f), 32)
|
out, err := strconv.ParseFloat(string(f), 32)
|
||||||
return float32(out), err
|
return float32(out), err
|
||||||
|
|
Loading…
Reference in a new issue