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

Function encodeMediumNumber

pkg/util/encoding/decimal.go:224–240  ·  view source on GitHub ↗

encodeMediumNumber encodes the exponent and mantissa into a buffer, only used when the exponent is in [0, 10]. The encoding must fit in encInto. The mantissa m can overlap with encInto. Returns the length-adjusted buffer.

(negative bool, e int, m []byte, encInto []byte)

Source from the content-addressed store, hash-verified

222//
223// Returns the length-adjusted buffer.
224func encodeMediumNumber(negative bool, e int, m []byte, encInto []byte) []byte {
225 l := 1 + len(m)
226 if len(encInto) < l+1 {
227 panic("buffer too short")
228 }
229 // Because m can overlap with encInto, we must first copy m to the right place
230 // before modifying encInto.
231 copy(encInto[1:], m)
232 if negative {
233 encInto[0] = decimalNegMedium - byte(e)
234 onesComplement(encInto[1:l])
235 } else {
236 encInto[0] = decimalPosMedium + byte(e)
237 }
238 encInto[l] = decimalTerminator
239 return encInto[:l+1]
240}
241
242// DecodeDecimalAscending returns the remaining byte slice after decoding and the decoded
243// decimal from buf.

Callers 1

encodeEandMFunction · 0.85

Calls 1

onesComplementFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…