MCPcopy
hub / github.com/segmentio/kafka-go / readVarInt

Method readVarInt

protocol/decode.go:279–304  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

277}
278
279func (d *decoder) readVarInt() int64 {
280 n := 11 // varints are at most 11 bytes
281
282 if n > d.remain {
283 n = d.remain
284 }
285
286 x := uint64(0)
287 s := uint(0)
288
289 for n > 0 {
290 b := d.readByte()
291
292 if (b & 0x80) == 0 {
293 x |= uint64(b) << s
294 return int64(x>>1) ^ -(int64(x) & 1)
295 }
296
297 x |= uint64(b&0x7f) << s
298 s += 7
299 n--
300 }
301
302 d.setError(fmt.Errorf("cannot decode varint from input stream"))
303 return 0
304}
305
306func (d *decoder) readUnsignedVarInt() uint64 {
307 n := 11 // varints are at most 11 bytes

Callers 4

TestVarIntsFunction · 0.95
readVarStringMethod · 0.95
readVarBytesMethod · 0.95
readFromVersion2Method · 0.95

Calls 2

readByteMethod · 0.95
setErrorMethod · 0.95

Tested by 1

TestVarIntsFunction · 0.76