DecodeVarintAscending decodes a value encoded by EncodeVarintAscending.
(b []byte)
| 361 | |
| 362 | // DecodeVarintAscending decodes a value encoded by EncodeVarintAscending. |
| 363 | func 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. |
no test coverage detected
searching dependent graphs…