diff options
Diffstat (limited to 'encode.go')
-rw-r--r-- | encode.go | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -228,7 +228,12 @@ func encode(w *ReEncoder, val reflect.Value, escaper BackslashEscaper, quote boo return err } } - if _, err := w.WriteString(strconv.FormatInt(val.Int(), 10)); err != nil { + // MaxInt64 = 9223372036854775807 + // MinInt64 = -9223372036854775808 + // 0 1 2 + // 12345678901234567890 + var buf [20]byte + if _, err := w.Write(strconv.AppendInt(buf[:0], val.Int(), 10)); err != nil { return err } if quote { @@ -242,7 +247,11 @@ func encode(w *ReEncoder, val reflect.Value, escaper BackslashEscaper, quote boo return err } } - if _, err := w.WriteString(strconv.FormatUint(val.Uint(), 10)); err != nil { + // MaxUint64 = 18446744073709551615 + // 0 1 2 + // 12345678901234567890 + var buf [20]byte + if _, err := w.Write(strconv.AppendUint(buf[:0], val.Uint(), 10)); err != nil { return err } if quote { |