Skip to content

Commit

Permalink
Type check
Browse files Browse the repository at this point in the history
  • Loading branch information
2tvenom committed Mar 16, 2014
1 parent efec77f commit c2959e5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,25 @@ func (encoder *cborEncode) decode(v reflect.Value) (bool, error) {
case majorTypeSimpleAndFloat:
switch headerAdditionInfo {
case additionalTypeIntFalse:
if v.Kind() != reflect.Bool {
return false, fmt.Errorf("Can convert %s to bool", v.Type())
}
v.Set(reflect.ValueOf(false))
return true, nil
case additionalTypeIntTrue:
if v.Kind() != reflect.Bool {
return false, fmt.Errorf("Can convert %s to bool", v.Type())
}
v.Set(reflect.ValueOf(true))
return true, nil
case additionalTypeIntNull:
return true, nil
case additionalTypeFloat16:
return true, fmt.Errorf("Float16 decode not support")
case additionalTypeFloat32:
if v.Kind() != reflect.Float32 {
return false, fmt.Errorf("Can convert %s to float32", v.Type())
}
var out float32
err := unpack(buff, &out)

Expand All @@ -311,7 +320,11 @@ func (encoder *cborEncode) decode(v reflect.Value) (bool, error) {

return true, nil
case additionalTypeFloat64:
if v.Kind() != reflect.Float64 {
return false, fmt.Errorf("Can convert %s to float64", v.Type())
}
var out float64

err := unpack(buff, &out)

if err != nil {
Expand Down

0 comments on commit c2959e5

Please sign in to comment.