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

Function EncodeVarintAscending

pkg/util/encoding/encoding.go:306–332  ·  view source on GitHub ↗

EncodeVarintAscending encodes the int64 value using a variable length (length-prefixed) representation. The length is encoded as a single byte. If the value to be encoded is negative the length is encoded as 8-numBytes. If the value is positive it is encoded as 8+numBytes. The encoded bytes are appe

(b []byte, v int64)

Source from the content-addressed store, hash-verified

304// 8+numBytes. The encoded bytes are appended to the supplied buffer
305// and the final buffer is returned.
306func EncodeVarintAscending(b []byte, v int64) []byte {
307 if v < 0 {
308 switch {
309 case v >= -0xff:
310 return append(b, IntMin+7, byte(v))
311 case v >= -0xffff:
312 return append(b, IntMin+6, byte(v>>8), byte(v))
313 case v >= -0xffffff:
314 return append(b, IntMin+5, byte(v>>16), byte(v>>8), byte(v))
315 case v >= -0xffffffff:
316 return append(b, IntMin+4, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
317 case v >= -0xffffffffff:
318 return append(b, IntMin+3, byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8),
319 byte(v))
320 case v >= -0xffffffffffff:
321 return append(b, IntMin+2, byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16),
322 byte(v>>8), byte(v))
323 case v >= -0xffffffffffffff:
324 return append(b, IntMin+1, byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24),
325 byte(v>>16), byte(v>>8), byte(v))
326 default:
327 return append(b, IntMin, byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32),
328 byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
329 }
330 }
331 return EncodeUvarintAscending(b, uint64(v))
332}
333
334// EncodeVarintDescending encodes the int64 value so that it sorts in reverse
335// order, from largest to smallest.

Callers 5

EncodeVarintDescendingFunction · 0.85
encodeTimeFunction · 0.85
encodeTimeTZFunction · 0.85
EncodeDurationAscendingFunction · 0.85
EncodeJSONValueLengthFunction · 0.85

Calls 1

EncodeUvarintAscendingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…