EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied buffer, and returns the final buffer.
(appendTo []byte, d *apd.Decimal)
| 870 | // EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied |
| 871 | // buffer, and returns the final buffer. |
| 872 | func EncodeUntaggedDecimalValue(appendTo []byte, d *apd.Decimal) []byte { |
| 873 | // To avoid the allocation, leave space for the varint, encode the decimal, |
| 874 | // encode the varint, and shift the encoded decimal to the end of the |
| 875 | // varint. |
| 876 | varintPos := len(appendTo) |
| 877 | // Manually append 10 (binary.MaxVarintLen64) 0s to avoid the allocation. |
| 878 | appendTo = append(appendTo, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
| 879 | decOffset := len(appendTo) |
| 880 | appendTo = EncodeNonsortingDecimal(appendTo, d) |
| 881 | decLen := len(appendTo) - decOffset |
| 882 | varintLen := binary.PutUvarint(appendTo[varintPos:decOffset], uint64(decLen)) |
| 883 | copy(appendTo[varintPos+varintLen:varintPos+varintLen+decLen], appendTo[decOffset:decOffset+decLen]) |
| 884 | return appendTo[:varintPos+varintLen+decLen] |
| 885 | } |
| 886 | |
| 887 | // DecodeValueTag decodes a value encoded by EncodeValueTag, used as a prefix in |
| 888 | // each of the other EncodeFooValue methods. |
no test coverage detected