MCPcopy
hub / github.com/alecthomas/kong / uintDecoder

Function uintDecoder

mapper.go:399–426  ·  view source on GitHub ↗
(bits int)

Source from the content-addressed store, hash-verified

397}
398
399func 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
428func floatDecoder(bits int) MapperFunc {
429 return func(ctx *DecodeContext, target reflect.Value) error {

Callers 1

RegisterDefaultsMethod · 0.85

Calls 2

PopValueMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…