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

Function DecodeVarintAscending

pkg/util/encoding/encoding.go:282–311  ·  view source on GitHub ↗

DecodeVarintAscending decodes a value encoded by EncodeVaringAscending.

(b []byte)

Source from the content-addressed store, hash-verified

280
281// DecodeVarintAscending decodes a value encoded by EncodeVaringAscending.
282func DecodeVarintAscending(b []byte) ([]byte, int64, error) {
283 if len(b) == 0 {
284 return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value")
285 }
286 length := int(b[0]) - intZero
287 if length < 0 {
288 length = -length
289 remB := b[1:]
290 if len(remB) < length {
291 return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value: %q", remB)
292 }
293 var v int64
294 // Use the ones-complement of each encoded byte in order to build
295 // up a positive number, then take the ones-complement again to
296 // arrive at our negative value.
297 for _, t := range remB[:length] {
298 v = (v << 8) | int64(^t)
299 }
300 return remB[length:], ^v, nil
301 }
302
303 remB, v, err := DecodeUvarintAscending(b)
304 if err != nil {
305 return remB, 0, err
306 }
307 if v > math.MaxInt64 {
308 return nil, 0, errors.Errorf("varint %d overflows int64", v)
309 }
310 return remB, int64(v), nil
311}
312
313// DecodeVarintDescending decodes a uint64 value which was encoded
314// using EncodeVarintDescending.

Callers 5

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

Calls 1

DecodeUvarintAscendingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…