(data []byte)
| 67 | } |
| 68 | |
| 69 | func VarInt(data []byte) (int32, []byte, error) { |
| 70 | var ( |
| 71 | position int |
| 72 | currentByte byte |
| 73 | |
| 74 | value int32 |
| 75 | ) |
| 76 | |
| 77 | for { |
| 78 | if len(data) == 0 { |
| 79 | return value, data, io.EOF |
| 80 | } |
| 81 | currentByte = data[0] |
| 82 | data = data[1:] |
| 83 | |
| 84 | value |= int32(currentByte&127) << position |
| 85 | |
| 86 | if (currentByte & 128) == 0 { |
| 87 | break |
| 88 | } |
| 89 | |
| 90 | position += 7 |
| 91 | |
| 92 | if position >= 32 { |
| 93 | return value, data, fmt.Errorf("VarInt is too big") |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return value, data, nil |
| 98 | } |
| 99 | |
| 100 | func ReadVarInt(r io.Reader) (int32, error) { |
| 101 | var ( |
no outgoing calls
no test coverage detected