ReadVariableWidthInt reads and returns an int in Git VLQ special format: Ordinary VLQ has some redundancies, example: the number 358 can be encoded as the 2-octet VLQ 0x8166 or the 3-octet VLQ 0x808166 or the 4-octet VLQ 0x80808166 and so forth. To avoid these redundancies, the VLQ format used in
(r io.Reader)
| 85 | // dheader[--pos] = 128 | (--ofs & 127); |
| 86 | // |
| 87 | func ReadVariableWidthInt(r io.Reader) (int64, error) { |
| 88 | var c byte |
| 89 | if err := Read(r, &c); err != nil { |
| 90 | return 0, err |
| 91 | } |
| 92 | |
| 93 | var v = int64(c & maskLength) |
| 94 | for c&maskContinue > 0 { |
| 95 | v++ |
| 96 | if err := Read(r, &c); err != nil { |
| 97 | return 0, err |
| 98 | } |
| 99 | |
| 100 | v = (v << lengthBits) + int64(c&maskLength) |
| 101 | } |
| 102 | |
| 103 | return v, nil |
| 104 | } |
| 105 | |
| 106 | const ( |
| 107 | maskContinue = uint8(128) // 1000 000 |