func (d *decoder) parse_int(v reflect.Value) {
	start := d.offset - 1
	d.read_until('e')
	if d.buf.Len() == 0 {
		panic(&SyntaxError{
			Offset: start,
			What:   errors.New("empty integer value"),
		})
	}
	s := d.buf.String()
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		n, err := strconv.ParseInt(s, 10, 64)
		check_for_int_parse_error(err, start)
		if v.OverflowInt(n) {
			panic(&UnmarshalTypeError{
				Value: "integer " + s,
				Type:  v.Type(),
			})
		}
		v.SetInt(n)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		n, err := strconv.ParseUint(s, 10, 64)
		check_for_int_parse_error(err, start)
		if v.OverflowUint(n) {
			panic(&UnmarshalTypeError{
				Value: "integer " + s,
				Type:  v.Type(),
			})
		}
		v.SetUint(n)
	case reflect.Bool:
		v.SetBool(s != "0")
	default:
		panic(&UnmarshalTypeError{
			Value: "integer " + s,
			Type:  v.Type(),
		})
	}
	d.buf.Reset()
}
called when 'i' was consumed
package bencode
import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"io"
	"math/big"
	"reflect"
	"runtime"
	"strconv"
	"strings"
)
type decoder struct {
	*bufio.Reader
	offset int64
	buf    bytes.Buffer
	key    string
}
func (d *decoder) decode(v interface{}) (err error) {
	defer func() {
		if e := recover(); e != nil {
			if _, ok := e.(runtime.Error); ok {
				panic(e)
			}
			err = e.(error)
		}
	}()
	pv := reflect.ValueOf(v)
	if pv.Kind() != reflect.Ptr || pv.IsNil() {
		return &UnmarshalInvalidArgError{reflect.TypeOf(v)}
	}
	if !d.parse_value(pv.Elem()) {
		d.throwSyntaxError(d.offset-1, errors.New("unexpected 'e'"))
	}
	return nil
}
func check_for_unexpected_eof(err error, offset int64) {
	if err == io.EOF {
		panic(&SyntaxError{
			Offset: offset,
			What:   io.ErrUnexpectedEOF,
		})
	}
}
func (d *decoder) read_byte() byte {
	b, err := d.ReadByte()
	if err != nil {
		check_for_unexpected_eof(err, d.offset)
		panic(err)
	}
	d.offset++
	return b
}
func (d *decoder) read_until(sep byte) {
	for {
		b := d.read_byte()
		if b == sep {
			return
		}
		d.buf.WriteByte(b)
	}
}
func check_for_int_parse_error(err error, offset int64) {
	if err != nil {
		panic(&SyntaxError{
			Offset: offset,
			What:   err,
		})
	}
}
func (d *decoder) throwSyntaxError(offset int64, err error) {
	panic(&SyntaxError{
		Offset: offset,
		What:   err,
	})
}