(bits int)
| 430 | } |
| 431 | |
| 432 | func floatDecoder(bits int) MapperFunc { |
| 433 | return func(ctx *DecodeContext, target reflect.Value) error { |
| 434 | t, err := ctx.Scan.PopValue("float") |
| 435 | if err != nil { |
| 436 | return err |
| 437 | } |
| 438 | switch v := t.Value.(type) { |
| 439 | case string: |
| 440 | n, err := strconv.ParseFloat(v, bits) |
| 441 | if err != nil { |
| 442 | return fmt.Errorf("expected a float but got %q (%T)", t, t.Value) |
| 443 | } |
| 444 | target.SetFloat(n) |
| 445 | |
| 446 | case float32: |
| 447 | target.SetFloat(float64(v)) |
| 448 | |
| 449 | case float64: |
| 450 | target.SetFloat(v) |
| 451 | |
| 452 | case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: |
| 453 | target.SetFloat(reflect.ValueOf(v).Convert(reflect.TypeOf(float64(0))).Float()) |
| 454 | |
| 455 | default: |
| 456 | return fmt.Errorf("expected a float but got %q (%T)", t, t.Value) |
| 457 | } |
| 458 | return nil |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | func mapDecoder(r *Registry) MapperFunc { |
| 463 | return func(ctx *DecodeContext, target reflect.Value) error { |
no test coverage detected