DecodeVarintAscending decodes a value encoded by EncodeVaringAscending.
(b []byte)
| 280 | |
| 281 | // DecodeVarintAscending decodes a value encoded by EncodeVaringAscending. |
| 282 | func DecodeVarintAscending(b []byte) ([]byte, int64, error) { |
| 283 | if len(b) == 0 { |
| 284 | return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value") |
| 285 | } |
| 286 | length := int(b[0]) - intZero |
| 287 | if length < 0 { |
| 288 | length = -length |
| 289 | remB := b[1:] |
| 290 | if len(remB) < length { |
| 291 | return nil, 0, errors.Errorf("insufficient bytes to decode uvarint value: %q", remB) |
| 292 | } |
| 293 | var v int64 |
| 294 | // Use the ones-complement of each encoded byte in order to build |
| 295 | // up a positive number, then take the ones-complement again to |
| 296 | // arrive at our negative value. |
| 297 | for _, t := range remB[:length] { |
| 298 | v = (v << 8) | int64(^t) |
| 299 | } |
| 300 | return remB[length:], ^v, nil |
| 301 | } |
| 302 | |
| 303 | remB, v, err := DecodeUvarintAscending(b) |
| 304 | if err != nil { |
| 305 | return remB, 0, err |
| 306 | } |
| 307 | if v > math.MaxInt64 { |
| 308 | return nil, 0, errors.Errorf("varint %d overflows int64", v) |
| 309 | } |
| 310 | return remB, int64(v), nil |
| 311 | } |
| 312 | |
| 313 | // DecodeVarintDescending decodes a uint64 value which was encoded |
| 314 | // using EncodeVarintDescending. |
no test coverage detected
searching dependent graphs…