(bits int)
| 397 | } |
| 398 | |
| 399 | func uintDecoder(bits int) MapperFunc { //nolint: dupl |
| 400 | return func(ctx *DecodeContext, target reflect.Value) error { |
| 401 | t, err := ctx.Scan.PopValue("uint") |
| 402 | if err != nil { |
| 403 | return err |
| 404 | } |
| 405 | var sv string |
| 406 | switch v := t.Value.(type) { |
| 407 | case string: |
| 408 | sv = v |
| 409 | |
| 410 | case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: |
| 411 | sv = fmt.Sprintf("%v", v) |
| 412 | |
| 413 | case float32, float64: |
| 414 | sv = fmt.Sprintf("%0.f", v) |
| 415 | |
| 416 | default: |
| 417 | return fmt.Errorf("expected an int but got %q (%T)", t, t.Value) |
| 418 | } |
| 419 | n, err := strconv.ParseUint(sv, 0, bits) |
| 420 | if err != nil { |
| 421 | return fmt.Errorf("expected a valid %d bit uint but got %q", bits, sv) |
| 422 | } |
| 423 | target.SetUint(n) |
| 424 | return nil |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | func floatDecoder(bits int) MapperFunc { |
| 429 | return func(ctx *DecodeContext, target reflect.Value) error { |
no test coverage detected
searching dependent graphs…