func newBuf(packetSize int, rw io.ReadWriter) *buf {
	b := new(buf)
	b.PacketSize = packetSize
	b.rw = rw
	b.me = bin.NewEncoder(&b.mb, binary.LittleEndian)
	b.pe = bin.NewEncoder(b, binary.LittleEndian)
	b.he = bin.NewEncoder(&struct {
		io.Reader
		io.Writer
	}{b.rw, &b.pb}, binary.BigEndian)
	b.cancelCh = make(chan error, 1)
	b.CancelTimeout = defaultCancelTimeout
	return b
}
newBuf inits a buffer struct with the different buffers for packet, message and header
package tds
import (
	"bytes"
	"context"
	"encoding/binary"
	"errors"
	"fmt"
	"io"
	"net"
	"sync/atomic"
	"time"
	bin "github.com/thda/tds/binary"
)
const headerSize = 8
const (
	_ = iota
	eom
	cancelAck
	cancel
)
type header struct {
	token      packetType
	status     uint8
	packetSize uint16
	spid       uint16
	packetNo   uint8
	pad        uint8
}
func (h *header) read(e *bin.Encoder) error {
	h.token = packetType(e.ReadByte())
	h.status = e.Uint8()
	h.packetSize = e.Uint16()
	h.spid = e.Uint16()
	h.packetNo = e.Uint8()
	h.pad = e.Uint8()
	err := e.Err()
	return err
}
func (h header) write(e *bin.Encoder) error {
	e.WriteByte(byte(h.token))
	e.WriteByte(h.status)
	e.WriteUint16(h.packetSize)
	e.WriteUint16(h.spid)
	e.WriteUint8(h.packetNo)
	e.WriteUint8(h.pad)
	err := e.Err()
	return err
}
const maxMsgBufSize = 25000
const defaultCancelTimeout = 10
type buf struct {
	rw io.ReadWriter
	h  header        
	pb bytes.Buffer  
	d  [50]byte      
	mb bytes.Buffer  
	me bin.Encoder   
	he bin.Encoder   
	pe         bin.Encoder
	debug      bool
	PacketSize int
	cancelCh      chan error  
	inCancel      int32       
	WriteTimeout  int
	ReadTimeout   int
	CancelTimeout int  
	defaultMessageMap map[token]messageReader
}