MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / DecodeIntoNonsortingDecimal

Function DecodeIntoNonsortingDecimal

pkg/util/encoding/decimal.go:622–673  ·  view source on GitHub ↗

DecodeIntoNonsortingDecimal is like DecodeNonsortingDecimal, but it operates on the passed-in *apd.Decimal instead of producing a new one.

(dec *apd.Decimal, buf []byte, tmp []byte)

Source from the content-addressed store, hash-verified

620// DecodeIntoNonsortingDecimal is like DecodeNonsortingDecimal, but it operates
621// on the passed-in *apd.Decimal instead of producing a new one.
622func DecodeIntoNonsortingDecimal(dec *apd.Decimal, buf []byte, tmp []byte) error {
623 *dec = apd.Decimal{}
624 switch buf[0] {
625 case decimalNaN:
626 dec.Form = apd.NaN
627 return nil
628 case decimalNegativeInfinity:
629 dec.Form = apd.Infinite
630 dec.Negative = true
631 return nil
632 case decimalInfinity:
633 dec.Form = apd.Infinite
634 return nil
635 case decimalZero:
636 return nil
637 }
638
639 dec.Form = apd.Finite
640 switch {
641 case buf[0] == decimalNegLarge:
642 if err := decodeNonsortingDecimalValue(dec, false, buf[1:], tmp); err != nil {
643 return err
644 }
645 dec.Negative = true
646 return nil
647 case buf[0] == decimalNegMedium:
648 decodeNonsortingDecimalValueWithoutExp(dec, buf[1:], tmp)
649 dec.Negative = true
650 return nil
651 case buf[0] == decimalNegSmall:
652 if err := decodeNonsortingDecimalValue(dec, true, buf[1:], tmp); err != nil {
653 return err
654 }
655 dec.Negative = true
656 return nil
657 case buf[0] == decimalPosSmall:
658 if err := decodeNonsortingDecimalValue(dec, true, buf[1:], tmp); err != nil {
659 return err
660 }
661 return nil
662 case buf[0] == decimalPosMedium:
663 decodeNonsortingDecimalValueWithoutExp(dec, buf[1:], tmp)
664 return nil
665 case buf[0] == decimalPosLarge:
666 if err := decodeNonsortingDecimalValue(dec, false, buf[1:], tmp); err != nil {
667 return err
668 }
669 return nil
670 default:
671 return errors.Errorf("unknown decimal prefix of the encoded byte slice: %q", buf)
672 }
673}
674
675func decodeNonsortingDecimalValue(dec *apd.Decimal, negExp bool, buf, tmp []byte) error {
676 // Decode the exponent.

Callers 2

DecodeNonsortingDecimalFunction · 0.85

Calls 3

ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…