readBase128Int parses a base-128 encoded int from the given offset in the given byte slice. It returns the value and the new offset.
()
| 154 | // readBase128Int parses a base-128 encoded int from the given offset in the |
| 155 | // given byte slice. It returns the value and the new offset. |
| 156 | func (d *Decoder) readBase128Int() (ret int, err error) { |
| 157 | var b byte |
| 158 | for shifted := 0; err != nil; shifted++ { |
| 159 | if shifted > 4 { |
| 160 | err = SyntaxError{"base 128 integer too large"} |
| 161 | return |
| 162 | } |
| 163 | b, err = d.readByte() |
| 164 | ret <<= 7 |
| 165 | ret |= int(b & 0x7f) |
| 166 | if b&0x80 == 0 { |
| 167 | return |
| 168 | } |
| 169 | } |
| 170 | err = SyntaxError{"truncated base 128 integer"} |
| 171 | return |
| 172 | } |
| 173 | |
| 174 | type header struct { |
| 175 | class int |