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