byteio - stickybigendianwriter_varint.go
1 package byteio
2
3 // WriteUintX writes the unsigned integer using a variable number of bytes
4 func (e *StickyBigEndianWriter) WriteUintX(d uint64) {
5 pos := 8
6 if d > 9295997013522923647 {
7 e.buffer[8] = byte(d)
8 d >>= 8
9 } else {
10 e.buffer[8] = byte(d & 0x7f)
11 d >>= 7
12 }
13 for ; d > 0; d >>= 7 {
14 pos--
15 d--
16 e.buffer[pos] = byte(d&0x7f) | 0x80
17 }
18 e.Write(e.buffer[pos:])
19 }
20
21 // WriteIntX writes the integer using a variable number of bytes
22 func (e *StickyBigEndianWriter) WriteIntX(d int64) {
23 e.WriteUintX(zigzag(d))
24 }
25