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