MCPcopy Create free account
hub / github.com/dolthub/doltgresql / EncodeUntaggedDecimalValue

Function EncodeUntaggedDecimalValue

postgres/parser/encoding/encoding.go:872–885  ·  view source on GitHub ↗

EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied buffer, and returns the final buffer.

(appendTo []byte, d *apd.Decimal)

Source from the content-addressed store, hash-verified

870// EncodeUntaggedDecimalValue encodes an apd.Decimal value, appends it to the supplied
871// buffer, and returns the final buffer.
872func 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.

Callers 1

encodeMethod · 0.92

Calls 1

EncodeNonsortingDecimalFunction · 0.85

Tested by

no test coverage detected