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

Function DecodeVarintAscending

pkg/util/encoding/encoding.go:363–392  ·  view source on GitHub ↗

DecodeVarintAscending decodes a value encoded by EncodeVarintAscending.

(b []byte)

Source from the content-addressed store, hash-verified

361
362// DecodeVarintAscending decodes a value encoded by EncodeVarintAscending.
363func DecodeVarintAscending(b []byte) ([]byte, int64, error) {
364 if len(b) == 0 {
365 return nil, 0, errors.Errorf("insufficient bytes to decode varint value")
366 }
367 length := int(b[0]) - intZero
368 if length < 0 {
369 length = -length
370 remB := b[1:]
371 if len(remB) < length {
372 return nil, 0, errors.Errorf("insufficient bytes to decode varint value: %q", remB)
373 }
374 var v int64
375 // Use the ones-complement of each encoded byte in order to build
376 // up a positive number, then take the ones-complement again to
377 // arrive at our negative value.
378 for _, t := range remB[:length] {
379 v = (v << 8) | int64(^t)
380 }
381 return remB[length:], ^v, nil
382 }
383
384 remB, v, err := DecodeUvarintAscending(b)
385 if err != nil {
386 return remB, 0, err
387 }
388 if v > math.MaxInt64 {
389 return nil, 0, errors.Errorf("varint %d overflows int64", v)
390 }
391 return remB, int64(v), nil
392}
393
394// DecodeVarintDescending decodes a int64 value which was encoded
395// using EncodeVarintDescending.

Callers 6

DecodeVarintDescendingFunction · 0.85
decodeTimeFunction · 0.85
decodeTimeTZFunction · 0.85
DecodeDurationAscendingFunction · 0.85
prettyPrintFirstValueFunction · 0.85
DecodeJSONValueLengthFunction · 0.85

Calls 2

DecodeUvarintAscendingFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…