MCPcopy Create free account
hub / github.com/go-git/go-git / ReadVariableWidthInt

Function ReadVariableWidthInt

utils/binary/read.go:87–104  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

85// dheader[--pos] = 128 | (--ofs & 127);
86//
87func 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
106const (
107 maskContinue = uint8(128) // 1000 000

Callers 4

doReadEntryNameV4Method · 0.92
nextObjectHeaderMethod · 0.92

Calls 1

ReadFunction · 0.85

Tested by 2