packet

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PACKET_BUFFER_SIZE is how much we buffer for reading.
	PACKET_BUFFER_SIZE = 32 * 1024
)
View Source
const (
	// PACKET_MAX_SIZE used for the max packet size.
	PACKET_MAX_SIZE = (1<<24 - 1) // (16MB - 1)
)

Variables

View Source
var (
	// ErrBadConn used for the error of bad connection.
	ErrBadConn = errors.New("connection.was.bad")
	// ErrMalformPacket used for the bad packet.
	ErrMalformPacket = errors.New("Malform.packet.error")
)

Functions

This section is empty.

Types

type MockConn

type MockConn struct {
	// contains filtered or unexported fields
}

MockConn used to mock a net.Conn for testing purposes.

func NewMockConn

func NewMockConn() *MockConn

NewMockConn creates new mock connection.

func (*MockConn) Close

func (m *MockConn) Close() error

Close implements the net.Conn interface.

func (*MockConn) Datas

func (m *MockConn) Datas() []byte

Datas implements the net.Conn interface.

func (*MockConn) LocalAddr

func (m *MockConn) LocalAddr() net.Addr

LocalAddr implements the net.Conn interface.

func (*MockConn) Read

func (m *MockConn) Read(b []byte) (n int, err error)

Read implements the net.Conn interface.

func (*MockConn) RemoteAddr

func (m *MockConn) RemoteAddr() net.Addr

RemoteAddr implements the net.Conn interface.

func (*MockConn) SetDeadline

func (m *MockConn) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn interface.

func (*MockConn) SetReadDeadline

func (m *MockConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn interface.

func (*MockConn) SetWriteDeadline

func (m *MockConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the net.Conn interface.

func (*MockConn) Write

func (m *MockConn) Write(b []byte) (n int, err error)

Write implements the net.Conn interface.

type Packet

type Packet struct {
	SequenceID byte
	Datas      []byte
}

Packet presents the packet tuple.

type Packets

type Packets struct {
	// contains filtered or unexported fields
}

Packets presents the stream tuple.

func NewPackets

func NewPackets(c net.Conn) *Packets

NewPackets creates the new packets.

func (*Packets) Append

func (p *Packets) Append(rawdata []byte) error

Append appends packets to buffer but not write to stream. This is underlying packet unit. NOTICE: SequenceID++

func (*Packets) AppendColumns

func (p *Packets) AppendColumns(columns []*querypb.Field) error

AppendColumns used to append column to columns.

func (*Packets) AppendEOF

func (p *Packets) AppendEOF(flags uint16, warnings uint16) error

AppendEOF appends EOF packet to the stream buffer.

func (*Packets) AppendOKWithEOFHeader

func (p *Packets) AppendOKWithEOFHeader(affectedRows, lastInsertID uint64, flags uint16, warnings uint16) error

AppendOKWithEOFHeader appends OK packet to the stream buffer with EOF header.

func (*Packets) Flush

func (p *Packets) Flush() error

Flush writes all append-packets to the wire.

func (*Packets) Next

func (p *Packets) Next() ([]byte, error)

Next used to read the next packet.

func (*Packets) ParseERR

func (p *Packets) ParseERR(data []byte) error

ParseERR used to parse the ERR packet.

func (*Packets) ParseOK

func (p *Packets) ParseOK(data []byte) (*proto.OK, error)

ParseOK used to parse the OK packet.

func (*Packets) ReadColumns

func (p *Packets) ReadColumns(colNumber int) ([]*querypb.Field, error)

ReadColumns used to read all columns from the stream buffer.

func (*Packets) ReadComQueryResponse

func (p *Packets) ReadComQueryResponse() (*proto.OK, int, error, error)

ReadComQueryResponse used to read query command response and parse the column count. http://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText::Resultset Returns: ok, colNumbs, myerr, err

myerr is the error who was send by MySQL server, the client does not close the connection. if err is not nil, we(the client) will close the connection.

func (*Packets) ReadEOF

func (p *Packets) ReadEOF() error

ReadEOF used to read the EOF packet.

func (*Packets) ReadOK

func (p *Packets) ReadOK() error

ReadOK used to read the OK packet.

func (*Packets) ReadStatementPrepareResponse

func (p *Packets) ReadStatementPrepareResponse(clientFlags uint32) (*proto.Statement, error)

ReadStatementPrepareResponse -- read the stmt prepare response by client from the server.

func (*Packets) ResetSeq

func (p *Packets) ResetSeq()

ResetSeq reset sequence to zero.

func (*Packets) Write

func (p *Packets) Write(payload []byte) error

Write writes the packet to the wire. It packed as: [header] [payload]

func (*Packets) WriteCommand

func (p *Packets) WriteCommand(command byte, payload []byte) error

WriteCommand writes a command packet to the wire.

func (*Packets) WriteERR

func (p *Packets) WriteERR(errorCode uint16, sqlState string, format string, args ...interface{}) error

WriteERR writes ERR packet to the wire.

func (*Packets) WriteOK

func (p *Packets) WriteOK(affectedRows, lastInsertID uint64, flags uint16, warnings uint16) error

WriteOK writes OK packet to the wire.

func (*Packets) WriteStatementPrepareResponse

func (p *Packets) WriteStatementPrepareResponse(clientFlags uint32, stmt *proto.Statement) error

WriteStatementPrepareResponse -- write the stmt prepare response to client by server.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream represents the stream tuple.

func NewStream

func NewStream(conn net.Conn, pktMaxSize int) *Stream

NewStream creates a new stream.

func (*Stream) Append

func (s *Stream) Append(data []byte) error

Append used to append data to write buffer.

func (*Stream) Flush

func (s *Stream) Flush() error

Flush used to flush the writer.

func (*Stream) Read

func (s *Stream) Read() (*Packet, error)

Read reads the next packet from the reader The returned pkt.Datas is only guaranteed to be valid until the next read

func (*Stream) Write

func (s *Stream) Write(data []byte) error

Write writes the packet to writer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL