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