Skip to content

Commit

Permalink
increase varint.WriteTo range
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Cooper committed Dec 23, 2014
1 parent ed8844c commit b366f54
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gumble/varint/write.go
Expand Up @@ -11,14 +11,25 @@ import (
// and nil.
func WriteTo(w io.Writer, value int64) (int64, error) {
var length int
var buff [2]byte
var buff [4]byte
if value <= 0x7F {
buff[0] = byte(value)
length = 1
} else if value <= 0x3FFF {
buff[0] = byte(((value >> 8) & 0x3F) | 0x80)
buff[1] = byte(value & 0xFF)
length = 2
} else if value <= 0x1FFFFF {
buff[0] = byte((value >> 16) & 0x1F | 0xC0)
buff[1] = byte((value >> 8) & 0xFF)
buff[2] = byte(value & 0xFF)
length = 3
} else if value <= 0xFFFFFFF {
buff[0] = byte((value >> 24) & 0xF | 0xE0)
buff[1] = byte((value >> 16) & 0xFF)
buff[2] = byte((value >> 8) & 0xFF)
buff[3] = byte(value & 0xFF)
length = 4
}
if length > 0 {
if n, err := w.Write(buff[:length]); err != nil {
Expand Down

0 comments on commit b366f54

Please sign in to comment.