DecodeUvarintAscending decodes a uint64 encoded uint64 from the input buffer. The remainder of the input buffer and the decoded uint64 are returned.
(b []byte)
| 556 | // buffer. The remainder of the input buffer and the decoded uint64 |
| 557 | // are returned. |
| 558 | func DecodeUvarintAscending(b []byte) ([]byte, uint64, error) { |
| 559 | if len(b) == 0 { |
| 560 | return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value") |
| 561 | } |
| 562 | length := int(b[0]) - intZero |
| 563 | b = b[1:] // skip length byte |
| 564 | if length <= intSmall { |
| 565 | return b, uint64(length), nil |
| 566 | } |
| 567 | length -= intSmall |
| 568 | if length < 0 || length > 8 { |
| 569 | return nil, 0, errors.Errorf("invalid uvarint length of %d", length) |
| 570 | } else if len(b) < length { |
| 571 | return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value: %q", b) |
| 572 | } |
| 573 | var v uint64 |
| 574 | // It is faster to range over the elements in a slice than to index |
| 575 | // into the slice on each loop iteration. |
| 576 | for _, t := range b[:length] { |
| 577 | v = (v << 8) | uint64(t) |
| 578 | } |
| 579 | return b[length:], v, nil |
| 580 | } |
| 581 | |
| 582 | // DecodeUvarintDescending decodes a uint64 value which was encoded |
| 583 | // using EncodeUvarintDescending. |
no test coverage detected
searching dependent graphs…