DecodeUvarintAscending decodes a varint encoded uint64 from the input buffer. The remainder of the input buffer and the decoded uint64 are returned.
(b []byte)
| 425 | // buffer. The remainder of the input buffer and the decoded uint64 |
| 426 | // are returned. |
| 427 | func DecodeUvarintAscending(b []byte) ([]byte, uint64, error) { |
| 428 | if len(b) == 0 { |
| 429 | return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value") |
| 430 | } |
| 431 | length := int(b[0]) - intZero |
| 432 | b = b[1:] // skip length byte |
| 433 | if length <= intSmall { |
| 434 | return b, uint64(length), nil |
| 435 | } |
| 436 | length -= intSmall |
| 437 | if length < 0 || length > 8 { |
| 438 | return nil, 0, errors.Errorf("invalid uvarint length of %d", length) |
| 439 | } else if len(b) < length { |
| 440 | return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value: %q", b) |
| 441 | } |
| 442 | var v uint64 |
| 443 | // It is faster to range over the elements in a slice than to index |
| 444 | // into the slice on each loop iteration. |
| 445 | for _, t := range b[:length] { |
| 446 | v = (v << 8) | uint64(t) |
| 447 | } |
| 448 | return b[length:], v, nil |
| 449 | } |
| 450 | |
| 451 | // DecodeUvarintDescending decodes a uint64 value which was encoded |
| 452 | // using EncodeUvarintDescending. |
no outgoing calls
no test coverage detected
searching dependent graphs…