func (m *Reader) ReadBool() (bool, error) {
	p, err := m.R.Peek(1)
	if err != nil {
		return false, err
	}
	if p[0] != mtrue && p[0] != mfalse {
		return false, badPrefix(BoolType, p[0])
	}
	_, err = m.R.Skip(1)
	return p[0] == mtrue, err
}
ReadBool reads a bool from the reader.
package msgp
import (
	"io"
	"math"
	"time"
	"github.com/philhofer/fwd"
)
const smallint = (32 << (^uint(0) >> 63)) == 32
type Type byte
const (
	InvalidType Type = iota
	StrType
	BinType
	MapType
	ArrayType
	Float64Type
	Float32Type
	BoolType
	IntType
	UintType
	NilType
	ExtensionType
	Complex64Type
	Complex128Type
	TimeType
)
func (t Type) String() string {
	switch t {
	case StrType:
		return "str"
	case BinType:
		return "bin"
	case MapType:
		return "map"
	case ArrayType:
		return "array"
	case Float64Type:
		return "float64"
	case Float32Type:
		return "float32"
	case BoolType:
		return "bool"
	case UintType:
		return "uint"
	case IntType:
		return "int"
	case ExtensionType:
		return "ext"
	case NilType:
		return "nil"
	default:
		return "<invalid>"
	}
}
type Unmarshaler interface {
	UnmarshalMsg([]byte) ([]byte, error)
}
type Decoder interface {
	DecodeMsg(*Reader) error
}
func Decode(r io.Reader, d Decoder) error {
	rd := NewReader(r)
	return d.DecodeMsg(rd)
}
func NewReader(r io.Reader) *Reader {
	return &Reader{R: fwd.NewReader(r)}
}
func NewReaderSize(r io.Reader, sz int) *Reader {
	return &Reader{R: fwd.NewReaderSize(r, sz)}
}
type Reader struct {
	R       *fwd.Reader
	scratch []byte
}
func (m *Reader) Read(p []byte) (int, error) {
	return m.R.Read(p)
}
func (m *Reader) CopyNext(w io.Writer) (int64, error) {
	sz, o, err := getNextSize(m.R)
	if err != nil {
		return 0, err
	}
	var n int64
	if int(sz) <= m.R.BufferSize() {
		var nn int
		var buf []byte
		buf, err = m.R.Next(int(sz))
		if err != nil {
			if err == io.ErrUnexpectedEOF {
				err = ErrShortBytes
			}
			return 0, err
		}
		nn, err = w.Write(buf)
		n += int64(nn)
	} else {
		n, err = io.CopyN(w, m.R, int64(sz))
		if err == io.ErrUnexpectedEOF {
			err = ErrShortBytes
		}
	}
	if err != nil {
		return n, err
	} else if n < int64(sz) {
		return n, io.ErrShortWrite
	}
	for x := uintptr(0); x < o; x++ {
		n2, err := m.CopyNext(w)
		if err != nil {
			return n, err
		}
		n += n2
	}
	return n, nil
}
func (m *Reader) ReadFull(p []byte) (int, error) {
	return m.R.ReadFull(p)
}
func (m *Reader) Reset(r io.Reader) { m.R.Reset(r) }
func (m *Reader) Buffered() int { return m.R.Buffered() }
func (m *Reader) BufferSize() int { return m.R.BufferSize() }
func (m *Reader) NextType() (Type, error) {
	p, err := m.R.Peek(1)
	if err != nil {
		return InvalidType, err
	}
	t := getType(p[0])
	if t == InvalidType {
		return t, InvalidPrefixError(p[0])
	}
	if t == ExtensionType {
		v, err := m.peekExtensionType()
		if err != nil {
			return InvalidType, err
		}
		switch v {
		case Complex64Extension:
			return Complex64Type, nil
		case Complex128Extension:
			return Complex128Type, nil
		case TimeExtension:
			return TimeType, nil
		}
	}
	return t, nil
}
func (m *Reader) IsNil() bool {
	p, err := m.R.Peek(1)
	return err == nil && p[0] == mnil
}
func getNextSize(r *fwd.Reader) (uintptr, uintptr, error) {
	b, err := r.Peek(1)
	if err != nil {
		return 0, 0, err
	}
	lead := b[0]
	spec := &sizes[lead]
	size, mode := spec.size, spec.extra
	if size == 0 {
		return 0, 0, InvalidPrefixError(lead)
	}
	if mode >= 0 {
		return uintptr(size), uintptr(mode), nil
	}
	b, err = r.Peek(int(size))
	if err != nil {
		return 0, 0, err
	}
	switch mode {
	case extra8:
		return uintptr(size) + uintptr(b[1]), 0, nil
	case extra16:
		return uintptr(size) + uintptr(big.Uint16(b[1:])), 0, nil
	case extra32:
		return uintptr(size) + uintptr(big.Uint32(b[1:])), 0, nil
	case map16v:
		return uintptr(size), 2 * uintptr(big.Uint16(b[1:])), nil
	case map32v:
		return uintptr(size), 2 * uintptr(big.Uint32(b[1:])), nil
	case array16v:
		return uintptr(size), uintptr(big.Uint16(b[1:])), nil
	case array32v:
		return uintptr(size), uintptr(big.Uint32(b[1:])), nil
	default:
		return 0, 0, fatal
	}
}
func (m *Reader) Skip() error {
	var v, o uintptr  
	if m.R.Buffered() >= 5 {
		p, err := m.R.Peek(5)
		if err != nil {
			return err
		}
		v, o, err = getSize(p)
		if err != nil {
			return err
		}
	} else {
		var err error
		v, o, err = getNextSize(m.R)
		if err != nil {
			return err
		}
	}
	_, err := m.R.Skip(int(v))
	if err != nil {
		return err
	}
	for x := uintptr(0); x < o; x++ {
		err = m.Skip()
		if err != nil {
			return err
		}
	}
	return nil
}
func (m *Reader) ReadMapHeader() (uint32, error) {
	p, err := m.R.Peek(1)
	if err != nil {
		return 0, err
	}
	lead := p[0]
	if isfixmap(lead) {
		_, err = m.R.Skip(1)
		return uint32(rfixmap(lead)), err
	}
	switch lead {
	case mmap16:
		p, err = m.R.Next(3)
		if err != nil {
			return 0, err
		}
		return uint32(big.Uint16(p[1:])), nil
	case mmap32:
		p, err = m.R.Next(5)
		if err != nil {
			return 0, err
		}
		return big.Uint32(p[1:]), nil
	default:
		return 0, badPrefix(MapType, lead)
	}
}
func (m *Reader) ReadMapKey(scratch []byte) ([]byte, error) {
	out, err := m.ReadStringAsBytes(scratch)
	if err != nil {
		if tperr, ok := err.(TypeError); ok && tperr.Encoded == BinType {
			return m.ReadBytes(scratch)
		}
		return nil, err
	}
	return out, nil
}
func (m *Reader) ReadMapKeyPtr() ([]byte, error) {
	p, err := m.R.Peek(1)
	if err != nil {
		return nil, err
	}
	lead := p[0]
	var read int
	if isfixstr(lead) {
		read = int(rfixstr(lead))
		m.R.Skip(1)
	} else {
		switch lead {
		case mstr8, mbin8:
			p, err = m.R.Next(2)
			if err != nil {
				return nil, err
			}
			read = int(p[1])
		case mstr16, mbin16:
			p, err = m.R.Next(3)
			if err != nil {
				return nil, err
			}
			read = int(big.Uint16(p[1:]))
		case mstr32, mbin32:
			p, err = m.R.Next(5)
			if err != nil {
				return nil, err
			}
			read = int(big.Uint32(p[1:]))
		default:
			return nil, badPrefix(StrType, lead)
		}
	}
	if read == 0 {
		return nil, ErrShortBytes
	}
	return m.R.Next(read)
}
func (m *Reader) ReadArrayHeader() (uint32, error) {
	p, err := m.R.Peek(1)
	if err != nil {
		return 0, err
	}
	lead := p[0]
	if isfixarray(lead) {
		_, err = m.R.Skip(1)
		return uint32(rfixarray(lead)), err
	}
	switch lead {
	case marray16:
		p, err = m.R.Next(3)
		if err != nil {
			return 0, err
		}
		return uint32(big.Uint16(p[1:])), nil
	case marray32:
		p, err = m.R.Next(5)
		if err != nil {
			return 0, err
		}
		return big.Uint32(p[1:]), nil
	default:
		return 0, badPrefix(ArrayType, lead)
	}
}
func (m *Reader) ReadNil() error {
	p, err := m.R.Peek(1)
	if err != nil {
		return err
	}
	if p[0] != mnil {
		return badPrefix(NilType, p[0])
	}
	_, err = m.R.Skip(1)
	return err
}
func (m *Reader) ReadFloat64() (float64, error) {
	p, err := m.R.Peek(9)
	if err != nil {
		if err == io.EOF && len(p) > 0 && p[0] == mfloat32 {
			ef, err := m.ReadFloat32()
			return float64(ef), err
		}
		return 0, err
	}
	if p[0] != mfloat64 {
		if p[0] == mfloat32 {
			ef, err := m.ReadFloat32()
			return float64(ef), err
		}
		return 0, badPrefix(Float64Type, p[0])
	}
	_, err = m.R.Skip(9)
	return math.Float64frombits(getMuint64(p)), err
}
func (m *Reader) ReadFloat32() (float32, error) {
	p, err := m.R.Peek(5)
	if err != nil {
		return 0, err
	}
	if p[0] != mfloat32 {
		return 0, badPrefix(Float32Type, p[0])
	}
	_, err = m.R.Skip(5)
	return math.Float32frombits(getMuint32(p)), err
}