EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied buffer, and returns the final buffer.
(appendTo []byte, d *apd.Decimal)
| 2733 | // EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied |
| 2734 | // buffer, and returns the final buffer. |
| 2735 | func EncodeUntaggedDecimalValue(appendTo []byte, d *apd.Decimal) []byte { |
| 2736 | // To avoid the allocation, leave space for the varint, encode the decimal, |
| 2737 | // encode the varint, and shift the encoded decimal to the end of the |
| 2738 | // varint. |
| 2739 | varintPos := len(appendTo) |
| 2740 | // Manually append 10 (binary.MaxVarintLen64) 0s to avoid the allocation. |
| 2741 | appendTo = append(appendTo, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
| 2742 | decOffset := len(appendTo) |
| 2743 | appendTo = EncodeNonsortingDecimal(appendTo, d) |
| 2744 | decLen := len(appendTo) - decOffset |
| 2745 | varintLen := binary.PutUvarint(appendTo[varintPos:decOffset], uint64(decLen)) |
| 2746 | copy(appendTo[varintPos+varintLen:varintPos+varintLen+decLen], appendTo[decOffset:decOffset+decLen]) |
| 2747 | return appendTo[:varintPos+varintLen+decLen] |
| 2748 | } |
| 2749 | |
| 2750 | // EncodeDurationValue encodes a duration.Duration value with its value tag, |
| 2751 | // appends it to the supplied buffer, and returns the final buffer. |
no test coverage detected
searching dependent graphs…