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

Function getDecimalLen

pkg/util/encoding/decimal.go:321–344  ·  view source on GitHub ↗

getDecimalLen returns the length of an encoded decimal.

(buf []byte)

Source from the content-addressed store, hash-verified

319
320// getDecimalLen returns the length of an encoded decimal.
321func getDecimalLen(buf []byte) (int, error) {
322 m := buf[0]
323 p := 1
324 if m < decimalNaN || m > decimalNaNDesc {
325 panic(fmt.Errorf("invalid tag %d", m))
326 }
327 switch m {
328 case decimalNaN, decimalNegativeInfinity, decimalNaNDesc, decimalInfinity, decimalZero:
329 return 1, nil
330 case decimalNegLarge, decimalNegSmall, decimalPosLarge, decimalPosSmall:
331 // Skip the varint exponent.
332 l, err := getVarintLen(buf[p:])
333 if err != nil {
334 return 0, err
335 }
336 p += l
337 }
338
339 idx, err := findDecimalTerminator(buf[p:])
340 if err != nil {
341 return 0, err
342 }
343 return p + idx + 1, nil
344}
345
346// makeDecimalFromMandE reconstructs the decimal from the mantissa M and
347// exponent E.

Callers 1

PeekLengthFunction · 0.85

Calls 3

getVarintLenFunction · 0.85
findDecimalTerminatorFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…