getDecimalLen returns the length of an encoded decimal.
(buf []byte)
| 319 | |
| 320 | // getDecimalLen returns the length of an encoded decimal. |
| 321 | func 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. |
no test coverage detected
searching dependent graphs…