getVarintLen returns the encoded length of an encoded varint. Assumes the slice has at least one byte.
(b []byte)
| 259 | // getVarintLen returns the encoded length of an encoded varint. Assumes the |
| 260 | // slice has at least one byte. |
| 261 | func getVarintLen(b []byte) (int, error) { |
| 262 | length := int(b[0]) - intZero |
| 263 | if length >= 0 { |
| 264 | if length <= intSmall { |
| 265 | // just the tag |
| 266 | return 1, nil |
| 267 | } |
| 268 | // tag and length-intSmall bytes |
| 269 | length = 1 + length - intSmall |
| 270 | } else { |
| 271 | // tag and -length bytes |
| 272 | length = 1 - length |
| 273 | } |
| 274 | |
| 275 | if length > len(b) { |
| 276 | return 0, errors.Errorf("varint length %d exceeds slice length %d", length, len(b)) |
| 277 | } |
| 278 | return length, nil |
| 279 | } |
| 280 | |
| 281 | // DecodeVarintAscending decodes a value encoded by EncodeVaringAscending. |
| 282 | func DecodeVarintAscending(b []byte) ([]byte, int64, error) { |
no outgoing calls
no test coverage detected
searching dependent graphs…