EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied buffer, and returns the final buffer.
(appendTo []byte, d *apd.Decimal)
| 1931 | // EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied |
| 1932 | // buffer, and returns the final buffer. |
| 1933 | func EncodeUntaggedDecimalValue(appendTo []byte, d *apd.Decimal) []byte { |
| 1934 | // To avoid the allocation, leave space for the varint, encode the decimal, |
| 1935 | // encode the varint, and shift the encoded decimal to the end of the |
| 1936 | // varint. |
| 1937 | varintPos := len(appendTo) |
| 1938 | // Manually append 10 (binary.MaxVarintLen64) 0s to avoid the allocation. |
| 1939 | appendTo = append(appendTo, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
| 1940 | decOffset := len(appendTo) |
| 1941 | appendTo = EncodeNonsortingDecimal(appendTo, d) |
| 1942 | decLen := len(appendTo) - decOffset |
| 1943 | varintLen := binary.PutUvarint(appendTo[varintPos:decOffset], uint64(decLen)) |
| 1944 | copy(appendTo[varintPos+varintLen:varintPos+varintLen+decLen], appendTo[decOffset:decOffset+decLen]) |
| 1945 | return appendTo[:varintPos+varintLen+decLen] |
| 1946 | } |
| 1947 | |
| 1948 | // EncodeDurationValue encodes a duration.Duration value with its value tag, |
| 1949 | // appends it to the supplied buffer, and returns the final buffer. |
no test coverage detected
searching dependent graphs…