byteio - stickybigendianreader_varint.go
1 package byteio
2
3 // ReadUintX reads an unsinged integer that was encoded using a variable number
4 // of bytes
5 func (e *StickyBigEndianReader) ReadUintX() uint64 {
6 c, _ := e.ReadByte()
7 val := uint64(c) & 0x7f
8 for n := 1; c&0x80 != 0 && n < 9; n++ {
9 c, _ = e.ReadByte()
10 val++
11 if n == 8 {
12 val = (val << 8) | uint64(c)
13 } else {
14 val = (val << 7) | uint64(c&0x7f)
15 }
16 }
17 return val
18 }
19
20 // ReadIntX reads an integer that was encoded using a variable number of bytes
21 func (e *StickyBigEndianReader) ReadIntX() int64 {
22 return unzigzag(e.ReadUintX())
23 }
24