func (c *conn) NextPacket() ([]byte, error) {
	return c.packets.Next()
}
NextPacket used to get the next packet
package driver
import (
	"context"
	"net"
	"strings"
	"time"
	"github.com/xelabs/go-mysqlstack/packet"
	"github.com/xelabs/go-mysqlstack/proto"
	"github.com/xelabs/go-mysqlstack/sqldb"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/common"
	querypb "github.com/xelabs/go-mysqlstack/sqlparser/depends/query"
	"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
)
var _ Conn = &conn{}
type Conn interface {
	Ping() error
	Quit()
	Close() error
	Closed() bool
	Cleanup()
	NextPacket() ([]byte, error)
	ConnectionID() uint32
	InitDB(db string) error
	Command(command byte) error
	Query(sql string) (Rows, error)
	Exec(sql string) error
	FetchAll(sql string, maxrows int) (*sqltypes.Result, error)
	FetchAllWithFunc(sql string, maxrows int, fn Func) (*sqltypes.Result, error)
	ComStatementPrepare(sql string) (*Statement, error)
}
type conn struct {
	netConn  net.Conn
	auth     *proto.Auth
	greeting *proto.Greeting
	packets  *packet.Packets
}
func (c *conn) handleErrorPacket(data []byte) error {
	if data[0] == proto.ERR_PACKET {
		return c.packets.ParseERR(data)
	}
	return nil
}
func (c *conn) handShake(username, password, database, charset string) error {
	var err error
	var data []byte
	{
		if data, err = c.packets.Next(); err != nil {
			return err
		}
		if err = c.handleErrorPacket(data); err != nil {
			return err
		}
		if err = c.greeting.UnPack(data); err != nil {
			return err
		}
		if c.greeting.Capability&sqldb.CLIENT_PROTOCOL_41 == 0 {
			err = sqldb.NewSQLError(sqldb.CR_VERSION_ERROR, "cannot connect to servers earlier than 4.1")
			return err
		}
	}
	{
		cs, ok := sqldb.CharacterSetMap[strings.ToLower(charset)]
		if !ok {
			cs = sqldb.CharacterSetUtf8
		}
		data := c.auth.Pack(
			proto.DefaultClientCapability,
			cs,
			username,
			password,
			c.greeting.Salt,
			database,
		)
		if err = c.packets.Write(data); err != nil {
			return err
		}
		c.auth.CleanAuthResponse()
	}
	{
		if data, err = c.packets.Next(); err != nil {
			return err
		}
		if err = c.handleErrorPacket(data); err != nil {
			return err
		}
	}
	return nil
}
func NewConn(username, password, address, database, charset string) (Conn, error) {
	var err error
	c := &conn{}
	timeout := time.Duration(30) * time.Second
	if c.netConn, err = net.DialTimeout("tcp", address, timeout); err != nil {
		return nil, err
	}
	if tcpConn, ok := c.netConn.(*net.TCPConn); ok {
		tcpConn.SetKeepAlive(true)
		tcpConn.SetKeepAlivePeriod(time.Second * 180)
		c.netConn = tcpConn
	}
	defer func() {
		if err != nil {
			c.Cleanup()
		}
	}()
	c.netConn.SetReadDeadline(time.Now().Add(timeout))
	defer c.netConn.SetReadDeadline(time.Time{})
	c.auth = proto.NewAuth()
	c.greeting = proto.NewGreeting(0, "")
	c.packets = packet.NewPackets(c.netConn)
	if err = c.handShake(username, password, database, charset); err != nil {
		return nil, err
	}
	return c, nil
}