package pool

import (
	
	
	
)

const defaultBufSize = 65 << 10 // 65kb

var wbPool = sync.Pool{
	New: func() interface{} {
		return NewWriteBuffer()
	},
}

func () *WriteBuffer {
	 := wbPool.Get().(*WriteBuffer)
	return 
}

func ( *WriteBuffer) {
	.Reset()
	wbPool.Put()
}

type WriteBuffer struct {
	Bytes []byte

	msgStart   int
	paramStart int
}

func () *WriteBuffer {
	return &WriteBuffer{
		Bytes: make([]byte, 0, defaultBufSize),
	}
}

func ( *WriteBuffer) () {
	.Bytes = .Bytes[:0]
}

func ( *WriteBuffer) ( byte) {
	if  == 0 {
		.msgStart = len(.Bytes)
		.Bytes = append(.Bytes, 0, 0, 0, 0)
	} else {
		.msgStart = len(.Bytes) + 1
		.Bytes = append(.Bytes, , 0, 0, 0, 0)
	}
}

func ( *WriteBuffer) () {
	binary.BigEndian.PutUint32(
		.Bytes[.msgStart:], uint32(len(.Bytes)-.msgStart))
}

func ( *WriteBuffer) () []byte {
	return .Bytes[.msgStart+4 : len(.Bytes)-1]
}

func ( *WriteBuffer) () {
	.paramStart = len(.Bytes)
	.Bytes = append(.Bytes, 0, 0, 0, 0)
}

func ( *WriteBuffer) () {
	binary.BigEndian.PutUint32(
		.Bytes[.paramStart:], uint32(len(.Bytes)-.paramStart-4))
}

var nullParamLength = int32(-1)

func ( *WriteBuffer) () {
	binary.BigEndian.PutUint32(
		.Bytes[.paramStart:], uint32(nullParamLength))
}

func ( *WriteBuffer) ( []byte) (int, error) {
	.Bytes = append(.Bytes, ...)
	return len(), nil
}

func ( *WriteBuffer) ( int16) {
	.Bytes = append(.Bytes, 0, 0)
	binary.BigEndian.PutUint16(.Bytes[len(.Bytes)-2:], uint16())
}

func ( *WriteBuffer) ( int32) {
	.Bytes = append(.Bytes, 0, 0, 0, 0)
	binary.BigEndian.PutUint32(.Bytes[len(.Bytes)-4:], uint32())
}

func ( *WriteBuffer) ( string) {
	.Bytes = append(.Bytes, ...)
	.Bytes = append(.Bytes, 0)
}

func ( *WriteBuffer) ( []byte) {
	.Bytes = append(.Bytes, ...)
	.Bytes = append(.Bytes, 0)
}

func ( *WriteBuffer) ( byte) error {
	.Bytes = append(.Bytes, )
	return nil
}

func ( *WriteBuffer) ( io.Reader) (int64, error) {
	,  := .Read(.Bytes[len(.Bytes):cap(.Bytes)])
	.Bytes = .Bytes[:len(.Bytes)+]
	return int64(), 
}