| 202 | } |
| 203 | |
| 204 | func (r *compactReader) readVarint(typ string, min, max int64) (int64, error) { |
| 205 | var br io.ByteReader |
| 206 | |
| 207 | switch x := r.Reader().(type) { |
| 208 | case *bytes.Buffer: |
| 209 | br = x |
| 210 | case *bytes.Reader: |
| 211 | br = x |
| 212 | case *bufio.Reader: |
| 213 | br = x |
| 214 | case io.ByteReader: |
| 215 | br = x |
| 216 | default: |
| 217 | br = &r.binary |
| 218 | } |
| 219 | |
| 220 | v, err := binary.ReadVarint(br) |
| 221 | if err == nil { |
| 222 | if v < min || v > max { |
| 223 | err = fmt.Errorf("%s varint out of range: %d not in [%d;%d]", typ, v, min, max) |
| 224 | } |
| 225 | } |
| 226 | return v, err |
| 227 | } |
| 228 | |
| 229 | type compactWriter struct { |
| 230 | protocol *CompactProtocol |