MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / EncodeUntaggedDecimalValue

Function EncodeUntaggedDecimalValue

pkg/util/encoding/encoding.go:2735–2748  ·  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

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

Callers 2

encodeMethod · 0.92
EncodeDecimalValueFunction · 0.85

Calls 1

EncodeNonsortingDecimalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…