()
| 304 | } |
| 305 | |
| 306 | func (d *decoder) readUnsignedVarInt() uint64 { |
| 307 | n := 11 // varints are at most 11 bytes |
| 308 | |
| 309 | if n > d.remain { |
| 310 | n = d.remain |
| 311 | } |
| 312 | |
| 313 | x := uint64(0) |
| 314 | s := uint(0) |
| 315 | |
| 316 | for n > 0 { |
| 317 | b := d.readByte() |
| 318 | |
| 319 | if (b & 0x80) == 0 { |
| 320 | x |= uint64(b) << s |
| 321 | return x |
| 322 | } |
| 323 | |
| 324 | x |= uint64(b&0x7f) << s |
| 325 | s += 7 |
| 326 | n-- |
| 327 | } |
| 328 | |
| 329 | d.setError(fmt.Errorf("cannot decode unsigned varint from input stream")) |
| 330 | return 0 |
| 331 | } |
| 332 | |
| 333 | type decodeFunc func(*decoder, value) |
| 334 |