func Encode(w io.Writer, e Encodable) error {
	wr := NewWriter(w)
	err := e.EncodeMsg(wr)
	if err == nil {
		err = wr.Flush()
	}
	freeW(wr)
	return err
}
Encode encodes an Encodable to an io.Writer.
package msgp
import (
	"errors"
	"fmt"
	"io"
	"math"
	"reflect"
	"sync"
	"time"
)
const (
	minWriterSize = 18
)
type Sizer interface {
	Msgsize() int
}
var (
	Nowhere io.Writer = nwhere{}
	btsType    = reflect.TypeOf(([]byte)(nil))
	writerPool = sync.Pool{
		New: func() interface{} {
			return &Writer{buf: make([]byte, 2048)}
		},
	}
)
func popWriter(w io.Writer) *Writer {
	wr := writerPool.Get().(*Writer)
	wr.Reset(w)
	return wr
}
func pushWriter(wr *Writer) {
	wr.w = nil
	wr.wloc = 0
	writerPool.Put(wr)
}
func freeW(w *Writer) { pushWriter(w) }
func Require(old []byte, extra int) []byte {
	l := len(old)
	c := cap(old)
	r := l + extra
	if c >= r {
		return old
	} else if l == 0 {
		return make([]byte, 0, extra)
	}
	c <<= 1
	if c < r {
		c = r
	}
	n := make([]byte, l, c)
	copy(n, old)
	return n
}
type nwhere struct{}
func (n nwhere) Write(p []byte) (int, error) { return len(p), nil }
type Marshaler interface {
	MarshalMsg([]byte) ([]byte, error)
}
type Encodable interface {
	EncodeMsg(*Writer) error
}
type Writer struct {
	w    io.Writer
	buf  []byte
	wloc int
}
func NewWriter(w io.Writer) *Writer {
	if wr, ok := w.(*Writer); ok {
		return wr
	}
	return popWriter(w)
}
func NewWriterSize(w io.Writer, sz int) *Writer {
	if sz < minWriterSize {
		sz = minWriterSize
	}
	buf := make([]byte, sz)
	return NewWriterBuf(w, buf)
}
func NewWriterBuf(w io.Writer, buf []byte) *Writer {
	if cap(buf) < minWriterSize {
		buf = make([]byte, minWriterSize)
	}
	buf = buf[:cap(buf)]
	return &Writer{
		w:   w,
		buf: buf,
	}
}