func (b *Buffer) WriteVarInt(v uint64) {
	switch {
	case v < uint64(0xfd):
		b.WriteU8(uint8(v))
	case v <= 0xffff:
		b.WriteU8(0xfd)
		b.WriteU16(uint32(v))
	case v <= 0xffffffff:
		b.WriteU8(0xfe)
		b.WriteU32(uint32(v))
	default:
		b.WriteU8(0xff)
		b.WriteU64(v)
	}
}
WriteVarInt -- write variable int to the buffer.
package xbase
import (
	"fmt"
)
type Buffer struct {
	seek   int
	length int
	data   []byte
}
func NewBuffer() *Buffer {
	return &Buffer{}
}
func NewBufferReader(data []byte) *Buffer {
	return &Buffer{
		data:   data,
		length: len(data),
	}
}
func (b *Buffer) check(l int) error {
	if (b.seek + l) > b.length {
		return fmt.Errorf("error.seek[%v].required[%v].length[%v]", b.seek, l, b.length)
	}
	return nil
}
func (b *Buffer) WriteU8(v uint8) {
	b.data = append(b.data, v)
	b.length++
}
func (b *Buffer) ReadU8() (uint8, error) {
	if err := b.check(1); err != nil {
		return 0, err
	}
	v := b.data[b.seek]
	b.seek++
	return v, nil
}
func (b *Buffer) WriteU16(v uint32) {
	b.data = append(b.data, byte(v))
	b.data = append(b.data, byte(v>>8))
	b.length += 2
}
func (b *Buffer) ReadU16() (uint32, error) {
	if err := b.check(2); err != nil {
		return 0, err
	}
	v := uint32(b.data[b.seek]) |
		uint32(b.data[b.seek+1])<<8
	b.seek += 2
	return v, nil
}
func (b *Buffer) WriteU32(v uint32) {
	b.data = append(b.data, byte(v))
	b.data = append(b.data, byte(v>>8))
	b.data = append(b.data, byte(v>>16))
	b.data = append(b.data, byte(v>>24))
	b.length += 4
}
func (b *Buffer) ReadU32() (uint32, error) {
	if err := b.check(4); err != nil {
		return 0, err
	}
	v := uint32(b.data[b.seek]) |
		uint32(b.data[b.seek+1])<<8 |
		uint32(b.data[b.seek+2])<<16 |
		uint32(b.data[b.seek+3])<<24
	b.seek += 4
	return v, nil
}
func (b *Buffer) WriteU64(v uint64) {
	b.data = append(b.data, byte(v))
	b.data = append(b.data, byte(v>>8))
	b.data = append(b.data, byte(v>>16))
	b.data = append(b.data, byte(v>>24))
	b.data = append(b.data, byte(v>>32))
	b.data = append(b.data, byte(v>>40))
	b.data = append(b.data, byte(v>>48))
	b.data = append(b.data, byte(v>>56))
	b.length += 8
}
func (b *Buffer) ReadU64() (uint64, error) {
	if err := b.check(8); err != nil {
		return 0, err
	}
	v := uint64(b.data[b.seek]) |
		uint64(b.data[b.seek+1])<<8 |
		uint64(b.data[b.seek+2])<<16 |
		uint64(b.data[b.seek+3])<<24 |
		uint64(b.data[b.seek+4])<<32 |
		uint64(b.data[b.seek+5])<<40 |
		uint64(b.data[b.seek+6])<<48 |
		uint64(b.data[b.seek+7])<<56
	b.seek += 8
	return v, nil
}