(bits int)
| 368 | } |
| 369 | |
| 370 | func intDecoder(bits int) MapperFunc { //nolint: dupl |
| 371 | return func(ctx *DecodeContext, target reflect.Value) error { |
| 372 | t, err := ctx.Scan.PopValue("int") |
| 373 | if err != nil { |
| 374 | return err |
| 375 | } |
| 376 | var sv string |
| 377 | switch v := t.Value.(type) { |
| 378 | case string: |
| 379 | sv = v |
| 380 | |
| 381 | case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: |
| 382 | sv = fmt.Sprintf("%v", v) |
| 383 | |
| 384 | case float32, float64: |
| 385 | sv = fmt.Sprintf("%0.f", v) |
| 386 | |
| 387 | default: |
| 388 | return fmt.Errorf("expected an int but got %q (%T)", t, t.Value) |
| 389 | } |
| 390 | n, err := strconv.ParseInt(sv, 0, bits) |
| 391 | if err != nil { |
| 392 | return fmt.Errorf("expected a valid %d bit int but got %q", bits, sv) |
| 393 | } |
| 394 | target.SetInt(n) |
| 395 | return nil |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | func uintDecoder(bits int) MapperFunc { //nolint: dupl |
| 400 | return func(ctx *DecodeContext, target reflect.Value) error { |
no test coverage detected
searching dependent graphs…