MCPcopy
hub / github.com/jackc/pgx / Scan

Method Scan

pgtype/numeric.go:602–706  ·  view source on GitHub ↗
(src []byte, dst any)

Source from the content-addressed store, hash-verified

600type scanPlanBinaryNumericToNumericScanner struct{}
601
602func (scanPlanBinaryNumericToNumericScanner) Scan(src []byte, dst any) error {
603 scanner := (dst).(NumericScanner)
604
605 if src == nil {
606 return scanner.ScanNumeric(Numeric{})
607 }
608
609 if len(src) < 8 {
610 return fmt.Errorf("numeric incomplete %v", src)
611 }
612
613 rp := 0
614 ndigits := binary.BigEndian.Uint16(src[rp:])
615 rp += 2
616 weight := int16(binary.BigEndian.Uint16(src[rp:]))
617 rp += 2
618 sign := binary.BigEndian.Uint16(src[rp:])
619 rp += 2
620 dscale := int16(binary.BigEndian.Uint16(src[rp:]))
621 rp += 2
622
623 switch sign {
624 case pgNumericNaNSign:
625 return scanner.ScanNumeric(Numeric{NaN: true, Valid: true})
626 case pgNumericPosInfSign:
627 return scanner.ScanNumeric(Numeric{InfinityModifier: Infinity, Valid: true})
628 case pgNumericNegInfSign:
629 return scanner.ScanNumeric(Numeric{InfinityModifier: NegativeInfinity, Valid: true})
630 }
631
632 if ndigits == 0 {
633 return scanner.ScanNumeric(Numeric{Int: big.NewInt(0), Valid: true})
634 }
635
636 if len(src[rp:]) < int(ndigits)*2 {
637 return fmt.Errorf("numeric incomplete %v", src)
638 }
639
640 accum := &big.Int{}
641
642 for i := 0; i < int(ndigits+3)/4; i++ {
643 int64accum, bytesRead, digitsRead := nbaseDigitsToInt64(src[rp:])
644 rp += bytesRead
645
646 if i > 0 {
647 var mul *big.Int
648 switch digitsRead {
649 case 1:
650 mul = bigNBase
651 case 2:
652 mul = bigNBaseX2
653 case 3:
654 mul = bigNBaseX3
655 case 4:
656 mul = bigNBaseX4
657 default:
658 return fmt.Errorf("invalid digitsRead: %d (this can't happen)", digitsRead)
659 }

Callers

nothing calls this directly

Calls 4

nbaseDigitsToInt64Function · 0.85
Uint16Method · 0.80
SetMethod · 0.80
ScanNumericMethod · 0.65

Tested by

no test coverage detected