Commit d1fee502 authored by Damian Gryski's avatar Damian Gryski

encoder: fix integer encoding ranges

parent c1da7072
......@@ -132,13 +132,16 @@ func (e *Encoder) encodeInt(k reflect.Kind, i int64) {
// FIXME: need support for 64-bit ints
switch {
case i > 0 && i < math.MaxInt8:
case i > 0 && i < math.MaxUint8:
e.w.Write([]byte{opBinint1, byte(i)})
case i > 0 && i < math.MaxInt16:
case i > 0 && i < math.MaxUint16:
e.w.Write([]byte{opBinint2, byte(i >> 8), byte(i)})
default:
case i >= math.MinInt32 && i <= math.MaxInt32:
e.w.Write([]byte{opBinint})
binary.Write(e.w, binary.LittleEndian, int32(i))
default: // int64, but as a string :/
e.w.Write([]byte{opInt})
fmt.Fprintf(e.w, "%d\n", i)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment