Skip to content

Commit

Permalink
Handle various uint/int types
Browse files Browse the repository at this point in the history
Needed after change to go-ole Value() method.
  • Loading branch information
maddyblue committed Mar 10, 2015
1 parent a18616e commit 9d56c56
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,8 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat
defer prop.Clear()

switch val := prop.Value().(type) {
case int, int64:
var v int64
switch val := val.(type) {
case int:
v = int64(val)
case int64:
v = val
default:
panic("unexpected type")
}
case int8, int16, int32, int64, int:
v := reflect.ValueOf(val).Int()
switch f.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
f.SetInt(v)
Expand All @@ -282,6 +274,20 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat
Reason: "not an integer class",
}
}
case uint8, uint16, uint32, uint64:
v := reflect.ValueOf(val).Uint()
switch f.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
f.SetInt(int64(v))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
f.SetUint(v)
default:
return &ErrFieldMismatch{
StructType: of.Type(),
FieldName: n,
Reason: "not an integer class",
}
}
case string:
iv, err := strconv.ParseInt(val, 10, 64)
switch f.Kind() {
Expand Down

0 comments on commit 9d56c56

Please sign in to comment.