func (b *Buffer) ReadLenEncode() (v uint64, err error) {
	var u8 uint8
	var u16 uint16
	var u24 uint32
	if u8, err = b.ReadU8(); err != nil {
		return
	}
	switch u8 {
	case 0xfb:
		v = ^uint64(0)
		return
	case 0xfc:
		if u16, err = b.ReadU16(); err != nil {
			return
		}
		v = uint64(u16)
		return
	case 0xfd:
		if u24, err = b.ReadU24(); err != nil {
			return
		}
		v = uint64(u24)
		return
	case 0xfe:
		if v, err = b.ReadU64(); err != nil {
			return
		}
		return
	default:
		return uint64(u8), nil
	}
}
ReadLenEncode used to read variable length.
package common
import (
	"bytes"
	"io"
)
var (
	ErrIOEOF = io.EOF
)
type Buffer struct {
	pos  int
	seek int
	cap  int
	buf  []byte
}
func NewBuffer(cap int) *Buffer {
	return &Buffer{pos: 0,
		cap: cap,
		buf: make([]byte, cap),
	}
}
func ReadBuffer(b []byte) *Buffer {
	return &Buffer{
		buf: b,
		pos: len(b),
	}
}
func (b *Buffer) Reset(data []byte) {
	b.buf = data
	b.pos = len(data)
	b.seek = 0
}
func (b *Buffer) Datas() []byte {
	return b.buf[:b.pos]
}
func (b *Buffer) Length() int {
	return b.pos
}
func (b *Buffer) Seek() int {
	return b.seek
}
func (b *Buffer) extend(n int) {
	if (b.pos + n) > b.cap {
		b.cap = (b.pos + n) * 2
		t := make([]byte, b.cap)
		copy(t, b.buf)
		b.buf = t
	}
}
func (b *Buffer) WriteU8(v uint8) {
	b.extend(1)
	b.buf[b.pos] = v
	b.pos++
}
func (b *Buffer) ReadU8() (v uint8, err error) {
	if (b.seek + 1) > b.pos {
		err = ErrIOEOF
		return
	}
	v = uint8(b.buf[b.seek])
	b.seek++
	return
}
func (b *Buffer) WriteU16(v uint16) {
	b.extend(2)
	b.buf[b.pos] = byte(v)
	b.buf[b.pos+1] = byte(v >> 8)
	b.pos += 2
}
func (b *Buffer) ReadU16() (v uint16, err error) {
	if (b.seek + 2) > b.pos {
		err = ErrIOEOF
		return
	}
	v = uint16(b.buf[b.seek]) |
		uint16(b.buf[b.seek+1])<<8
	b.seek += 2
	return
}
func (b *Buffer) WriteU24(v uint32) {
	b.extend(3)
	b.buf[b.pos] = byte(v)
	b.buf[b.pos+1] = byte(v >> 8)
	b.buf[b.pos+2] = byte(v >> 16)
	b.pos += 3
}
func (b *Buffer) ReadU24() (v uint32, err error) {
	if (b.seek + 3) > b.pos {
		err = ErrIOEOF
		return
	}
	v = uint32(b.buf[b.seek]) |
		uint32(b.buf[b.seek+1])<<8 |
		uint32(b.buf[b.seek+2])<<16
	b.seek += 3
	return
}
func (b *Buffer) WriteU32(v uint32) {
	b.extend(4)
	b.buf[b.pos] = byte(v)
	b.buf[b.pos+1] = byte(v >> 8)
	b.buf[b.pos+2] = byte(v >> 16)
	b.buf[b.pos+3] = byte(v >> 24)
	b.pos += 4
}
func (b *Buffer) ReadU32() (v uint32, err error) {
	if (b.seek + 4) > b.pos {
		err = ErrIOEOF
		return
	}
	v = uint32(b.buf[b.seek]) |
		uint32(b.buf[b.seek+1])<<8 |
		uint32(b.buf[b.seek+2])<<16 |
		uint32(b.buf[b.seek+3])<<24
	b.seek += 4
	return
}
func (b *Buffer) WriteU64(v uint64) {
	b.extend(8)
	b.buf[b.pos] = byte(v)
	b.buf[b.pos+1] = byte(v >> 8)
	b.buf[b.pos+2] = byte(v >> 16)
	b.buf[b.pos+3] = byte(v >> 24)
	b.buf[b.pos+4] = byte(v >> 32)
	b.buf[b.pos+5] = byte(v >> 40)
	b.buf[b.pos+6] = byte(v >> 48)
	b.buf[b.pos+7] = byte(v >> 56)
	b.pos += 8
}
func (b *Buffer) ReadU64() (v uint64, err error) {
	if (b.seek + 8) > b.pos {
		err = ErrIOEOF
		return
	}
	v = uint64(b.buf[b.seek]) |
		uint64(b.buf[b.seek+1])<<8 |
		uint64(b.buf[b.seek+2])<<16 |
		uint64(b.buf[b.seek+3])<<24 |
		uint64(b.buf[b.seek+4])<<32 |
		uint64(b.buf[b.seek+5])<<40 |
		uint64(b.buf[b.seek+6])<<48 |
		uint64(b.buf[b.seek+7])<<56
	b.seek += 8
	return
}
func (b *Buffer) WriteLenEncode(v uint64) {
	switch {
	case v < 251:
		b.WriteU8(uint8(v))
	case v >= 251 && v < (1<<16):
		b.WriteU8(0xfc)
		b.WriteU16(uint16(v))
	case v >= (1<<16) && v < (1<<24):
		b.WriteU8(0xfd)
		b.WriteU24(uint32(v))
	default:
		b.WriteU8(0xfe)
		b.WriteU64(v)
	}
}
func (b *Buffer) WriteLenEncodeNUL() {
	b.WriteU8(0xfb)
}