mirror of
https://github.com/Luzifer/sii.git
synced 2024-12-21 00:21:15 +00:00
Support nil values in ints and RawValue unmarshalling
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
a061da28b0
commit
a40e9a5c6e
1 changed files with 22 additions and 2 deletions
|
@ -79,7 +79,11 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
|
||||||
valField.Set(reflect.ValueOf(v))
|
valField.Set(reflect.ValueOf(v))
|
||||||
|
|
||||||
case reflect.Int, reflect.Int64:
|
case reflect.Int, reflect.Int64:
|
||||||
v, err := strconv.ParseInt(string(getSingleValue(in, attributeName)), 10, 64)
|
bv := getSingleValue(in, attributeName)
|
||||||
|
if isNilValue(bv) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
@ -121,7 +125,19 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
|
||||||
for _, bv := range ba {
|
for _, bv := range ba {
|
||||||
e := Placement{}
|
e := Placement{}
|
||||||
if err := e.UnmarshalSII(bv); err != nil {
|
if err := e.UnmarshalSII(bv); err != nil {
|
||||||
return errors.Wrapf(err, "Unable to parse Ptr for attribute %q", attributeName)
|
return errors.Wrapf(err, "Unable to parse Placement for attribute %q", attributeName)
|
||||||
|
}
|
||||||
|
v = append(v, e)
|
||||||
|
}
|
||||||
|
valField.Set(reflect.ValueOf(v))
|
||||||
|
continue
|
||||||
|
|
||||||
|
case reflect.TypeOf(RawValue{}):
|
||||||
|
var v []RawValue
|
||||||
|
for _, bv := range ba {
|
||||||
|
e := RawValue{}
|
||||||
|
if err := e.UnmarshalSII(bv); err != nil {
|
||||||
|
return errors.Wrapf(err, "Unable to parse RawValue for attribute %q", attributeName)
|
||||||
}
|
}
|
||||||
v = append(v, e)
|
v = append(v, e)
|
||||||
}
|
}
|
||||||
|
@ -229,3 +245,7 @@ func getArrayValues(in []byte, name string) ([][]byte, error) {
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isNilValue(in []byte) bool {
|
||||||
|
return reflect.DeepEqual(in, []byte("nil"))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue