getVarintLen returns the encoded length of an encoded varint. Assumes the slice has at least one byte.
(b []byte)
| 340 | // getVarintLen returns the encoded length of an encoded varint. Assumes the |
| 341 | // slice has at least one byte. |
| 342 | func getVarintLen(b []byte) (int, error) { |
| 343 | length := int(b[0]) - intZero |
| 344 | if length >= 0 { |
| 345 | if length <= intSmall { |
| 346 | // just the tag |
| 347 | return 1, nil |
| 348 | } |
| 349 | // tag and length-intSmall bytes |
| 350 | length = 1 + length - intSmall |
| 351 | } else { |
| 352 | // tag and -length bytes |
| 353 | length = 1 - length |
| 354 | } |
| 355 | |
| 356 | if length > len(b) { |
| 357 | return 0, errors.Errorf("varint length %d exceeds slice length %d", length, len(b)) |
| 358 | } |
| 359 | return length, nil |
| 360 | } |
| 361 | |
| 362 | // DecodeVarintAscending decodes a value encoded by EncodeVarintAscending. |
| 363 | func DecodeVarintAscending(b []byte) ([]byte, int64, error) { |
no test coverage detected
searching dependent graphs…